All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] gpiolib: Avoid side effects in gpio_is_visible()
@ 2023-05-19  5:07 Chris Packham
  2023-05-19 10:08 ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Chris Packham @ 2023-05-19  5:07 UTC (permalink / raw)
  To: linus.walleij, brgl, andy.shevchenko, johan, maz, warthog618
  Cc: linux-gpio, linux-kernel, Chris Packham

On a system with pca9555 GPIOs that have been exported via sysfs the
following warning could be triggered on kexec().

  WARNING: CPU: 0 PID: 265 at drivers/gpio/gpiolib.c:3411 gpiochip_disable_irq
  Call trace:
   gpiochip_disable_irq
   machine_crash_shutdown
   __crash_kexec
   panic
   sysrq_reset_seq_param_set
   __handle_sysrq
   write_sysrq_trigger

The warning is triggered because there is an irq_desc for the GPIO but
it does not have the FLAG_USED_AS_IRQ set. This is because when the GPIO
is exported via gpiod_export(), gpio_is_visible() is used to determine
if the "edge" attribute should be provided but in doing so it ends up
calling gpiochip_to_irq() which creates the irq_desc.

Remove the call to gpiod_to_irq() from gpio_is_visible(). The actual
intended creation of the irq_desc comes via edge_store() when requested
by the user.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---

Notes:
    Changes in v2:
    - expand commit message to (hopefully) better describe the problem and
      solution
    - drop the inaccurate fixes tag

 drivers/gpio/gpiolib-sysfs.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 530dfd19d7b5..f859dcd1cbf3 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -362,8 +362,6 @@ static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr,
 		if (!show_direction)
 			mode = 0;
 	} else if (attr == &dev_attr_edge.attr) {
-		if (gpiod_to_irq(desc) < 0)
-			mode = 0;
 		if (!show_direction && test_bit(FLAG_IS_OUT, &desc->flags))
 			mode = 0;
 	}
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-29  4:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-19  5:07 [PATCH v2] gpiolib: Avoid side effects in gpio_is_visible() Chris Packham
2023-05-19 10:08 ` Andy Shevchenko
2023-05-26 13:01   ` Bartosz Golaszewski
2023-05-26 13:23     ` Johan Hovold
2023-05-28 21:21       ` Chris Packham
2023-05-29  4:08         ` Chris Packham

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.