diff mbox series

[RFT] gpio: mlxbf2: Fix sleeping while holding spinlock

Message ID 20200521015713.2206065-1-axel.lin@ingics.com
State New
Headers show
Series [RFT] gpio: mlxbf2: Fix sleeping while holding spinlock | expand

Commit Message

Axel Lin May 21, 2020, 1:57 a.m. UTC
mutex_lock() can sleep, don't call mutex_lock() while holding spin_lock.

Fixes: bc0ae0e737f5 ("gpio: add driver for Mellanox BlueField 2 GPIO controller")
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Hi Asmaa,
I don't have this h/w to test, please help to review and test this patch.

Thanks,
Axel

 drivers/gpio/gpio-mlxbf2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Asmaa Mnebhi May 21, 2020, 1:56 p.m. UTC | #1
Hi Axel,

Tested it with no problem. Thank you!
Acked-by: asmaa@mellanox.com

-----Original Message-----
From: Axel Lin <axel.lin@ingics.com> 
Sent: Wednesday, May 20, 2020 9:57 PM
To: linux-gpio@vger.kernel.org
Cc: Asmaa Mnebhi <Asmaa@mellanox.com>; Bartosz Golaszewski <bgolaszewski@baylibre.com>; Linus Walleij <linus.walleij@linaro.org>; Axel Lin <axel.lin@ingics.com>
Subject: [RFT][PATCH] gpio: mlxbf2: Fix sleeping while holding spinlock

mutex_lock() can sleep, don't call mutex_lock() while holding spin_lock.

Fixes: bc0ae0e737f5 ("gpio: add driver for Mellanox BlueField 2 GPIO controller")
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
Hi Asmaa,
I don't have this h/w to test, please help to review and test this patch.

Thanks,
Axel

 drivers/gpio/gpio-mlxbf2.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-mlxbf2.c b/drivers/gpio/gpio-mlxbf2.c index fca6a50d9308..94d5efce1721 100644
--- a/drivers/gpio/gpio-mlxbf2.c
+++ b/drivers/gpio/gpio-mlxbf2.c
@@ -126,8 +126,8 @@ static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs)  {
 	u32 arm_gpio_lock_val;
 
-	spin_lock(&gs->gc.bgpio_lock);
 	mutex_lock(yu_arm_gpio_lock_param.lock);
+	spin_lock(&gs->gc.bgpio_lock);
 
 	arm_gpio_lock_val = readl(yu_arm_gpio_lock_param.io);
 
@@ -135,8 +135,8 @@ static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs)
 	 * When lock active bit[31] is set, ModeX is write enabled
 	 */
 	if (YU_LOCK_ACTIVE_BIT(arm_gpio_lock_val)) {
-		mutex_unlock(yu_arm_gpio_lock_param.lock);
 		spin_unlock(&gs->gc.bgpio_lock);
+		mutex_unlock(yu_arm_gpio_lock_param.lock);
 		return -EINVAL;
 	}
 
@@ -151,8 +151,8 @@ static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs)  static void mlxbf2_gpio_lock_release(struct mlxbf2_gpio_context *gs)  {
 	writel(YU_ARM_GPIO_LOCK_RELEASE, yu_arm_gpio_lock_param.io);
-	mutex_unlock(yu_arm_gpio_lock_param.lock);
 	spin_unlock(&gs->gc.bgpio_lock);
+	mutex_unlock(yu_arm_gpio_lock_param.lock);
 }
 
 /*
--
2.25.1
Bartosz Golaszewski May 25, 2020, 9:10 a.m. UTC | #2
czw., 21 maj 2020 o 03:57 Axel Lin <axel.lin@ingics.com> napisaƂ(a):
>
> mutex_lock() can sleep, don't call mutex_lock() while holding spin_lock.
>
> Fixes: bc0ae0e737f5 ("gpio: add driver for Mellanox BlueField 2 GPIO controller")
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---

Applied for fixes, thanks!

Bartosz
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-mlxbf2.c b/drivers/gpio/gpio-mlxbf2.c
index fca6a50d9308..94d5efce1721 100644
--- a/drivers/gpio/gpio-mlxbf2.c
+++ b/drivers/gpio/gpio-mlxbf2.c
@@ -126,8 +126,8 @@  static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs)
 {
 	u32 arm_gpio_lock_val;
 
-	spin_lock(&gs->gc.bgpio_lock);
 	mutex_lock(yu_arm_gpio_lock_param.lock);
+	spin_lock(&gs->gc.bgpio_lock);
 
 	arm_gpio_lock_val = readl(yu_arm_gpio_lock_param.io);
 
@@ -135,8 +135,8 @@  static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs)
 	 * When lock active bit[31] is set, ModeX is write enabled
 	 */
 	if (YU_LOCK_ACTIVE_BIT(arm_gpio_lock_val)) {
-		mutex_unlock(yu_arm_gpio_lock_param.lock);
 		spin_unlock(&gs->gc.bgpio_lock);
+		mutex_unlock(yu_arm_gpio_lock_param.lock);
 		return -EINVAL;
 	}
 
@@ -151,8 +151,8 @@  static int mlxbf2_gpio_lock_acquire(struct mlxbf2_gpio_context *gs)
 static void mlxbf2_gpio_lock_release(struct mlxbf2_gpio_context *gs)
 {
 	writel(YU_ARM_GPIO_LOCK_RELEASE, yu_arm_gpio_lock_param.io);
-	mutex_unlock(yu_arm_gpio_lock_param.lock);
 	spin_unlock(&gs->gc.bgpio_lock);
+	mutex_unlock(yu_arm_gpio_lock_param.lock);
 }
 
 /*