Skip to content

Commit 9c09f62

Browse files
committed
Merge tag 'gpio-v5.3-6' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO fixes from Linus Walleij: "I don't really like to send so many fixes at the very last minute, but the bug-sport activity is unpredictable. Four fixes, three are -stable material that will go everywhere, one is for the current cycle: - An ACPI DSDT error fixup of the type we always see and Hans invariably gets to fix. - A OF quirk fix for the current release (v5.3) - Some consistency checks on the userspace ABI. - A memory leak" * tag 'gpio-v5.3-6' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: gpiolib: acpi: Add gpiolib_acpi_run_edge_events_on_boot option and blacklist gpiolib: of: fix fallback quirks handling gpio: fix line flag validation in lineevent_create gpio: fix line flag validation in linehandle_create gpio: mockup: add missing single_release()
2 parents 3120b9a + 61f7f7c commit 9c09f62

File tree

4 files changed

+59
-27
lines changed

4 files changed

+59
-27
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-acpi.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Mika Westerberg <[email protected]>
88
*/
99

10+
#include <linux/dmi.h>
1011
#include <linux/errno.h>
1112
#include <linux/gpio/consumer.h>
1213
#include <linux/gpio/driver.h>
@@ -19,6 +20,11 @@
1920

2021
#include "gpiolib.h"
2122

23+
static int run_edge_events_on_boot = -1;
24+
module_param(run_edge_events_on_boot, int, 0444);
25+
MODULE_PARM_DESC(run_edge_events_on_boot,
26+
"Run edge _AEI event-handlers at boot: 0=no, 1=yes, -1=auto");
27+
2228
/**
2329
* struct acpi_gpio_event - ACPI GPIO event handler data
2430
*
@@ -170,10 +176,13 @@ static void acpi_gpiochip_request_irq(struct acpi_gpio_chip *acpi_gpio,
170176
event->irq_requested = true;
171177

172178
/* Make sure we trigger the initial state of edge-triggered IRQs */
173-
value = gpiod_get_raw_value_cansleep(event->desc);
174-
if (((event->irqflags & IRQF_TRIGGER_RISING) && value == 1) ||
175-
((event->irqflags & IRQF_TRIGGER_FALLING) && value == 0))
176-
event->handler(event->irq, event);
179+
if (run_edge_events_on_boot &&
180+
(event->irqflags & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING))) {
181+
value = gpiod_get_raw_value_cansleep(event->desc);
182+
if (((event->irqflags & IRQF_TRIGGER_RISING) && value == 1) ||
183+
((event->irqflags & IRQF_TRIGGER_FALLING) && value == 0))
184+
event->handler(event->irq, event);
185+
}
177186
}
178187

179188
static void acpi_gpiochip_request_irqs(struct acpi_gpio_chip *acpi_gpio)
@@ -1283,3 +1292,28 @@ static int acpi_gpio_handle_deferred_request_irqs(void)
12831292
}
12841293
/* We must use _sync so that this runs after the first deferred_probe run */
12851294
late_initcall_sync(acpi_gpio_handle_deferred_request_irqs);
1295+
1296+
static const struct dmi_system_id run_edge_events_on_boot_blacklist[] = {
1297+
{
1298+
.matches = {
1299+
DMI_MATCH(DMI_SYS_VENDOR, "MINIX"),
1300+
DMI_MATCH(DMI_PRODUCT_NAME, "Z83-4"),
1301+
}
1302+
},
1303+
{} /* Terminating entry */
1304+
};
1305+
1306+
static int acpi_gpio_setup_params(void)
1307+
{
1308+
if (run_edge_events_on_boot < 0) {
1309+
if (dmi_check_system(run_edge_events_on_boot_blacklist))
1310+
run_edge_events_on_boot = 0;
1311+
else
1312+
run_edge_events_on_boot = 1;
1313+
}
1314+
1315+
return 0;
1316+
}
1317+
1318+
/* Directly after dmi_setup() which runs as core_initcall() */
1319+
postcore_initcall(acpi_gpio_setup_params);

drivers/gpio/gpiolib-of.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -343,36 +343,27 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
343343

344344
desc = of_get_named_gpiod_flags(dev->of_node, prop_name, idx,
345345
&of_flags);
346-
/*
347-
* -EPROBE_DEFER in our case means that we found a
348-
* valid GPIO property, but no controller has been
349-
* registered so far.
350-
*
351-
* This means we don't need to look any further for
352-
* alternate name conventions, and we should really
353-
* preserve the return code for our user to be able to
354-
* retry probing later.
355-
*/
356-
if (IS_ERR(desc) && PTR_ERR(desc) == -EPROBE_DEFER)
357-
return desc;
358346

359-
if (!IS_ERR(desc) || (PTR_ERR(desc) != -ENOENT))
347+
if (!IS_ERR(desc) || PTR_ERR(desc) != -ENOENT)
360348
break;
361349
}
362350

363-
/* Special handling for SPI GPIOs if used */
364-
if (IS_ERR(desc))
351+
if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
352+
/* Special handling for SPI GPIOs if used */
365353
desc = of_find_spi_gpio(dev, con_id, &of_flags);
366-
if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER) {
354+
}
355+
356+
if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
367357
/* This quirk looks up flags and all */
368358
desc = of_find_spi_cs_gpio(dev, con_id, idx, flags);
369359
if (!IS_ERR(desc))
370360
return desc;
371361
}
372362

373-
/* Special handling for regulator GPIOs if used */
374-
if (IS_ERR(desc) && PTR_ERR(desc) != -EPROBE_DEFER)
363+
if (IS_ERR(desc) && PTR_ERR(desc) == -ENOENT) {
364+
/* Special handling for regulator GPIOs if used */
375365
desc = of_find_regulator_gpio(dev, con_id, &of_flags);
366+
}
376367

377368
if (IS_ERR(desc))
378369
return desc;

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)