mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Semen Protsenko <semen.protsenko@globallogic.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	Alexandre Courbot <gnurou@gmail.com>
Cc: Grant Likely <grant.likely@linaro.org>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	devicetree@vger.kernel.org, Marc Zyngier <maz@misterjones.org>,
	Grygorii Strashko <grygorii.strashko@globallogic.com>,
	Illia Smyrnov <illia.smyrnov@globallogic.com>
Subject: [PATCH 3/4] gpio: max732x: Fix possible deadlock
Date: Tue, 13 Jan 2015 15:41:44 +0200	[thread overview]
Message-ID: <1421156505-16600-4-git-send-email-semen.protsenko@globallogic.com> (raw)
In-Reply-To: <1421156505-16600-1-git-send-email-semen.protsenko@globallogic.com>

This patch was derived from next one:
"gpio: fix pca953x set_type 'scheduling while atomic' bug".

After adding entry that consumes max732x GPIO as interrupt line to dts
file, deadlock appears somewhere in max732x probe function.

Deadlock caught by lockdep (from kernel log):
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< cut here >>>>>>>>>>>>>>>>>>>>>>>>>>>
[    0.473419] ======================================================
[    0.473419] [ INFO: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected ]
[    0.473449] 3.x.xx-xxxxx-xxxxxxxx-dirty #2 Tainted: G        W
[    0.473449] ------------------------------------------------------
[    0.473449] swapper/0/1 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire:
[    0.473449]  (&lock->wait_lock){+.+...}, at: [<c072e350>] rt_mutex_trylock+0xc/0x74
[    0.473480]
[    0.473480] and this task is already holding:
[    0.473510]  (&chip->lock){......}, at: [<c0314514>] max732x_gpio_set_value+0x2c/0xa4
[    0.473541] which would create a new lock dependency:
[    0.473541]  (&chip->lock){......} -> (&lock->wait_lock){+.+...}

...

[    0.474273]  *** DEADLOCK ***
[    0.474273]
[    0.474273] 5 locks held by swapper/0/1:
[    0.474273]  #0:  (&__lockdep_no_validate__){......}, at: [<c03b2328>] __driver_attach+0x48/0x98
[    0.474304]  #1:  (&__lockdep_no_validate__){......}, at: [<c03b2338>] __driver_attach+0x58/0x98
[    0.474334]  #2:  (&chip->irq_lock){+.+...}, at: [<c0313e3c>] max732x_irq_bus_lock+0x14/0x20
[    0.474365]  #3:  (&irq_desc_lock_class){-.....}, at: [<c00a65a4>] __irq_get_desc_lock+0x48/0x88
[    0.474365]  #4:  (&chip->lock){......}, at: [<c0314514>] max732x_gpio
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< cut here >>>>>>>>>>>>>>>>>>>>>>>>>>>

Signed-off-by: Semen Protsenko <semen.protsenko@globallogic.com>
---
 drivers/gpio/gpio-max732x.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-max732x.c b/drivers/gpio/gpio-max732x.c
index f8f3e80..5fbab13 100644
--- a/drivers/gpio/gpio-max732x.c
+++ b/drivers/gpio/gpio-max732x.c
@@ -377,8 +377,18 @@ static void max732x_irq_bus_lock(struct irq_data *d)
 static void max732x_irq_bus_sync_unlock(struct irq_data *d)
 {
 	struct max732x_chip *chip = irq_data_get_irq_chip_data(d);
+	uint16_t new_irqs;
+	uint16_t level;
 
 	max732x_irq_update_mask(chip);
+
+	new_irqs = chip->irq_trig_fall | chip->irq_trig_raise;
+	while (new_irqs) {
+		level = __ffs(new_irqs);
+		max732x_gpio_direction_input(&chip->gpio_chip, level);
+		new_irqs &= ~(1 << level);
+	}
+
 	mutex_unlock(&chip->irq_lock);
 }
 
@@ -410,7 +420,7 @@ static int max732x_irq_set_type(struct irq_data *d, unsigned int type)
 	else
 		chip->irq_trig_raise &= ~mask;
 
-	return max732x_gpio_direction_input(&chip->gpio_chip, off);
+	return 0;
 }
 
 static struct irq_chip max732x_irq_chip = {
-- 
1.7.9.5


  parent reply	other threads:[~2015-01-13 13:42 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13 13:41 [PATCH 0/4] gpio: max732x: Update MAX732X driver to use modern kernel API Semen Protsenko
2015-01-13 13:41 ` [PATCH 1/4] gpio: max732x: Add device tree support Semen Protsenko
2015-01-15 16:52   ` Linus Walleij
2015-01-13 13:41 ` [PATCH 2/4] gpio: max732x: Rewrite IRQ code to use irq_domain API Semen Protsenko
2015-01-15 17:03   ` Linus Walleij
2015-01-13 13:41 ` Semen Protsenko [this message]
2015-01-15 17:04   ` [PATCH 3/4] gpio: max732x: Fix possible deadlock Linus Walleij
2015-01-13 13:41 ` [PATCH 4/4] gpio: max732x: Add DT binding documentation Semen Protsenko
2015-01-15 17:19   ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421156505-16600-4-git-send-email-semen.protsenko@globallogic.com \
    --to=semen.protsenko@globallogic.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gnurou@gmail.com \
    --cc=grant.likely@linaro.org \
    --cc=grygorii.strashko@globallogic.com \
    --cc=illia.smyrnov@globallogic.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@misterjones.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®