From 6458b08e5655dd6f3c89c83a4ef1e3d4f665733f Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Thu, 12 May 2016 16:12:43 +0100 Subject: [PATCH] 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. --- lib/comedi.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/comedi.c b/lib/comedi.c index c5a7238..adb9294 100644 --- a/lib/comedi.c +++ b/lib/comedi.c @@ -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);