public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] pinctrl: Some code cleanup including guards
@ 2026-01-14 15:30 Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 01/11] pinctrl: aspeed: Cleanup header includes Krzysztof Kozlowski
                   ` (10 more replies)
  0 siblings, 11 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Few cleanups - from unused headers - or code simplifyings, including
usage of guards when beneficial.  I did not conver cases where guards
would be mixed with gotos, because this is discouraged practice.

Best regards,
Krzysztof

---
Krzysztof Kozlowski (11):
      pinctrl: aspeed: Cleanup header includes
      pinctrl: starfive: jh7110-sys: Cleanup header includes
      pinctrl: sophgo: Cleanup header includes
      pinctrl: amd: Cleanup header includes
      pinctrl: aw9523: Simplify locking with guard()
      pinctrl: microchip-sgpio: Simplify locking with guard()
      pinctrl: tb10x: Simplify locking with guard()
      pinctrl: tegra-xusb: Return void in padctl enable/disable functions
      pinctrl: tegra-xusb: Simplify locking with guard()
      pinctrl: rockchip: Simplify locking with scoped_guard()
      pinctrl: st: Annotate st_pinconf_dbg_show() as holding mutex

 drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c         |  4 +-
 drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c         |  3 +-
 drivers/pinctrl/aspeed/pinctrl-aspeed-g6.c         |  5 +-
 drivers/pinctrl/pinctrl-amd.c                      |  2 -
 drivers/pinctrl/pinctrl-aw9523.c                   | 53 ++++++++++------------
 drivers/pinctrl/pinctrl-microchip-sgpio.c          |  6 +--
 drivers/pinctrl/pinctrl-rockchip.c                 | 19 ++++----
 drivers/pinctrl/pinctrl-st.c                       |  1 +
 drivers/pinctrl/pinctrl-tb10x.c                    | 17 ++-----
 drivers/pinctrl/sophgo/pinctrl-cv18xx.h            |  4 --
 drivers/pinctrl/sophgo/pinctrl-sg2042.h            |  6 ---
 .../pinctrl/starfive/pinctrl-starfive-jh7110-sys.c |  3 --
 drivers/pinctrl/tegra/pinctrl-tegra-xusb.c         | 28 ++++++------
 13 files changed, 55 insertions(+), 96 deletions(-)
---
base-commit: b775e489bec70895b7ef6b66927886bbac79598f
change-id: 20260114-pinctrl-cleanup-guard-d899b4938b26

Best regards,
-- 
Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>


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

* [PATCH 01/11] pinctrl: aspeed: Cleanup header includes
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-15  1:41   ` Andrew Jeffery
  2026-01-14 15:30 ` [PATCH 02/11] pinctrl: starfive: jh7110-sys: " Krzysztof Kozlowski
                   ` (9 subsequent siblings)
  10 siblings, 1 reply; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Remove unused includes (no mutexes, string functions, no OF functions)
and bring directly used mod_devicetable.h (previously pulled via of.h).

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c | 4 +---
 drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c | 3 +--
 drivers/pinctrl/aspeed/pinctrl-aspeed-g6.c | 5 +----
 3 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c b/drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c
index cb295856dda1..f9d8fb1ab1ec 100644
--- a/drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c
+++ b/drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c
@@ -6,14 +6,12 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
-#include <linux/mutex.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
 #include <linux/pinctrl/pinconf.h>
 #include <linux/pinctrl/pinconf-generic.h>
-#include <linux/string.h>
 #include <linux/types.h>
 
 #include "../core.h"
diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c b/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
index 792089628362..9934ef6205d6 100644
--- a/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
+++ b/drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c
@@ -7,14 +7,13 @@
 #include <linux/io.h>
 #include <linux/kernel.h>
 #include <linux/mfd/syscon.h>
-#include <linux/mutex.h>
+#include <linux/mod_devicetable.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
 #include <linux/pinctrl/pinconf.h>
 #include <linux/pinctrl/pinconf-generic.h>
-#include <linux/string.h>
 #include <linux/types.h>
 
 #include "../core.h"
diff --git a/drivers/pinctrl/aspeed/pinctrl-aspeed-g6.c b/drivers/pinctrl/aspeed/pinctrl-aspeed-g6.c
index b0c7e4f6df9c..8cf61aab81b1 100644
--- a/drivers/pinctrl/aspeed/pinctrl-aspeed-g6.c
+++ b/drivers/pinctrl/aspeed/pinctrl-aspeed-g6.c
@@ -4,13 +4,10 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
-#include <linux/mfd/syscon.h>
-#include <linux/mutex.h>
-#include <linux/of.h>
+#include <linux/mod_devicetable.h>
 #include <linux/platform_device.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinmux.h>
-#include <linux/string.h>
 #include <linux/types.h>
 
 #include "../core.h"

-- 
2.51.0


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

* [PATCH 02/11] pinctrl: starfive: jh7110-sys: Cleanup header includes
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 01/11] pinctrl: aspeed: Cleanup header includes Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-18  9:23   ` Hal Feng
  2026-01-14 15:30 ` [PATCH 03/11] pinctrl: sophgo: " Krzysztof Kozlowski
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Remove unused includes: no clocks, mutexes and resets.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c
index 9b67063a0b0b..44f84e4c29bf 100644
--- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c
+++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c
@@ -7,14 +7,11 @@
  */
 
 #include <linux/bits.h>
-#include <linux/clk.h>
 #include <linux/gpio/driver.h>
 #include <linux/io.h>
 #include <linux/mod_devicetable.h>
 #include <linux/module.h>
-#include <linux/mutex.h>
 #include <linux/platform_device.h>
-#include <linux/reset.h>
 #include <linux/spinlock.h>
 
 #include <linux/pinctrl/pinctrl.h>

