All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Gregory CLEMENT <gregory.clement@bootlin.com>,
	Rosen Penev <rosenp@gmail.com>, Rob Herring <robh@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Ralph Sennhauser <ralph.sennhauser@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>
Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
	linux-gpio@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock
Date: Fri,  4 Dec 2026 19:11:10 -0800	[thread overview]
Message-ID: <20261205031111.12306-5-rosenp@gmail.com> (raw)
In-Reply-To: <20261205031111.12306-1-rosenp@gmail.com>

mvebu_pwm_request() calls gpiochip_request_own_desc() with mvpwm->lock
held and interrupts disabled, and mvebu_pwm_free() does the same with
gpiochip_free_own_desc().  Both can sleep: requesting the line goes
through gpiochip_generic_request() and sets the direction through
pinctrl, which takes the pinctrl mutex.

The PWM core already calls .request and .free with pwm_lock held, so
the spinlock adds nothing there.  Drop it from both callbacks.

Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-mvebu.c | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index eda52cfaa145..0672528e97dc 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -662,39 +662,31 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
 	struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
 	struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
 	struct gpio_desc *desc;
-	unsigned long flags;
-	int ret = 0;
 
-	spin_lock_irqsave(&mvpwm->lock, flags);
+	/*
+	 * The PWM core calls .request and .free with pwm_lock held, which
+	 * serialises them; gpiochip_request_own_desc() may sleep, so it must
+	 * not run under mvpwm->lock.
+	 */
+	if (mvpwm->gpiod)
+		return -EBUSY;
 
-	if (mvpwm->gpiod) {
-		ret = -EBUSY;
-	} else {
-		desc = gpiochip_request_own_desc(&mvchip->chip,
-						 pwm->hwpwm, "mvebu-pwm",
-						 GPIO_ACTIVE_HIGH,
-						 GPIOD_OUT_LOW);
-		if (IS_ERR(desc)) {
-			ret = PTR_ERR(desc);
-			goto out;
-		}
+	desc = gpiochip_request_own_desc(&mvchip->chip, pwm->hwpwm, "mvebu-pwm",
+					 GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW);
+	if (IS_ERR(desc))
+		return PTR_ERR(desc);
 
-		mvpwm->gpiod = desc;
-	}
-out:
-	spin_unlock_irqrestore(&mvpwm->lock, flags);
-	return ret;
+	mvpwm->gpiod = desc;
+
+	return 0;
 }
 
 static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 {
 	struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
-	unsigned long flags;
 
-	spin_lock_irqsave(&mvpwm->lock, flags);
 	gpiochip_free_own_desc(mvpwm->gpiod);
 	mvpwm->gpiod = NULL;
-	spin_unlock_irqrestore(&mvpwm->lock, flags);
 }
 
 static int mvebu_pwm_get_state(struct pwm_chip *chip,
-- 
2.56.1


  parent reply	other threads:[~2026-12-05  3:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
2026-12-05  3:11 ` [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too Rosen Penev
2026-12-05  3:11 ` [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock Rosen Penev
2026-12-05  3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
2026-12-05  3:25   ` sashiko-bot
2026-12-05  3:11 ` Rosen Penev [this message]
2026-12-05  3:11 ` [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit Rosen Penev

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=20261205031111.12306-5-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=bigeasy@linutronix.de \
    --cc=brgl@kernel.org \
    --cc=clrkwllms@kernel.org \
    --cc=gregory.clement@bootlin.com \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=ralph.sennhauser@gmail.com \
    --cc=robh@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=thierry.reding@gmail.com \
    /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 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.