rtems_set_errno_and_return_minus_one in driver not returning correct value

Inderjit Singh inderjit.singh at aacmicrotec.com
Mon Aug 24 13:07:50 UTC 2015


Ok I experimented on and this is what I found out:

This is what I'm doing:

App:
    fd = open(RTEMS_SYSFLASH_DEVICE_NAME, O_RDWR);
    printk("Errno: (%d:%s).", errno, strerror(errno));
    assert(0);

Driver:
rtems_device_driver rtems_sysflash_open(rtems_device_major_number major, rtems_device_minor_number unused, void *args)
{
    uint32_t result;
    uint32_t status;
    rtems_libio_rw_args_t *rw_args;

    errno = EALREADY;
    return -1;
}

Printout:
  Errno: (22:Invalid argument).


Now, If I change the return value to RTEMS_SUCCESSFULL in driver like
Driver:
...
   errno = EALREADY;
   return RTEMS_SUCCESSFULL;
}

Printout:
   Errno: (120:Socket already connected)


So it seems the one must return RTEMS_SUCCESSFUL to retain the errno value. This is not how it should behave right?

Regards,
Indy
________________________________________
From: devel [devel-bounces at rtems.org] on behalf of Inderjit Singh [inderjit.singh at aacmicrotec.com]
Sent: 24 August 2015 09:08
To: Chris Johns; devel at rtems.org
Subject: RE: rtems_set_errno_and_return_minus_one in driver not returning correct value

Hi Chris,

I am pretty sure the driver is working fine yes. I had this issue for some time and ignored the error messages during development as I always get a negative value. Now the driver is working is as it should and I am enforcing the error to test this.

Regards,
Indy
________________________________________
From: Chris Johns [chrisj at rtems.org]
Sent: 24 August 2015 01:19
To: Inderjit Singh; devel at rtems.org
Subject: Re: rtems_set_errno_and_return_minus_one in driver not returning correct value

On 21/08/2015 10:22 pm, Inderjit Singh wrote:
> Hi,
>
> In my RTEMS driver I set and return error value by following macro:
>
> rtems_set_errno_and_return_minus_one(EALREADY);
>
> But in my rtems app when I print the error out by:
>
> fd = open(RTEMS_SYSFLASH_DEVICE_NAME, O_RDWR);
> if(fd < 0) {
> printk("Couldn't Open device (%d:%d:%s).", fd, errno, strerror(errno));
> exit(-1);
> }
>
> *OUTPUT:* Couldn't Open device (-1:22:Invalid argument).
>
> No matter what errno value i set I always get the same (22: Invalid
> argument). I don't understand why. Any help would be appreciated.
>

Are you sure the driver is correctly installed and registered and
reaching your code ? Maybe some other part of the file system is
detecting an error and returning the error code you are seeing for some
other reason. I would add a print statement where you set the error code
to see if that code is being reached.

Chris
_______________________________________________
devel mailing list
devel at rtems.org
http://lists.rtems.org/mailman/listinfo/devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20150824/a7bb0acc/attachment-0002.html>


More information about the devel mailing list