-- 
2.51.0


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

* [PATCH 03/11] pinctrl: sophgo: Cleanup header includes
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 01/11] pinctrl: aspeed: Cleanup header includes Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 02/11] pinctrl: starfive: jh7110-sys: " Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-15  1:52   ` Inochi Amaoto
  2026-01-14 15:30 ` [PATCH 04/11] pinctrl: amd: " Krzysztof Kozlowski
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Remove unused includes from internal headers, because they do not have
following: bit manipulations, mutexes, spinlocks and struct devices.
These headers are included by actual C files, which seem to have all
necessary includes.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/sophgo/pinctrl-cv18xx.h | 4 ----
 drivers/pinctrl/sophgo/pinctrl-sg2042.h | 6 ------
 2 files changed, 10 deletions(-)

diff --git a/drivers/pinctrl/sophgo/pinctrl-cv18xx.h b/drivers/pinctrl/sophgo/pinctrl-cv18xx.h
index 759c0e604acf..973ab9a38fcf 100644
--- a/drivers/pinctrl/sophgo/pinctrl-cv18xx.h
+++ b/drivers/pinctrl/sophgo/pinctrl-cv18xx.h
@@ -6,11 +6,7 @@
 #ifndef _PINCTRL_SOPHGO_CV18XX_H
 #define _PINCTRL_SOPHGO_CV18XX_H
 
-#include <linux/bits.h>
 #include <linux/bitfield.h>
-#include <linux/mutex.h>
-#include <linux/spinlock.h>
-#include <linux/platform_device.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinconf.h>
 
diff --git a/drivers/pinctrl/sophgo/pinctrl-sg2042.h b/drivers/pinctrl/sophgo/pinctrl-sg2042.h
index d481973fcf97..1a2b00dde1fa 100644
--- a/drivers/pinctrl/sophgo/pinctrl-sg2042.h
+++ b/drivers/pinctrl/sophgo/pinctrl-sg2042.h
@@ -6,12 +6,6 @@
 #ifndef _PINCTRL_SOPHGO_SG2042_H
 #define _PINCTRL_SOPHGO_SG2042_H
 
-#include <linux/bits.h>
-#include <linux/bitfield.h>
-#include <linux/device.h>
-#include <linux/mutex.h>
-#include <linux/spinlock.h>
-#include <linux/platform_device.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinconf.h>
 

-- 
2.51.0


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

* [PATCH 04/11] pinctrl: amd: Cleanup header includes
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (2 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 03/11] pinctrl: sophgo: " Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 05/11] pinctrl: aw9523: Simplify locking with guard() Krzysztof Kozlowski
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Remove unused includes: no lists and mutexes.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/pinctrl-amd.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 2dac5c71eb00..2af94ef56434 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -21,11 +21,9 @@
 #include <linux/gpio/driver.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
-#include <linux/mutex.h>
 #include <linux/acpi.h>
 #include <linux/seq_file.h>
 #include <linux/interrupt.h>
-#include <linux/list.h>
 #include <linux/bitops.h>
 #include <linux/pinctrl/pinconf.h>
 #include <linux/pinctrl/pinconf-generic.h>

-- 
2.51.0


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

* [PATCH 05/11] pinctrl: aw9523: Simplify locking with guard()
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (3 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 04/11] pinctrl: amd: " Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 06/11] pinctrl: microchip-sgpio: " Krzysztof Kozlowski
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Simplify error handling (less gotos) over locks with guard() which also
removes possibility (at least by reading the code) of returning
uninitialized rc/ret value in aw9523_pconf_set() and
aw9523_gpio_get_multiple() functions.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/pinctrl-aw9523.c | 53 +++++++++++++++++-----------------------
 1 file changed, 23 insertions(+), 30 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-aw9523.c b/drivers/pinctrl/pinctrl-aw9523.c
index 479553a79216..02a24ac87ea4 100644
--- a/drivers/pinctrl/pinctrl-aw9523.c
+++ b/drivers/pinctrl/pinctrl-aw9523.c
@@ -291,14 +291,14 @@ static int aw9523_pconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 	unsigned int mask, val;
 	int i, rc;
 
-	mutex_lock(&awi->i2c_lock);
+	guard(mutex)(&awi->i2c_lock);
 	for (i = 0; i < num_configs; i++) {
 		param = pinconf_to_config_param(configs[i]);
 		arg = pinconf_to_config_argument(configs[i]);
 
 		rc = aw9523_pcfg_param_to_reg(param, pin, &reg);
 		if (rc)
-			goto end;
+			return rc;
 
 		switch (param) {
 		case PIN_CONFIG_LEVEL:
@@ -307,7 +307,7 @@ static int aw9523_pconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 						AW9523_REG_CONF_STATE(pin),
 						BIT(regbit), 0);
 			if (rc)
-				goto end;
+				return rc;
 
 			/* Then, fall through to config output level */
 			fallthrough;
@@ -323,10 +323,9 @@ static int aw9523_pconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			break;
 		case PIN_CONFIG_DRIVE_OPEN_DRAIN:
 			/* Open-Drain is supported only on port 0 */
-			if (pin >= AW9523_PINS_PER_PORT) {
-				rc = -ENOTSUPP;
-				goto end;
-			}
+			if (pin >= AW9523_PINS_PER_PORT)
+				return -ENOTSUPP;
+
 			mask = AW9523_GCR_GPOMD_MASK;
 			val = 0;
 			break;
@@ -341,17 +340,15 @@ static int aw9523_pconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			val = AW9523_GCR_GPOMD_MASK;
 			break;
 		default:
-			rc = -ENOTSUPP;
-			goto end;
+			return -ENOTSUPP;
 		}
 
 		rc = regmap_update_bits(awi->regmap, reg, mask, val);
 		if (rc)
-			goto end;
+			return rc;
 	}
-end:
-	mutex_unlock(&awi->i2c_lock);
-	return rc;
+
+	return 0;
 }
 
 static const struct pinconf_ops aw9523_pinconf_ops = {
@@ -599,14 +596,14 @@ static int aw9523_gpio_get_multiple(struct gpio_chip *chip,
 	u8 m, state = 0;
 	int ret;
 
-	mutex_lock(&awi->i2c_lock);
+	guard(mutex)(&awi->i2c_lock);
 
 	/* Port 0 (gpio 0-7) */
 	m = *mask;
 	if (m) {
 		ret = _aw9523_gpio_get_multiple(awi, 0, &state, m);
 		if (ret)
-			goto out;
+			return ret;
 	}
 	*bits = state;
 
@@ -616,13 +613,12 @@ static int aw9523_gpio_get_multiple(struct gpio_chip *chip,
 		ret = _aw9523_gpio_get_multiple(awi, AW9523_PINS_PER_PORT,
 						&state, m);
 		if (ret)
-			goto out;
+			return ret;
 
 		*bits |= (state << 8);
 	}
-out:
-	mutex_unlock(&awi->i2c_lock);
-	return ret;
+
+	return 0;
 }
 
 static int aw9523_gpio_set_multiple(struct gpio_chip *chip,
@@ -632,30 +628,28 @@ static int aw9523_gpio_set_multiple(struct gpio_chip *chip,
 	struct aw9523 *awi = gpiochip_get_data(chip);
 	u8 mask_lo, mask_hi, bits_lo, bits_hi;
 	unsigned int reg;
-	int ret = 0;
+	int ret;
 
 	mask_lo = *mask;
 	mask_hi = *mask >> 8;
 	bits_lo = *bits;
 	bits_hi = *bits >> 8;
 
-	mutex_lock(&awi->i2c_lock);
+	guard(mutex)(&awi->i2c_lock);
 	if (mask_hi) {
 		reg = AW9523_REG_OUT_STATE(AW9523_PINS_PER_PORT);
 		ret = regmap_write_bits(awi->regmap, reg, mask_hi, bits_hi);
 		if (ret)
-			goto out;
+			return ret;
 	}
 	if (mask_lo) {
 		reg = AW9523_REG_OUT_STATE(0);
 		ret = regmap_write_bits(awi->regmap, reg, mask_lo, bits_lo);
 		if (ret)
-			goto out;
+			return ret;
 	}
 
-out:
-	mutex_unlock(&awi->i2c_lock);
-	return ret;
+	return 0;
 }
 
 static int aw9523_gpio_set(struct gpio_chip *chip, unsigned int offset,
@@ -695,16 +689,15 @@ static int aw9523_direction_output(struct gpio_chip *chip,
 	u8 regbit = offset % AW9523_PINS_PER_PORT;
 	int ret;
 
-	mutex_lock(&awi->i2c_lock);
+	guard(mutex)(&awi->i2c_lock);
 	ret = regmap_update_bits(awi->regmap, AW9523_REG_OUT_STATE(offset),
 				 BIT(regbit), value ? BIT(regbit) : 0);
 	if (ret)
-		goto end;
+		return ret;
 
 	ret = regmap_update_bits(awi->regmap, AW9523_REG_CONF_STATE(offset),
 				 BIT(regbit), 0);
-end:
-	mutex_unlock(&awi->i2c_lock);
+
 	return ret;
 }
 

-- 
2.51.0


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

* [PATCH 06/11] pinctrl: microchip-sgpio: Simplify locking with guard()
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (4 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 05/11] pinctrl: aw9523: Simplify locking with guard() Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 07/11] pinctrl: tb10x: " Krzysztof Kozlowski
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Simplify error handling (less gotos) over locks with guard().

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/pinctrl-microchip-sgpio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c
index b6363f3cdce9..7a6cb5f502b0 100644
--- a/drivers/pinctrl/pinctrl-microchip-sgpio.c
+++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c
@@ -264,19 +264,17 @@ static int sgpio_single_shot(struct sgpio_priv *priv)
 	 * setting.
 	 * After the manual burst, reenable the auto repeat mode again.
 	 */
-	mutex_lock(&priv->poll_lock);
+	guard(mutex)(&priv->poll_lock);
 	ret = regmap_update_bits(priv->regs, addr, single_shot | auto_repeat,
 				 single_shot);
 	if (ret)
-		goto out;
+		return ret;
 
 	ret = regmap_read_poll_timeout(priv->regs, addr, ctrl,
 				       !(ctrl & single_shot), 100, 60000);
 
 	/* reenable auto repeat mode even if there was an error */
 	ret2 = regmap_update_bits(priv->regs, addr, auto_repeat, auto_repeat);
-out:
-	mutex_unlock(&priv->poll_lock);
 
 	return ret ?: ret2;
 }

-- 
2.51.0


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

* [PATCH 07/11] pinctrl: tb10x: Simplify locking with guard()
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (5 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 06/11] pinctrl: microchip-sgpio: " Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions Krzysztof Kozlowski
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Simplify error handling (less code in error case) over locks with
guard().

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/pinctrl-tb10x.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-tb10x.c b/drivers/pinctrl/pinctrl-tb10x.c
index 129fa51d13b1..3f581404a9b9 100644
--- a/drivers/pinctrl/pinctrl-tb10x.c
+++ b/drivers/pinctrl/pinctrl-tb10x.c
@@ -607,7 +607,7 @@ static int tb10x_gpio_request_enable(struct pinctrl_dev *pctl,
 	int muxmode = -1;
 	int i;
 
-	mutex_lock(&state->mutex);
+	guard(mutex)(&state->mutex);
 
 	/*
 	 * Figure out to which port the requested GPIO belongs and how to
@@ -642,7 +642,6 @@ static int tb10x_gpio_request_enable(struct pinctrl_dev *pctl,
 					 * Error: The requested pin is already
 					 * used for something else.
 					 */
-					mutex_unlock(&state->mutex);
 					return -EBUSY;
 				}
 				break;
@@ -667,8 +666,6 @@ static int tb10x_gpio_request_enable(struct pinctrl_dev *pctl,
 	if (muxport >= 0)
 		tb10x_pinctrl_set_config(state, muxport, muxmode);
 
-	mutex_unlock(&state->mutex);
-
 	return 0;
 }
 
@@ -695,34 +692,28 @@ static int tb10x_pctl_set_mux(struct pinctrl_dev *pctl,
 	if (grp->port < 0)
 		return 0;
 
-	mutex_lock(&state->mutex);
+	guard(mutex)(&state->mutex);
 
 	/*
 	 * Check if the requested function is compatible with previously
 	 * requested functions.
 	 */
 	if (state->ports[grp->port].count
-			&& (state->ports[grp->port].mode != grp->mode)) {
-		mutex_unlock(&state->mutex);
+			&& (state->ports[grp->port].mode != grp->mode))
 		return -EBUSY;
-	}
 
 	/*
 	 * Check if the requested function is compatible with previously
 	 * requested GPIOs.
 	 */
 	for (i = 0; i < grp->pincnt; i++)
-		if (test_bit(grp->pins[i], state->gpios)) {
-			mutex_unlock(&state->mutex);
+		if (test_bit(grp->pins[i], state->gpios))
 			return -EBUSY;
-		}
 
 	tb10x_pinctrl_set_config(state, grp->port, grp->mode);
 
 	state->ports[grp->port].count++;
 
-	mutex_unlock(&state->mutex);
-
 	return 0;
 }
 

-- 
2.51.0


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

* [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (6 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 07/11] pinctrl: tb10x: " Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-14 16:07   ` Jon Hunter
  2026-01-16 12:50   ` Thierry Reding
  2026-01-14 15:30 ` [PATCH 09/11] pinctrl: tegra-xusb: Simplify locking with guard() Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  10 siblings, 2 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Make the padctl functions a bit simpler by returning void instead of
