From: Alexandru Ardelean Date: Mon, 22 Mar 2021 08:41:35 +0000 (+0200) Subject: iio: buffer: return 0 for buffer getfd ioctl handler X-Git-Tag: accepted/tizen/unified/20230118.172025~7414^2~195^2~63 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c822244bf4a0fc7f0f5120dc4dae4e9aa815ea6;p=platform%2Fkernel%2Flinux-rpi.git iio: buffer: return 0 for buffer getfd ioctl handler As Lars pointed out, we could either return the FD vs memcpy-ing it to the userspace data object. However, this comment exposed a bug. We should return 0 or negative from these ioctl() handlers. Because an ioctl() handler can also return IIO_IOCTL_UNHANDLED (which is positive 1), which means that the ioctl() handler doesn't support this ioctl number. Positive 1 could also be a valid FD number in some corner cases. The reason we did this is to be able to differentiate between an error code and an unsupported ioctl number; for unsupported ioctl numbers, the main loop should keep going. Maybe we should change this to a higher negative number, to avoid such cases when/if we add more ioctl() handlers. Cc: Lars-Peter Clausen Fixes: f73f7f4da5818 ("iio: buffer: add ioctl() to support opening extra buffers for IIO device") Signed-off-by: Alexandru Ardelean Link: https://lore.kernel.org/r/20210322084135.17536-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index ccc8a8c..2ea5281 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -1442,7 +1442,7 @@ static long iio_device_buffer_getfd(struct iio_dev *indio_dev, unsigned long arg goto error_free_ib; } - return fd; + return 0; error_free_ib: kfree(ib);