Re: RFC: Use error codes from errno.h


Jesus Sanchez-Palencia <jesus.sanchez-palencia@...>
 

On Wed, 2 Mar 2016 16:03:22 -0300
Jesus Sanchez-Palencia <jesus.sanchez-palencia(a)intel.com> wrote:

Hi,

On Thu, 18 Feb 2016 17:47:56 -0200
Andre Guedes <andre.guedes(a)intel.com> wrote:

Hi all,

While we were discussing about adding a new error code for device.h (see
"[RFC] Add DEV_NOT_IMPLEMENTED error code" thread), we had an initial
agreement that it does make sense to use error codes from errno.h instead
of the ones from include/device.h. Since this topic deserves its own RFC,
I'm sending this email so we can have a proper discussion.
Cool!
+1 from my side, mainly so we don't need to discuss the addition of new error codes ever again :).


So the main points in favor of this change are 1) errno.h is a well-known
error convention which pretty much all developer is familiar with, 2)
errno.h codes address what we need, 3) no need to create new codes such
as DEV_NOT_IMPLEMENTED for instance, and 4) changing the current drivers
to use errno.h codes instead of DEV_* is a feasible task.
I would say it's more about 3) and 4) really, as I've seen surprisingly often how 1) and 2) are not
always true. I've seen recently people getting confused about what to return and when, myself
included. In the end it doesn't matter from each .h file you get the errors from, as long as you
have clear guidelines for them, in my opinion.


The initial discussion was about using errno.h codes at the driver's layer
but I think we can expand it to the whole system. Actually, errno.h codes
are already used in net/bluetooth and net/ip.
+1 ! But I would propose that we first get this right for the device driver APIs.

What we have on device.h currently is:

/* Common Error Codes devices can provide */
#define DEV_OK 0 /* No error */
#define DEV_FAIL 1 /* General operation failure */
#define DEV_INVALID_OP 2 /* Invalid operation */
#define DEV_INVALID_CONF 3 /* Invalid configuration */
#define DEV_USED 4 /* Device controller in use */
#define DEV_NO_ACCESS 5 /* Controller not accessible */
#define DEV_NO_SUPPORT 6 /* Device type not supported */
#define DEV_NOT_CONFIG 7 /* Device not configured */


I liked Dirk's suggestion on the previous thread, so I'm gonna propose 2 quick steps:
a- let's try to map each of this to errno codes;
b- let's document when we should return each of them.

You probably have b) ready from the other thread as well, so let me give it a try with a).
If we get this two right, then we end up with both the guidelines for documenting and the
transition patch Dirk suggested. After he deprecates DEV_*, moving to errno codes will be as easy
as a few seds. So:

I forgot to mention that whichever guidelines come out of this thread, I will move to QMSI so we
are all aligned.



DEV_OK = 0
DEV_FAIL = (??)
DEV_INVALID_OP = -EPERM or -ENOTSUP (??)
DEV_INVALID_CONF = -EINVAL
DEV_USED = -EBUSY
DEV_NO_ACCESS = -EAGAIN
DEV_NO_SUPPORT = -ENODEV or -ENXIO (??)
DEV_NOT_CONFIG = (??)
DEV_NOT_IMPLEMENTED = -ENOSYS
*this last one is from your previous RFC.


How bad does that look?!



Regards,
jesus

Join devel@lists.zephyrproject.org to automatically receive all group messages.