always '0'.  The callers - phy init/exit - still need to return 0, but
these are smaller function without if/branching.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/tegra/pinctrl-tegra-xusb.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
index 49c5edeba87f..34a373f7e04d 100644
--- a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
+++ b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
@@ -474,7 +474,7 @@ static const struct pinconf_ops tegra_xusb_padctl_pinconf_ops = {
 #endif
 };
 
-static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
+static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
 {
 	u32 value;
 
@@ -501,10 +501,9 @@ static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
 
 out:
 	mutex_unlock(&padctl->lock);
-	return 0;
 }
 
-static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
+static void tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
 {
 	u32 value;
 
@@ -534,21 +533,24 @@ static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
 
 out:
 	mutex_unlock(&padctl->lock);
-	return 0;
 }
 
 static int tegra_xusb_phy_init(struct phy *phy)
 {
 	struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
 
-	return tegra_xusb_padctl_enable(padctl);
+	tegra_xusb_padctl_enable(padctl);
+
+	return 0;
 }
 
 static int tegra_xusb_phy_exit(struct phy *phy)
 {
 	struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
 
-	return tegra_xusb_padctl_disable(padctl);
+	tegra_xusb_padctl_disable(padctl);
+
+	return 0;
 }
 
 static int pcie_phy_power_on(struct phy *phy)

