Page MenuHomeFreeBSD

Don't return IIC_Exxxxx status values to userspace
AcceptedPublic

Authored by thj on Nov 29 2017, 2:34 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 7 2024, 5:39 AM
Unknown Object (File)
Feb 21 2024, 6:05 PM
Unknown Object (File)
Jan 16 2024, 12:59 AM
Unknown Object (File)
Jan 6 2024, 1:15 AM
Unknown Object (File)
Dec 23 2023, 2:59 AM
Unknown Object (File)
Oct 31 2023, 3:48 AM
Unknown Object (File)
Jun 30 2023, 10:44 PM
Unknown Object (File)
Jun 16 2023, 4:17 PM
Subscribers

Details

Reviewers
ian
jtl
bz
Summary

iiconf.h states:

/*

  • Note that all iicbus functions return IIC_Exxxxx status values,
  • except iic2errno() (obviously) and iicbus_started() (returns bool). */

however iic.c returns a mixture of ERRNO values and IIC_Exxxxx values in ioctl and read calls. Attempt to translate
these calls with iic2errno.

Diff Detail

Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Recreate diff using svn diff --diff-cmd=diff -x -U999999 > change.diff

All these:

error = foo(bar);
error = iic2errno(error);

feel a bit strange. Wouldn't it be better to write:

error = iic2errorno(foo(bar));

Wrap calls with iic2errno converter

ian requested changes to this revision.Jul 16 2019, 2:44 PM
ian added a subscriber: ian.

Unfortunately, the comment that says "all iicbus functions return IIC_Exxxxx status values" is incorrect. There is one exception which screws up this whole error-translation thing: iicbus_poll() can return an errno and the rather important errno values it might return, EINTR and ERESTART, have no corresponding IIC_Exxxxx value they could be translated to so that they can later be translated back.

I have long believed that the right fix for this whole mess is to eliminate the IIC_Exxxxx stuff and just use errnos everywhere. But that's a hard change to make, especially considering there might be out-of-tree drivers.

A much simpler fix would be to add IIC_ERESTART and IIC_EINTR, and I guess something like IIC_EOTHER or maybe IIC_ESYSERR, some kind of catch-all that just means "I got an error from some system thing that isn't directly related to the iic protocol". Then iicbus_poll() could translate the errno from mtx_sleep() to an IIC_Exxxx that would then later be properly translated back to an errno. Ick, but it preserves KPI and KBI.

Note that I haven't yet done a detailed review of the code changes in the current diff.

This revision now requires changes to proceed.Jul 16 2019, 2:44 PM

Upon further reflection, I think the changes to iic(4) in this diff are correct and should be committed. The problem of iicbus_request_bus() returning an ambiguous mix of IIC_Exxxxx or errno values because of iicbus_poll() doing so is a separate problem and should be fixed separately.

This revision is now accepted and ready to land.Jul 16 2019, 5:42 PM