Skip to content

Commit aefde29

Browse files
committed
Merge tag 'gpio-v5.4-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux into fixes
gpio: fixes for v5.4 - fix a memory leak in gpio-mockup - fix two flag validation bugs in gpiolib's character device ioctl()'s
2 parents f74c2bb + 5ca2f54 commit aefde29

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

drivers/gpio/gpio-mockup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ static const struct file_operations gpio_mockup_debugfs_ops = {
309309
.read = gpio_mockup_debugfs_read,
310310
.write = gpio_mockup_debugfs_write,
311311
.llseek = no_llseek,
312+
.release = single_release,
312313
};
313314

314315
static void gpio_mockup_debugfs_setup(struct device *dev,

drivers/gpio/gpiolib.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,14 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
535535
if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS)
536536
return -EINVAL;
537537

538+
/*
539+
* Do not allow both INPUT & OUTPUT flags to be set as they are
540+
* contradictory.
541+
*/
542+
if ((lflags & GPIOHANDLE_REQUEST_INPUT) &&
543+
(lflags & GPIOHANDLE_REQUEST_OUTPUT))
544+
return -EINVAL;
545+
538546
/*
539547
* Do not allow OPEN_SOURCE & OPEN_DRAIN flags in a single request. If
540548
* the hardware actually supports enabling both at the same time the
@@ -926,7 +934,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
926934
}
927935

928936
/* This is just wrong: we don't look for events on output lines */
929-
if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
937+
if ((lflags & GPIOHANDLE_REQUEST_OUTPUT) ||
938+
(lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) ||
939+
(lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)) {
930940
ret = -EINVAL;
931941
goto out_free_label;
932942
}
@@ -940,10 +950,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
940950

941951
if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW)
942952
set_bit(FLAG_ACTIVE_LOW, &desc->flags);
943-
if (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN)
944-
set_bit(FLAG_OPEN_DRAIN, &desc->flags);
945-
if (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)
946-
set_bit(FLAG_OPEN_SOURCE, &desc->flags);
947953

948954
ret = gpiod_direction_input(desc);
949955
if (ret)

0 commit comments

Comments
 (0)