-- 
2.51.0


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

* [PATCH 09/11] pinctrl: tegra-xusb: Simplify locking with guard()
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (7 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-14 15:51   ` Jon Hunter
  2026-01-14 15:30 ` [PATCH 10/11] pinctrl: rockchip: Simplify locking with scoped_guard() Krzysztof Kozlowski
  2026-01-14 15:30 ` [PATCH 11/11] pinctrl: st: Annotate st_pinconf_dbg_show() as holding mutex Krzysztof Kozlowski
  10 siblings, 1 reply; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Simplify error handling (less gotos) over locks with guard().

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/tegra/pinctrl-tegra-xusb.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
index 34a373f7e04d..855f708ce510 100644
--- a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
+++ b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
@@ -478,10 +478,10 @@ static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
 {
 	u32 value;
 
-	mutex_lock(&padctl->lock);
+	guard(mutex)(&padctl->lock);
 
 	if (padctl->enable++ > 0)
-		goto out;
+		return;
 
 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
 	value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
@@ -499,7 +499,6 @@ static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
 	value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
 
-out:
 	mutex_unlock(&padctl->lock);
 }
 
@@ -507,13 +506,13 @@ static void tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
 {
 	u32 value;
 
-	mutex_lock(&padctl->lock);
+	guard(mutex)(&padctl->lock);
 
 	if (WARN_ON(padctl->enable == 0))
-		goto out;
+		return;
 
 	if (--padctl->enable > 0)
-		goto out;
+		return;
 
 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
 	value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
@@ -530,9 +529,6 @@ static void tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
 	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
 	value |= XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
 	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
-
-out:
-	mutex_unlock(&padctl->lock);
 }
 
 static int tegra_xusb_phy_init(struct phy *phy)

-- 
2.51.0


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

* [PATCH 10/11] pinctrl: rockchip: Simplify locking with scoped_guard()
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (8 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 09/11] pinctrl: tegra-xusb: Simplify locking with guard() Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-15 16:14   ` Heiko Stübner
  2026-01-14 15:30 ` [PATCH 11/11] pinctrl: st: Annotate st_pinconf_dbg_show() as holding mutex Krzysztof Kozlowski
  10 siblings, 1 reply; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Simplify error handling by removing two mutex_unlock() calls with
scoped_guard().

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/pinctrl/pinctrl-rockchip.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index e44ef262beec..bbe1cf712965 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -3640,17 +3640,16 @@ static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
 			 * The lock makes sure that either gpio-probe has completed
 			 * or the gpio driver hasn't probed yet.
 			 */
-			mutex_lock(&bank->deferred_lock);
-			if (!gpio || !gpio->direction_output) {
-				rc = rockchip_pinconf_defer_pin(bank, pin - bank->pin_base, param,
-								arg);
-				mutex_unlock(&bank->deferred_lock);
-				if (rc)
-					return rc;
-
-				break;
+			scoped_guard(mutex, &bank->deferred_lock) {
+				if (!gpio || !gpio->direction_output) {
+					rc = rockchip_pinconf_defer_pin(bank,
+									pin - bank->pin_base,
+									param, arg);
+					if (rc)
+						return rc;
+					break;
+				}
 			}
-			mutex_unlock(&bank->deferred_lock);
 		}
 
 		switch (param) {

-- 
2.51.0


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

* [PATCH 11/11] pinctrl: st: Annotate st_pinconf_dbg_show() as holding mutex
  2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
                   ` (9 preceding siblings ...)
  2026-01-14 15:30 ` [PATCH 10/11] pinctrl: rockchip: Simplify locking with scoped_guard() Krzysztof Kozlowski
@ 2026-01-14 15:30 ` Krzysztof Kozlowski
  2026-01-14 17:19   ` Patrice CHOTARD
  10 siblings, 1 reply; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 15:30 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

st_pinconf_dbg_show() unlocks and locks the pinctrl_dev mutex, so it
must be called by the pinctrl core with the mutex hold.  Annotate the
function with sparse __must_hold, so any changes in pinctrl locking will
be statically detected.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>

---

I think this is still useful, although maybe a bit pointless if core
explicitly always locks every pin_config_dbg_show() call? Anyway,
pattern of unlock+lock feels to me like something worth annotating.

I left the patch at the end of the set so it can be nicely discarded.
---
 drivers/pinctrl/pinctrl-st.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
index d3cea3437d7f..8ce88e591f47 100644
--- a/drivers/pinctrl/pinctrl-st.c
+++ b/drivers/pinctrl/pinctrl-st.c
@@ -987,6 +987,7 @@ static int st_pinconf_get(struct pinctrl_dev *pctldev,
 
 static void st_pinconf_dbg_show(struct pinctrl_dev *pctldev,
 				   struct seq_file *s, unsigned pin_id)
+	__must_hold(&pctldev->mutex)
 {
 	struct st_pio_control *pc;
 	unsigned long config;

-- 
2.51.0


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

* Re: [PATCH 09/11] pinctrl: tegra-xusb: Simplify locking with guard()
  2026-01-14 15:30 ` [PATCH 09/11] pinctrl: tegra-xusb: Simplify locking with guard() Krzysztof Kozlowski
@ 2026-01-14 15:51   ` Jon Hunter
  2026-01-14 16:01     ` Krzysztof Kozlowski
  0 siblings, 1 reply; 21+ messages in thread
From: Jon Hunter @ 2026-01-14 15:51 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Andrew Jeffery, Linus Walleij, Joel Stanley,
	Emil Renner Berthing, Hal Feng, Chen Wang, Inochi Amaoto,
	Basavaraj Natikar, Shyam Sundar S K, Bartosz Golaszewski,
	Steen Hegelund, Daniel Machon, UNGLinuxDriver, Thierry Reding,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip


On 14/01/2026 15:30, Krzysztof Kozlowski wrote:
> Simplify error handling (less gotos) over locks with guard().
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
>   drivers/pinctrl/tegra/pinctrl-tegra-xusb.c | 14 +++++---------
>   1 file changed, 5 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
> index 34a373f7e04d..855f708ce510 100644
> --- a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
> +++ b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
> @@ -478,10 +478,10 @@ static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
>   {
>   	u32 value;
>   
> -	mutex_lock(&padctl->lock);
> +	guard(mutex)(&padctl->lock);
>   
>   	if (padctl->enable++ > 0)
> -		goto out;
> +		return;
>   
>   	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
>   	value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
> @@ -499,7 +499,6 @@ static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
>   	value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
>   	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
>   
> -out:
>   	mutex_unlock(&padctl->lock);
>   }


I believe we need to remove the above unlock too?

Jon

-- 
nvpublic


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

* Re: [PATCH 09/11] pinctrl: tegra-xusb: Simplify locking with guard()
  2026-01-14 15:51   ` Jon Hunter
@ 2026-01-14 16:01     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 21+ messages in thread
From: Krzysztof Kozlowski @ 2026-01-14 16:01 UTC (permalink / raw)
  To: Jon Hunter, Andrew Jeffery, Linus Walleij, Joel Stanley,
	Emil Renner Berthing, Hal Feng, Chen Wang, Inochi Amaoto,
	Basavaraj Natikar, Shyam Sundar S K, Bartosz Golaszewski,
	Steen Hegelund, Daniel Machon, UNGLinuxDriver, Thierry Reding,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip

On 14/01/2026 16:51, Jon Hunter wrote:
> 
> On 14/01/2026 15:30, Krzysztof Kozlowski wrote:
>> Simplify error handling (less gotos) over locks with guard().
>>
>> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
>> ---
>>   drivers/pinctrl/tegra/pinctrl-tegra-xusb.c | 14 +++++---------
>>   1 file changed, 5 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
>> index 34a373f7e04d..855f708ce510 100644
>> --- a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
>> +++ b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
>> @@ -478,10 +478,10 @@ static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
>>   {
>>   	u32 value;
>>   
>> -	mutex_lock(&padctl->lock);
>> +	guard(mutex)(&padctl->lock);
>>   
>>   	if (padctl->enable++ > 0)
>> -		goto out;
>> +		return;
>>   
>>   	value = padctl_readl(padctl, XUSB_PADCTL_ELPG_PROGRAM);
>>   	value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_CLAMP_EN;
>> @@ -499,7 +499,6 @@ static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
>>   	value &= ~XUSB_PADCTL_ELPG_PROGRAM_AUX_MUX_LP0_VCORE_DOWN;
>>   	padctl_writel(padctl, value, XUSB_PADCTL_ELPG_PROGRAM);
>>   
>> -out:
>>   	mutex_unlock(&padctl->lock);
>>   }
> 
> 
> I believe we need to remove the above unlock too?

Uh, of course, thanks. Some rebasing mixup on my side.

Best regards,
Krzysztof

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

* Re: [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions
  2026-01-14 15:30 ` [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions Krzysztof Kozlowski
@ 2026-01-14 16:07   ` Jon Hunter
  2026-01-16 12:50   ` Thierry Reding
  1 sibling, 0 replies; 21+ messages in thread
From: Jon Hunter @ 2026-01-14 16:07 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Andrew Jeffery, Linus Walleij, Joel Stanley,
	Emil Renner Berthing, Hal Feng, Chen Wang, Inochi Amaoto,
	Basavaraj Natikar, Shyam Sundar S K, Bartosz Golaszewski,
	Steen Hegelund, Daniel Machon, UNGLinuxDriver, Thierry Reding,
	Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip



On 14/01/2026 15:30, Krzysztof Kozlowski wrote:
> Make the padctl functions a bit simpler by returning void instead of
> always '0'.  The callers - phy init/exit - still need to return 0, but
> these are smaller function without if/branching.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
>   drivers/pinctrl/tegra/pinctrl-tegra-xusb.c | 14 ++++++++------
>   1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
> index 49c5edeba87f..34a373f7e04d 100644
> --- a/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
> +++ b/drivers/pinctrl/tegra/pinctrl-tegra-xusb.c
> @@ -474,7 +474,7 @@ static const struct pinconf_ops tegra_xusb_padctl_pinconf_ops = {
>   #endif
>   };
>   
> -static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
> +static void tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
>   {
>   	u32 value;
>   
> @@ -501,10 +501,9 @@ static int tegra_xusb_padctl_enable(struct tegra_xusb_padctl *padctl)
>   
>   out:
>   	mutex_unlock(&padctl->lock);
> -	return 0;
>   }
>   
> -static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
> +static void tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
>   {
>   	u32 value;
>   
> @@ -534,21 +533,24 @@ static int tegra_xusb_padctl_disable(struct tegra_xusb_padctl *padctl)
>   
>   out:
>   	mutex_unlock(&padctl->lock);
> -	return 0;
>   }
>   
>   static int tegra_xusb_phy_init(struct phy *phy)
>   {
>   	struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
>   
> -	return tegra_xusb_padctl_enable(padctl);
> +	tegra_xusb_padctl_enable(padctl);
> +
> +	return 0;
>   }
>   
>   static int tegra_xusb_phy_exit(struct phy *phy)
>   {
>   	struct tegra_xusb_padctl *padctl = phy_get_drvdata(phy);
>   
> -	return tegra_xusb_padctl_disable(padctl);
> +	tegra_xusb_padctl_disable(padctl);
> +
> +	return 0;
>   }
>   
>   static int pcie_phy_power_on(struct phy *phy)
> 

Reviewed-by: Jon Hunter <jonathanh@nvidia.com>

Thanks
Jon

-- 
nvpublic


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

* Re: [PATCH 11/11] pinctrl: st: Annotate st_pinconf_dbg_show() as holding mutex
  2026-01-14 15:30 ` [PATCH 11/11] pinctrl: st: Annotate st_pinconf_dbg_show() as holding mutex Krzysztof Kozlowski
@ 2026-01-14 17:19   ` Patrice CHOTARD
  0 siblings, 0 replies; 21+ messages in thread
From: Patrice CHOTARD @ 2026-01-14 17:19 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Andrew Jeffery, Linus Walleij, Joel Stanley,
	Emil Renner Berthing, Hal Feng, Chen Wang, Inochi Amaoto,
	Basavaraj Natikar, Shyam Sundar S K, Bartosz Golaszewski,
	Steen Hegelund, Daniel Machon, UNGLinuxDriver, Thierry Reding,
	Jonathan Hunter, Heiko Stuebner
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip



On 1/14/26 16:30, Krzysztof Kozlowski wrote:
> st_pinconf_dbg_show() unlocks and locks the pinctrl_dev mutex, so it
> must be called by the pinctrl core with the mutex hold.  Annotate the
> function with sparse __must_hold, so any changes in pinctrl locking will
> be statically detected.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> 
> ---
> 
> I think this is still useful, although maybe a bit pointless if core
> explicitly always locks every pin_config_dbg_show() call? Anyway,
> pattern of unlock+lock feels to me like something worth annotating.
> 
> I left the patch at the end of the set so it can be nicely discarded.
> ---
>  drivers/pinctrl/pinctrl-st.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-st.c b/drivers/pinctrl/pinctrl-st.c
> index d3cea3437d7f..8ce88e591f47 100644
> --- a/drivers/pinctrl/pinctrl-st.c
> +++ b/drivers/pinctrl/pinctrl-st.c
> @@ -987,6 +987,7 @@ static int st_pinconf_get(struct pinctrl_dev *pctldev,
>  
>  static void st_pinconf_dbg_show(struct pinctrl_dev *pctldev,
>  				   struct seq_file *s, unsigned pin_id)
> +	__must_hold(&pctldev->mutex)
>  {
>  	struct st_pio_control *pc;
>  	unsigned long config;
> 

Hi Krzysztof

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

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

* Re: [PATCH 01/11] pinctrl: aspeed: Cleanup header includes
  2026-01-14 15:30 ` [PATCH 01/11] pinctrl: aspeed: Cleanup header includes Krzysztof Kozlowski
@ 2026-01-15  1:41   ` Andrew Jeffery
  0 siblings, 0 replies; 21+ messages in thread
From: Andrew Jeffery @ 2026-01-15  1:41 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Linus Walleij, Joel Stanley,
	Emil Renner Berthing, Hal Feng, Chen Wang, Inochi Amaoto,
	Basavaraj Natikar, Shyam Sundar S K, Bartosz Golaszewski,
	Steen Hegelund, Daniel Machon, UNGLinuxDriver, Thierry Reding,
	Jonathan Hunter, Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip

On Wed, 2026-01-14 at 16:30 +0100, Krzysztof Kozlowski wrote:
> Remove unused includes (no mutexes, string functions, no OF functions)
> and bring directly used mod_devicetable.h (previously pulled via of.h).
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
>  drivers/pinctrl/aspeed/pinctrl-aspeed-g4.c | 4 +---
>  drivers/pinctrl/aspeed/pinctrl-aspeed-g5.c | 3 +--
>  drivers/pinctrl/aspeed/pinctrl-aspeed-g6.c | 5 +----
>  3 files changed, 3 insertions(+), 9 deletions(-)

Reviewed-by: Andrew Jeffery <andrew@codeconstruct.com.au>

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

* Re: [PATCH 03/11] pinctrl: sophgo: Cleanup header includes
  2026-01-14 15:30 ` [PATCH 03/11] pinctrl: sophgo: " Krzysztof Kozlowski
@ 2026-01-15  1:52   ` Inochi Amaoto
  0 siblings, 0 replies; 21+ messages in thread
From: Inochi Amaoto @ 2026-01-15  1:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Andrew Jeffery, Linus Walleij, Joel Stanley,
	Emil Renner Berthing, Hal Feng, Chen Wang, Inochi Amaoto,
	Basavaraj Natikar, Shyam Sundar S K, Bartosz Golaszewski,
	Steen Hegelund, Daniel Machon, UNGLinuxDriver, Thierry Reding,
	Jonathan Hunter, Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip

On Wed, Jan 14, 2026 at 04:30:04PM +0100, Krzysztof Kozlowski wrote:
> Remove unused includes from internal headers, because they do not have
> following: bit manipulations, mutexes, spinlocks and struct devices.
> These headers are included by actual C files, which seem to have all
> necessary includes.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
>  drivers/pinctrl/sophgo/pinctrl-cv18xx.h | 4 ----
>  drivers/pinctrl/sophgo/pinctrl-sg2042.h | 6 ------
>  2 files changed, 10 deletions(-)
> 
> diff --git a/drivers/pinctrl/sophgo/pinctrl-cv18xx.h b/drivers/pinctrl/sophgo/pinctrl-cv18xx.h
> index 759c0e604acf..973ab9a38fcf 100644
> --- a/drivers/pinctrl/sophgo/pinctrl-cv18xx.h
> +++ b/drivers/pinctrl/sophgo/pinctrl-cv18xx.h
> @@ -6,11 +6,7 @@
>  #ifndef _PINCTRL_SOPHGO_CV18XX_H
>  #define _PINCTRL_SOPHGO_CV18XX_H
>  
> -#include <linux/bits.h>
>  #include <linux/bitfield.h>
> -#include <linux/mutex.h>
> -#include <linux/spinlock.h>
> -#include <linux/platform_device.h>
>  #include <linux/pinctrl/pinctrl.h>
>  #include <linux/pinctrl/pinconf.h>
>  
> diff --git a/drivers/pinctrl/sophgo/pinctrl-sg2042.h b/drivers/pinctrl/sophgo/pinctrl-sg2042.h
> index d481973fcf97..1a2b00dde1fa 100644
> --- a/drivers/pinctrl/sophgo/pinctrl-sg2042.h
> +++ b/drivers/pinctrl/sophgo/pinctrl-sg2042.h
> @@ -6,12 +6,6 @@
>  #ifndef _PINCTRL_SOPHGO_SG2042_H
>  #define _PINCTRL_SOPHGO_SG2042_H
>  
> -#include <linux/bits.h>
> -#include <linux/bitfield.h>
> -#include <linux/device.h>
> -#include <linux/mutex.h>
> -#include <linux/spinlock.h>
> -#include <linux/platform_device.h>
>  #include <linux/pinctrl/pinctrl.h>
>  #include <linux/pinctrl/pinconf.h>
>  
> 
> -- 
> 2.51.0
> 

Thanks.

Reviewed-by: Inochi Amaoto <inochiama@gmail.com>

Regards,
Inochi

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

* Re: [PATCH 10/11] pinctrl: rockchip: Simplify locking with scoped_guard()
  2026-01-14 15:30 ` [PATCH 10/11] pinctrl: rockchip: Simplify locking with scoped_guard() Krzysztof Kozlowski
@ 2026-01-15 16:14   ` Heiko Stübner
  0 siblings, 0 replies; 21+ messages in thread
From: Heiko Stübner @ 2026-01-15 16:14 UTC (permalink / raw)
  To: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Thierry Reding, Jonathan Hunter,
	Patrice Chotard, Krzysztof Kozlowski
  Cc: linux-aspeed, openbmc, linux-gpio, linux-arm-kernel, linux-kernel,
	sophgo, linux-tegra, linux-rockchip, Krzysztof Kozlowski

Am Mittwoch, 14. Januar 2026, 16:30:11 Mitteleuropäische Normalzeit schrieb Krzysztof Kozlowski:
> Simplify error handling by removing two mutex_unlock() calls with
> scoped_guard().
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>

Reviewed-by: Heiko Stuebner <heiko@sntech.de>



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

* Re: [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions
  2026-01-14 15:30 ` [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions Krzysztof Kozlowski
  2026-01-14 16:07   ` Jon Hunter
@ 2026-01-16 12:50   ` Thierry Reding
  1 sibling, 0 replies; 21+ messages in thread
From: Thierry Reding @ 2026-01-16 12:50 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Andrew Jeffery, Linus Walleij, Joel Stanley, Emil Renner Berthing,
	Hal Feng, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver, Jonathan Hunter, Heiko Stuebner,
	Patrice Chotard, linux-aspeed, openbmc, linux-gpio,
	linux-arm-kernel, linux-kernel, sophgo, linux-tegra,
	linux-rockchip

[-- Attachment #1: Type: text/plain, Size: 524 bytes --]

On Wed, Jan 14, 2026 at 04:30:09PM +0100, Krzysztof Kozlowski wrote:
> Make the padctl functions a bit simpler by returning void instead of
> always '0'.  The callers - phy init/exit - still need to return 0, but
> these are smaller function without if/branching.
> 
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---
>  drivers/pinctrl/tegra/pinctrl-tegra-xusb.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* RE: [PATCH 02/11] pinctrl: starfive: jh7110-sys: Cleanup header includes
  2026-01-14 15:30 ` [PATCH 02/11] pinctrl: starfive: jh7110-sys: " Krzysztof Kozlowski
@ 2026-01-18  9:23   ` Hal Feng
  0 siblings, 0 replies; 21+ messages in thread
From: Hal Feng @ 2026-01-18  9:23 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Andrew Jeffery, Linus Walleij, Joel Stanley,
	Emil Renner Berthing, Chen Wang, Inochi Amaoto, Basavaraj Natikar,
	Shyam Sundar S K, Bartosz Golaszewski, Steen Hegelund,
	Daniel Machon, UNGLinuxDriver@microchip.com, Thierry Reding,
	Jonathan Hunter, Heiko Stuebner, Patrice Chotard
  Cc: linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, sophgo@lists.linux.dev,
	linux-tegra@vger.kernel.org, linux-rockchip@lists.infradead.org

> On 14.01.26 23:30, Krzysztof Kozlowski wrote:
> Remove unused includes: no clocks, mutexes and resets.
> 
> Signed-off-by: Krzysztof Kozlowski
> <krzysztof.kozlowski@oss.qualcomm.com>

Reviewed-by: Hal Feng <hal.feng@starfivetech.com>

Best regards,
Hal

> ---
>  drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c | 3 ---
>  1 file changed, 3 deletions(-)
> 
> diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c
> b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c
> index 9b67063a0b0b..44f84e4c29bf 100644
> --- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c
> +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-sys.c
> @@ -7,14 +7,11 @@
>   */
> 
>  #include <linux/bits.h>
> -#include <linux/clk.h>
>  #include <linux/gpio/driver.h>
>  #include <linux/io.h>
>  #include <linux/mod_devicetable.h>
>  #include <linux/module.h>
> -#include <linux/mutex.h>
>  #include <linux/platform_device.h>
> -#include <linux/reset.h>
>  #include <linux/spinlock.h>
> 
>  #include <linux/pinctrl/pinctrl.h>
> 
> --
> 2.51.0


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

end of thread, other threads:[~2026-01-18  9:23 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-14 15:30 [PATCH 00/11] pinctrl: Some code cleanup including guards Krzysztof Kozlowski
2026-01-14 15:30 ` [PATCH 01/11] pinctrl: aspeed: Cleanup header includes Krzysztof Kozlowski
2026-01-15  1:41   ` Andrew Jeffery
2026-01-14 15:30 ` [PATCH 02/11] pinctrl: starfive: jh7110-sys: " Krzysztof Kozlowski
2026-01-18  9:23   ` Hal Feng
2026-01-14 15:30 ` [PATCH 03/11] pinctrl: sophgo: " Krzysztof Kozlowski
2026-01-15  1:52   ` Inochi Amaoto
2026-01-14 15:30 ` [PATCH 04/11] pinctrl: amd: " Krzysztof Kozlowski
2026-01-14 15:30 ` [PATCH 05/11] pinctrl: aw9523: Simplify locking with guard() Krzysztof Kozlowski
2026-01-14 15:30 ` [PATCH 06/11] pinctrl: microchip-sgpio: " Krzysztof Kozlowski
2026-01-14 15:30 ` [PATCH 07/11] pinctrl: tb10x: " Krzysztof Kozlowski
2026-01-14 15:30 ` [PATCH 08/11] pinctrl: tegra-xusb: Return void in padctl enable/disable functions Krzysztof Kozlowski
2026-01-14 16:07   ` Jon Hunter
2026-01-16 12:50   ` Thierry Reding
2026-01-14 15:30 ` [PATCH 09/11] pinctrl: tegra-xusb: Simplify locking with guard() Krzysztof Kozlowski
2026-01-14 15:51   ` Jon Hunter
2026-01-14 16:01     ` Krzysztof Kozlowski
2026-01-14 15:30 ` [PATCH 10/11] pinctrl: rockchip: Simplify locking with scoped_guard() Krzysztof Kozlowski
2026-01-15 16:14   ` Heiko Stübner
2026-01-14 15:30 ` [PATCH 11/11] pinctrl: st: Annotate st_pinconf_dbg_show() as holding mutex Krzysztof Kozlowski
2026-01-14 17:19   ` Patrice CHOTARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox