Page MenuHomeFreeBSD

iic: return errnos to userspace instead of IIC_ error numbers
Needs ReviewPublic

Authored by val_packett.cool on Dec 31 2021, 11:42 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Oct 3, 4:48 AM
Unknown Object (File)
Wed, Oct 2, 10:41 AM
Unknown Object (File)
Wed, Oct 2, 10:03 AM
Unknown Object (File)
Sat, Sep 28, 3:28 PM
Unknown Object (File)
Wed, Sep 25, 10:59 PM
Unknown Object (File)
Sep 8 2024, 9:47 PM
Unknown Object (File)
Sep 8 2024, 7:54 PM
Unknown Object (File)
Aug 31 2024, 5:03 PM

Details

Reviewers
manu
wulf
avg
Group Reviewers
Contributor Reviews (src)
Summary

Before:

% i2c -f /dev/iic1 -a 0x20 -d r -c 513
i2c: ioctl(I2CRDWR) failed: Exec format error

After:

% i2c -f /dev/iic1 -a 0x20 -d r -c 513
i2c: ioctl(I2CRDWR) failed: Operation not supported

(the example above is IIC_ENOTSUPP due to an overly long read)

So yeah, turns out this has been a thing for years :/

I guess we could alternatively keep the current way, document it in the manpage and add an iic_strerror to i2c(8) (which would also require moving the IIC_E* definitions to a header shared with userspace) but since nobody noticed that the errors are weird, it should be fine to change.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 43659
Build 40547: arc lint + arc unit

Event Timeline

I am a bit torn on this.
On the one hand, I like the simplicity that comes from returning errno codes to userland.
On the other hand, recently I had to write a program that had to use "low level" ioctl-s like I2CSTART and I needed to be able to distinguish IIC_ENOACK from other bus conditions.
In any case, the current state of matters where a return value can be either an errno code or an IIC code is clearly a mess.

Yeah, we should probably make the iic-errnos public instead. In freebsd-embedded-hal the API I'm implementing also prefers more specific errors.