linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] HID: cp2112: prevent sleeping function called from invalid context
@ 2019-08-12 16:04 Benjamin Tissoires
  2019-08-19 12:13 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: Benjamin Tissoires @ 2019-08-12 16:04 UTC (permalink / raw)
  To: David Barksdale, Jiri Kosina
  Cc: linux-input, linux-kernel, Benjamin Tissoires

When calling request_threaded_irq() with a CP2112, the function
cp2112_gpio_irq_startup() is called in a IRQ context.

Therefore we can not sleep, and we can not call
cp2112_gpio_direction_input() there.

Move the call to cp2112_gpio_direction_input() earlier to have a working
driver.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/hid/hid-cp2112.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c
index 2310c96ccf4a..db1b55df0d13 100644
--- a/drivers/hid/hid-cp2112.c
+++ b/drivers/hid/hid-cp2112.c
@@ -1153,8 +1153,6 @@ static unsigned int cp2112_gpio_irq_startup(struct irq_data *d)
 
 	INIT_DELAYED_WORK(&dev->gpio_poll_worker, cp2112_gpio_poll_callback);
 
-	cp2112_gpio_direction_input(gc, d->hwirq);
-
 	if (!dev->gpio_poll) {
 		dev->gpio_poll = true;
 		schedule_delayed_work(&dev->gpio_poll_worker, 0);
@@ -1204,6 +1202,12 @@ static int __maybe_unused cp2112_allocate_irq(struct cp2112_device *dev,
 		return PTR_ERR(dev->desc[pin]);
 	}
 
+	ret = cp2112_gpio_direction_input(&dev->gc, pin);
+	if (ret < 0) {
+		dev_err(dev->gc.parent, "Failed to set GPIO to input dir\n");
+		goto err_desc;
+	}
+
 	ret = gpiochip_lock_as_irq(&dev->gc, pin);
 	if (ret) {
 		dev_err(dev->gc.parent, "Failed to lock GPIO as interrupt\n");
-- 
2.19.2


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

* Re: [PATCH] HID: cp2112: prevent sleeping function called from invalid context
  2019-08-12 16:04 [PATCH] HID: cp2112: prevent sleeping function called from invalid context Benjamin Tissoires
@ 2019-08-19 12:13 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2019-08-19 12:13 UTC (permalink / raw)
  To: Benjamin Tissoires; +Cc: David Barksdale, linux-input, linux-kernel

On Mon, 12 Aug 2019, Benjamin Tissoires wrote:

> When calling request_threaded_irq() with a CP2112, the function
> cp2112_gpio_irq_startup() is called in a IRQ context.
> 
> Therefore we can not sleep, and we can not call
> cp2112_gpio_direction_input() there.
> 
> Move the call to cp2112_gpio_direction_input() earlier to have a working
> driver.
> 
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Pushed out to for-5.3/upstream-fixes.

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2019-08-19 12:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 16:04 [PATCH] HID: cp2112: prevent sleeping function called from invalid context Benjamin Tissoires
2019-08-19 12:13 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).