gpiolib: Never return internal error codes to user space
PATCH 1/2 gpiolib: Never return internal error codes to user space
Currently it's possible that character device interface may return the error codes which are not supposed to be seen by user space. In this case it's EPROBE_DEFER.
Wrap it to return -ENODEV instead as sysfs does.
--- drivers/gpio/gpiolib-cdev.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpio/gpiolib-cdev.c +12 -3
@@ -331,8 +331,11 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) } ret =gpiod_request (desc, lh->label); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) + ret = -ENODEV ; goto out_free_lh; + } lh->descs[i] = desc;linehandle_flags_to_desc_flags (handlereq.flags, &desc->flags);
@@ -1379,8 +1382,11 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) } ret =gpiod_request (desc, lr->label); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) + ret = -ENODEV ; goto out_free_linereq; + } lr->lines[i].desc = desc; flags =gpio_v2_line_config_flags (lc, i);
@@ -1765,8 +1771,11 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) } ret =gpiod_request (desc, le->label); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) + ret = -ENODEV ; goto out_free_le; + } le->desc = desc; le->eflags = eflags;
Signature · 1 line
2.30.2
PATCH 2/2 gpiolib: Introduce gpiod_request_user() helper
The gpiod_request_user() is a special helper to avoid propagating stuff to user space that should not be propagated, e.g. internal error codes.
For now, hide EPROBE_DEFER with ENODEV.
--- drivers/gpio/gpiolib-cdev.c | 21 ++++++--------------- drivers/gpio/gpiolib-sysfs.c | 7 ++----- drivers/gpio/gpiolib.h | 12 ++++++++++++ 3 files changed, 20 insertions(+), 20 deletions(-)
drivers/gpio/gpiolib-cdev.c +6 -15
@@ -330,12 +330,9 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) goto out_free_lh; } - ret =gpiod_request (desc, lh->label); -if (ret) { -if (ret == -EPROBE_DEFER ) - ret = -ENODEV ; + ret =gpiod_request_user (desc, lh->label); +if (ret) goto out_free_lh; - } lh->descs[i] = desc;linehandle_flags_to_desc_flags (handlereq.flags, &desc->flags);
@@ -1381,12 +1378,9 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) goto out_free_linereq; } - ret =gpiod_request (desc, lr->label); -if (ret) { -if (ret == -EPROBE_DEFER ) - ret = -ENODEV ; + ret =gpiod_request_user (desc, lr->label); +if (ret) goto out_free_linereq; - } lr->lines[i].desc = desc; flags =gpio_v2_line_config_flags (lc, i);
@@ -1770,12 +1764,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) } } - ret =gpiod_request (desc, le->label); -if (ret) { -if (ret == -EPROBE_DEFER ) - ret = -ENODEV ; + ret =gpiod_request_user (desc, le->label); +if (ret) goto out_free_le; - } le->desc = desc; le->eflags = eflags;
drivers/gpio/gpiolib-sysfs.c +2 -5
@@ -473,12 +473,9 @@ static ssize_t export_store(struct class *class,* they may be undone on its behalf too. */ - status =gpiod_request (desc,"sysfs" ); -if (status) { -if (status == -EPROBE_DEFER ) - status = -ENODEV ; + status =gpiod_request_user (desc,"sysfs" ); +if (status) goto done; - } status =gpiod_set_transitory (desc, false);if (!status) {
drivers/gpio/gpiolib.h +12 -0
@@ -142,6 +142,18 @@ struct gpio_desc {int gpiod_request (struct gpio_desc *desc,const char *label);void gpiod_free (struct gpio_desc *desc); + +static inline int gpiod_request_user (struct gpio_desc *desc,const char *label) +{ +int ret; + + ret =gpiod_request (desc, label); +if (ret == -EPROBE_DEFER ) + ret = -ENODEV ; + +return ret; +} +int gpiod_configure_flags (struct gpio_desc *desc,const char *con_id,unsigned long lflags,enum gpiod_flags dflags);int gpio_set_debounce_timeout (struct gpio_desc *desc,unsigned int debounce);
Signature · 1 line
2.30.2
Kent Gibson
reviewerQuoted 48 lines · Andy Shevchenko
Currently it's possible that character device interface may return the error codes which are not supposed to be seen by user space. In this case it's
EPROBE_DEFER.Wrap it to return
-ENODEVinstead as sysfs does.Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")Reported-by Suresh Balakrishnan <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>--- drivers/gpio/gpiolib-cdev.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)drivers/gpio/gpiolib-cdev.c +8
-2@@ -331,8 +331,11 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) } ret =gpiod_request (desc, lh->label); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) + ret = -ENODEV ; goto out_free_lh; + } lh->descs[i] = desc;linehandle_flags_to_desc_flags (handlereq.flags, &desc->flags);@@ -1379,8 +1382,11 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) } ret =gpiod_request (desc, lr->label); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) + ret = -ENODEV ; goto out_free_linereq; + } lr->lines[i].desc = desc; flags =gpio_v2_line_config_flags (lc, i);@@ -1765,8 +1771,11 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) }
drivers/gpio/gpiolib-cdev.c static int lineevent_create(struct gpio_device *gdev, void __user *ip) · line 1781
Quoted 10 lines
drivers/gpio/gpiolib-cdev.c +4
-1ret =gpiod_request (desc, le->label); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) + ret = -ENODEV ; goto out_free_le; + } le->desc = desc; le->eflags = eflags;
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set. Why split the patches instead of going direct to the new helper?
Cheers,
Kent.
Quoted 10 lines · Kent Gibson
Quoted 9 lines · Andy Shevchenko
Currently it's possible that character device interface may return the error codes which are not supposed to be seen by user space. In this case it's
EPROBE_DEFER.Wrap it to return
-ENODEVinstead as sysfs does.Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")
...
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Kent Gibson
reviewerQuoted 14 lines · Andy Shevchenko
Quoted 10 lines · Kent Gibson
Quoted 9 lines · Andy Shevchenko
Currently it's possible that character device interface may return the error codes which are not supposed to be seen by user space. In this case it's
EPROBE_DEFER.Wrap it to return
-ENODEVinstead as sysfs does.Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")...
Quoted 9 lines
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Not sure what the constraints are on backporting, but wouldn't it be simpler and cleaner to backport the new helper?
But, as you say, it is the maintainers' call.
Cheers,
Kent.
Quoted 20 lines · Kent Gibson
Quoted 19 lines · Andy Shevchenko
Quoted 10 lines · Kent Gibson
Quoted 9 lines · Andy Shevchenko
Currently it's possible that character device interface may return the error codes which are not supposed to be seen by user space. In this case it's
EPROBE_DEFER.Wrap it to return
-ENODEVinstead as sysfs does.Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")...
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
Quoted 7 lines
Quoted 4 lines
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Not sure what the constraints are on backporting, but wouldn't it be simpler and cleaner to backport the new helper?
Logically (and ideally) it would be three different patches:
1) introduce helper
2) use helper
3) fix places where it's needed to be done
But the above scheme doesn't fit backporting idea (we don't backport new features and APIs without really necessity). So, the options left are:
Option a: One patch (feels a bit like above)
Option b: Two patches like in this series (yes, you are correct about
disadvantages)
Quoted 1 line
But, as you say, it is the maintainers' call.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 42 lines · Andy Shevchenko
Quoted 20 lines · Kent Gibson
Quoted 19 lines · Andy Shevchenko
Quoted 10 lines · Kent Gibson
Quoted 9 lines · Andy Shevchenko
Currently it's possible that character device interface may return the error codes which are not supposed to be seen by user space. In this case it's
EPROBE_DEFER.Wrap it to return
-ENODEVinstead as sysfs does.Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")...
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
Quoted 7 lines
Quoted 4 lines
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Not sure what the constraints are on backporting, but wouldn't it be simpler and cleaner to backport the new helper?
Logically (and ideally) it would be three different patches:
1) introduce helper
2) use helper
3) fix places where it's needed to be doneBut the above scheme doesn't fit backporting idea (we don't backport new features and APIs without really necessity). So, the options left are:
Option a: One patch (feels a bit like above)
Option b: Two patches like in this series (yes, you are correct about
disadvantages)
Quoted 7 lines
Quoted 1 line
But, as you say, it is the maintainers' call.
--
With Best Regards,
Andy Shevchenko
Third option is to backport this patch but apply the helper immediately to master.
Bart
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Kent Gibson
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kent Gibson
On Tue, May 18, 2021 at 06:50:12PM +0300, Andy Shevchenko wrote:
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")
...
Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
Quoted 7 lines
Quoted 4 lines
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Not sure what the constraints are on backporting, but wouldn't it be simpler and cleaner to backport the new helper?
Logically (and ideally) it would be three different patches:
1) introduce helper
2) use helper
3) fix places where it's needed to be doneBut the above scheme doesn't fit backporting idea (we don't backport new features and APIs without really necessity). So, the options left are:
Quoted 8 lines
Quoted 5 lines
Option a: One patch (feels a bit like above)
Option b: Two patches like in this series (yes, you are correct about
disadvantages)Quoted 1 line
But, as you say, it is the maintainers' call.
Third option is to backport this patch but apply the helper immediately to master.
If I got you correctly, you want to have two patches, one for backporting and one for current, correct? But how can we backport something which has never been upstreamed?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 43 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Kent Gibson
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kent Gibson
On Tue, May 18, 2021 at 06:50:12PM +0300, Andy Shevchenko wrote:
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")...
Quoted 25 lines
Quoted 25 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
Quoted 7 lines
Quoted 4 lines
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Not sure what the constraints are on backporting, but wouldn't it be simpler and cleaner to backport the new helper?
Logically (and ideally) it would be three different patches:
1) introduce helper
2) use helper
3) fix places where it's needed to be doneBut the above scheme doesn't fit backporting idea (we don't backport new features and APIs without really necessity). So, the options left are:
Option a: One patch (feels a bit like above)
Option b: Two patches like in this series (yes, you are correct about
disadvantages)
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
But, as you say, it is the maintainers' call.
Third option is to backport this patch but apply the helper immediately to master.
If I got you correctly, you want to have two patches, one for backporting and one for current, correct? But how can we backport something which has never been upstreamed?
Well we would not technically backport anything - there would be one patch for mainline and a separate fix for stable.
Bart
Re: [PATCH v1 2/2] gpiolib: Introduce gpiod_request_user() helper
In reply to Andy ShevchenkoQuoted 6 lines · Andy Shevchenko
The
gpiod_request_user()is a special helper to avoid propagating stuff to user space that should not be propagated, e.g. internal error codes.For now, hide
EPROBE_DEFERwith ENODEV.Signed-off-by Andy Shevchenko <[email protected]>
This looks like a good solution.
Yours,
Linus Walleij
Quoted 50 lines · Bartosz Golaszewski
Quoted 48 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Kent Gibson
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kent Gibson
On Tue, May 18, 2021 at 06:50:12PM +0300, Andy Shevchenko wrote:
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")...
Quoted 29 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
Quoted 7 lines
Quoted 4 lines
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Not sure what the constraints are on backporting, but wouldn't it be simpler and cleaner to backport the new helper?
Logically (and ideally) it would be three different patches:
1) introduce helper
2) use helper
3) fix places where it's needed to be doneQuoted 8 lines
But the above scheme doesn't fit backporting idea (we don't backport new features and APIs without really necessity). So, the options left are:
Option a: One patch (feels a bit like above)
Option b: Two patches like in this series (yes, you are correct about
disadvantages)Quoted 1 line
But, as you say, it is the maintainers' call.
Third option is to backport this patch but apply the helper immediately to master.
Quoted 7 lines
Quoted 4 lines
If I got you correctly, you want to have two patches, one for backporting and one for current, correct? But how can we backport something which has never been upstreamed?
Well we would not technically backport anything - there would be one patch for mainline and a separate fix for stable.
So, what should I do here?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 57 lines · Andy Shevchenko
Quoted 55 lines · Bartosz Golaszewski
Quoted 52 lines · Andy Shevchenko
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Kent Gibson
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Kent Gibson
On Tue, May 18, 2021 at 06:50:12PM +0300, Andy Shevchenko wrote:
...
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Fixes d7c51b47ac11 ("gpio: userspace ABI for reading/writing GPIO lines")Fixes 61f922db7221 ("gpio: userspace ABI for reading GPIO line events")Fixes 3c0d9c635ae2 ("gpiolib: cdev: support GPIO_V2_GET_LINE_IOCTL and GPIO_V2_LINE_GET_VALUES_IOCTL")...
Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
You immediately revert this patch in patch 2.
My understanding is that is not allowed within a patch set.Why split the patches instead of going direct to the new helper?
Quoted 7 lines
Quoted 4 lines
It's for backporting to make it easier. (I deliberately left the context above)
I can fold them if maintainers think it's okay to do.
Not sure what the constraints are on backporting, but wouldn't it be simpler and cleaner to backport the new helper?
Logically (and ideally) it would be three different patches:
1) introduce helper
2) use helper
3) fix places where it's needed to be doneBut the above scheme doesn't fit backporting idea (we don't backport new features and APIs without really necessity). So, the options left are:
Quoted 8 lines
Quoted 5 lines
Option a: One patch (feels a bit like above)
Option b: Two patches like in this series (yes, you are correct about
disadvantages)Quoted 1 line
But, as you say, it is the maintainers' call.
Third option is to backport this patch but apply the helper immediately to master.
If I got you correctly, you want to have two patches, one for backporting and one for current, correct? But how can we backport something which has never been upstreamed?
Quoted 4 lines
Quoted 2 lines
Well we would not technically backport anything - there would be one patch for mainline and a separate fix for stable.
So, what should I do here?
Send a separate patch for stable branches that fixes the issue and fold this patch into the next one in the series for master.
Bart