lib: remove some unnecessary setting of __comedi_errno

Since comedi_ioctl() calls libc_error() to set __comedi_errno to errno
(and possibly print an error message), there is no need for callers of
comedi_ioctl() to set __comedi_errno immediately afterwards.  But
comedi_command(), comedi_command_test(), and comedi_do_insnlist()
currently do that.  Remove the unneeded setting of __comedi_errno in
those functions.

Also, comedi_command() and comedi_command_test() check __comedi_errno
regardless of whether comedi_ioctl() returnis an error, and possibly
modify the error code to an internal comedi error.  Change them to only
do that if comedi_ioctl() returns an error, because __comedi_errno might
contain a stale value.
This commit is contained in:
Ian Abbott 2016-05-12 16:12:43 +01:00
parent 27509ba9c9
commit 6458b08e56

View file

@ -164,11 +164,12 @@ int _comedi_command(comedi_t *it,comedi_cmd *t)
int ret;
if(!valid_dev(it)) return -1;
ret = comedi_ioctl(it->fd, COMEDI_CMD, t);
__comedi_errno = errno;
switch(__comedi_errno){
case EIO:
__comedi_errno = ECMDNOTSUPP;
break;
if(ret<0){
switch(__comedi_errno){
case EIO:
__comedi_errno = ECMDNOTSUPP;
break;
}
}
return ret;
}
@ -179,11 +180,12 @@ int _comedi_command_test(comedi_t *it,comedi_cmd *t)
int ret;
if(!valid_dev(it)) return -1;
ret = comedi_ioctl(it->fd, COMEDI_CMDTEST, t);
__comedi_errno = errno;
switch(__comedi_errno){
case EIO:
__comedi_errno = ECMDNOTSUPP;
break;
if(ret<0){
switch(__comedi_errno){
case EIO:
__comedi_errno = ECMDNOTSUPP;
break;
}
}
return ret;
}
@ -191,11 +193,8 @@ int _comedi_command_test(comedi_t *it,comedi_cmd *t)
EXPORT_ALIAS_DEFAULT(_comedi_do_insnlist,comedi_do_insnlist,0.7.18);
int _comedi_do_insnlist(comedi_t *it,comedi_insnlist *il)
{
int ret;
if(!valid_dev(it)) return -1;
ret = comedi_ioctl(it->fd, COMEDI_INSNLIST, il);
__comedi_errno = errno;
return ret;
return comedi_ioctl(it->fd, COMEDI_INSNLIST, il);
}
EXPORT_ALIAS_DEFAULT(_comedi_do_insn,comedi_do_insn,0.7.18);