Skip to content

Commit 95a4eed

Browse files
andy-shevbrgl
authored andcommitted
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. Fixes: d7c51b4 ("gpio: userspace ABI for reading/writing GPIO lines") Fixes: 61f922d ("gpio: userspace ABI for reading GPIO line events") Fixes: 3c0d9c6 ("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]> Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 2cba054 commit 95a4eed

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
330330
goto out_free_lh;
331331
}
332332

333-
ret = gpiod_request(desc, lh->label);
333+
ret = gpiod_request_user(desc, lh->label);
334334
if (ret)
335335
goto out_free_lh;
336336
lh->descs[i] = desc;
@@ -1378,7 +1378,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
13781378
goto out_free_linereq;
13791379
}
13801380

1381-
ret = gpiod_request(desc, lr->label);
1381+
ret = gpiod_request_user(desc, lr->label);
13821382
if (ret)
13831383
goto out_free_linereq;
13841384

@@ -1764,7 +1764,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
17641764
}
17651765
}
17661766

1767-
ret = gpiod_request(desc, le->label);
1767+
ret = gpiod_request_user(desc, le->label);
17681768
if (ret)
17691769
goto out_free_le;
17701770
le->desc = desc;

drivers/gpio/gpiolib-sysfs.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,9 @@ static ssize_t export_store(struct class *class,
475475
* they may be undone on its behalf too.
476476
*/
477477

478-
status = gpiod_request(desc, "sysfs");
479-
if (status) {
480-
if (status == -EPROBE_DEFER)
481-
status = -ENODEV;
478+
status = gpiod_request_user(desc, "sysfs");
479+
if (status)
482480
goto done;
483-
}
484481

485482
status = gpiod_set_transitory(desc, false);
486483
if (!status) {

drivers/gpio/gpiolib.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ struct gpio_desc {
135135

136136
int gpiod_request(struct gpio_desc *desc, const char *label);
137137
void gpiod_free(struct gpio_desc *desc);
138+
139+
static inline int gpiod_request_user(struct gpio_desc *desc, const char *label)
140+
{
141+
int ret;
142+
143+
ret = gpiod_request(desc, label);
144+
if (ret == -EPROBE_DEFER)
145+
ret = -ENODEV;
146+
147+
return ret;
148+
}
149+
138150
int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
139151
unsigned long lflags, enum gpiod_flags dflags);
140152
int gpio_set_debounce_timeout(struct gpio_desc *desc, unsigned int debounce);

0 commit comments

Comments
 (0)