[libcamera-devel,05/11] libcamera: v4l2_controls: Fix usage of strerror()

Message ID 20200309162414.720306-6-jacopo@jmondi.org
State Accepted
Headers show
Series
  • Adda support for V4L2 array control and strings
Related show

Commit Message

Jacopo Mondi March 9, 2020, 4:24 p.m. UTC
On failure, the return code from V4L2Device::ioctl() is the negative error
code set by the failed ::ioctl() system call. When the return code of
V4L2Device::ioctl() is provided to strerror() it has to be negated again
to obtain the positive error code. Fix a few wrong usages of the return
code which provided to the strerror() function a negative error code.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 src/libcamera/v4l2_device.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Laurent Pinchart March 20, 2020, 11:31 a.m. UTC | #1
Hi Jacopo,

Thank you for the patch.

On Mon, Mar 09, 2020 at 05:24:08PM +0100, Jacopo Mondi wrote:
> On failure, the return code from V4L2Device::ioctl() is the negative error
> code set by the failed ::ioctl() system call. When the return code of
> V4L2Device::ioctl() is provided to strerror() it has to be negated again
> to obtain the positive error code. Fix a few wrong usages of the return
> code which provided to the strerror() function a negative error code.
> 
> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

This is an independent bug fix, feel free to push it already.

> ---
>  src/libcamera/v4l2_device.cpp | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
> index 98639bd0f07f..179476e9afad 100644
> --- a/src/libcamera/v4l2_device.cpp
> +++ b/src/libcamera/v4l2_device.cpp
> @@ -201,13 +201,13 @@ int V4L2Device::getControls(ControlList *ctrls)
>  		/* Generic validation error. */
>  		if (errorIdx == 0 || errorIdx >= count) {
>  			LOG(V4L2, Error) << "Unable to read controls: "
> -					 << strerror(ret);
> +					 << strerror(-ret);
>  			return -EINVAL;
>  		}
>  
>  		/* A specific control failed. */
>  		LOG(V4L2, Error) << "Unable to read control " << errorIdx
> -				 << ": " << strerror(ret);
> +				 << ": " << strerror(-ret);
>  		count = errorIdx - 1;
>  		ret = errorIdx;
>  	}
> @@ -291,13 +291,13 @@ int V4L2Device::setControls(ControlList *ctrls)
>  		/* Generic validation error. */
>  		if (errorIdx == 0 || errorIdx >= count) {
>  			LOG(V4L2, Error) << "Unable to set controls: "
> -					 << strerror(ret);
> +					 << strerror(-ret);
>  			return -EINVAL;
>  		}
>  
>  		/* A specific control failed. */
>  		LOG(V4L2, Error) << "Unable to set control " << errorIdx
> -				 << ": " << strerror(ret);
> +				 << ": " << strerror(-ret);
>  		count = errorIdx - 1;
>  		ret = errorIdx;
>  	}

Patch

diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp
index 98639bd0f07f..179476e9afad 100644
--- a/src/libcamera/v4l2_device.cpp
+++ b/src/libcamera/v4l2_device.cpp
@@ -201,13 +201,13 @@  int V4L2Device::getControls(ControlList *ctrls)
 		/* Generic validation error. */
 		if (errorIdx == 0 || errorIdx >= count) {
 			LOG(V4L2, Error) << "Unable to read controls: "
-					 << strerror(ret);
+					 << strerror(-ret);
 			return -EINVAL;
 		}
 
 		/* A specific control failed. */
 		LOG(V4L2, Error) << "Unable to read control " << errorIdx
-				 << ": " << strerror(ret);
+				 << ": " << strerror(-ret);
 		count = errorIdx - 1;
 		ret = errorIdx;
 	}
@@ -291,13 +291,13 @@  int V4L2Device::setControls(ControlList *ctrls)
 		/* Generic validation error. */
 		if (errorIdx == 0 || errorIdx >= count) {
 			LOG(V4L2, Error) << "Unable to set controls: "
-					 << strerror(ret);
+					 << strerror(-ret);
 			return -EINVAL;
 		}
 
 		/* A specific control failed. */
 		LOG(V4L2, Error) << "Unable to set control " << errorIdx
-				 << ": " << strerror(ret);
+				 << ": " << strerror(-ret);
 		count = errorIdx - 1;
 		ret = errorIdx;
 	}