* [PATCH] iio: buffer: return 0 for buffer getfd ioctl handler
@ 2021-03-22 8:41 Alexandru Ardelean
2021-03-29 12:33 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Ardelean @ 2021-03-22 8:41 UTC (permalink / raw)
To: linux-iio, linux-kernel; +Cc: jic23, Alexandru Ardelean, Lars-Peter Clausen
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 <lars@metafoo.de>
Fixes: f73f7f4da5818 ("iio: buffer: add ioctl() to support opening extra buffers for IIO device")
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
---
drivers/iio/industrialio-buffer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index ee5aab9d4a23..d7a15c9bb0cd 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);
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: buffer: return 0 for buffer getfd ioctl handler
2021-03-22 8:41 [PATCH] iio: buffer: return 0 for buffer getfd ioctl handler Alexandru Ardelean
@ 2021-03-29 12:33 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2021-03-29 12:33 UTC (permalink / raw)
To: Alexandru Ardelean; +Cc: linux-iio, linux-kernel, Lars-Peter Clausen
On Mon, 22 Mar 2021 10:41:35 +0200
Alexandru Ardelean <aardelean@deviqon.com> wrote:
> 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.
That sounds like a sensible follow up plan to me - perhaps we could
use EOPNOTSUPP for this directly but add special handling for that in
the core so it doesn't worry about it as long as someone supports the ioctl.
>
> Cc: Lars-Peter Clausen <lars@metafoo.de>
> Fixes: f73f7f4da5818 ("iio: buffer: add ioctl() to support opening extra buffers for IIO device")
> Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Applied to the togreg branch of iio.git and pushed out as testing.
Thanks,
Jonathan
> ---
> drivers/iio/industrialio-buffer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index ee5aab9d4a23..d7a15c9bb0cd 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);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-29 12:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-22 8:41 [PATCH] iio: buffer: return 0 for buffer getfd ioctl handler Alexandru Ardelean
2021-03-29 12:33 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox