Skip to contentSkip to conversation

pinctrl: Address some issues reported by Smatch

PATCH Applied Andrew Goodbody 3 participants 8 messages Aug 7, 2025 – Aug 18, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover pinctrl: Address some issues reported by Smatch

Smatch reported some issues with pinctrl drivers. This includes unreachable code, duplicated code and uninitialised variables.

---
Andrew Goodbody (4):
pinctrl: single: Remove unreachable code
pinctrl: stmfx: Remove duplicated code
pinctrl: zynqmp: Ensure ret is initialised
pinctrl: zynqmp: Avoid using uninitialised variable

 drivers/pinctrl/pinctrl-single.c | 2 --
 drivers/pinctrl/pinctrl-stmfx.c  | 2 +-
 drivers/pinctrl/pinctrl-zynqmp.c | 6 +++---
 3 files changed, 4 insertions(+), 6 deletions(-)

---
base-commit: 3526f990b77fca1c933f1d8b24eb9385010a05bf
change-id: 20250807-pinctrl_misc-8b7d59c1684d

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#1 lore raw

PATCH 1/4 pinctrl: single: Remove unreachable code

In single_read there is a switch block with a default label. All cases in the switch block, including the default, return directly. So any code following the switch block is unreachable. Remove the unreachable code.

This issue was found by Smatch.

---
 drivers/pinctrl/pinctrl-single.c | 2 --
 1 file changed, 2 deletions(-)
drivers/pinctrl/pinctrl-single.c +0 -2
index a3802d22d4f..c96b293aadf 100644
@@ -109,8 +109,6 @@ static unsigned int single_read(struct udevice *dev, void *reg)
 	default: /* 32 bits */
 		return readl(reg);
 	}
-
-	return readb(reg);
 }
 
 static void single_write(struct udevice *dev, unsigned int val, void *reg)
Signature · 1 line
2.39.5
#2 lore raw

PATCH 2/4 pinctrl: stmfx: Remove duplicated code

In reply to Andrew Goodbody

In stmfx_read_reg there is duplicated code to detect ret < 0 and return ret if so. Remove one version of it.

This issue was found by Smatch.

---
 drivers/pinctrl/pinctrl-stmfx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-stmfx.c +1 -1
index 61f335c4eb1..0d5778faef9 100644
@@ -87,7 +87,7 @@ static int stmfx_read_reg(struct udevice *dev, u8 reg_base, uint offset)
 	if (ret < 0)
 		return ret;
 
-	return ret < 0 ? ret : !!(ret & mask);
+	return !!(ret & mask);
 }
 
 static int stmfx_write_reg(struct udevice *dev, u8 reg_base, uint offset,
Signature · 1 line
2.39.5
#3 lore raw

PATCH 3/4 pinctrl: zynqmp: Ensure ret is initialised

In reply to Andrew Goodbody

In zynqmp_pinctrl_prepare_func_groups if called with func->ngroups == 0 then ret will not be assigned to before its value is returned on exit. Initialise ret to ensure it is always valid.

This issue was found by Smatch.

---
 drivers/pinctrl/pinctrl-zynqmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-zynqmp.c +1 -1
index 6fa203a3b86..27dadbff8ca 100644
@@ -204,7 +204,7 @@ static int zynqmp_pinctrl_prepare_func_groups(u32 fid,
 	const char **fgroups;
 	char name[MAX_GROUP_NAME_LEN];
 	u16 resp[NUM_GROUPS_PER_RESP] = {0};
-	int ret, index, i;
+	int ret = 0, index, i;
 
 	fgroups = kcalloc(func->ngroups, sizeof(*fgroups), GFP_KERNEL);
 	if (!fgroups)
Signature · 1 line
2.39.5
maintainer Applied
#4 lore raw

Re: [PATCH 3/4] pinctrl: zynqmp: Ensure ret is initialised

Quoted 17 lines · Andrew Goodbody

In zynqmp_pinctrl_prepare_func_groups if called with func->ngroups == 0 then ret will not be assigned to before its value is returned on exit. Initialise ret to ensure it is always valid.

This issue was found by Smatch.

---
  drivers/pinctrl/pinctrl-zynqmp.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-zynqmp.c +0 -0
index 6fa203a3b86..27dadbff8ca 100644

drivers/pinctrl/pinctrl-zynqmp.c static int zynqmp_pinctrl_prepare_func_groups(u32 fid, · line 210

Quoted 8 lines
drivers/pinctrl/pinctrl-zynqmp.c +1 -1
@@ -204,7 +204,7 @@ static int zynqmp_pinctrl_prepare_func_groups(u32 fid,
  	const char **fgroups;
  	char name[MAX_GROUP_NAME_LEN];
  	u16 resp[NUM_GROUPS_PER_RESP] = {0};
-	int ret, index, i;
+	int ret = 0, index, i;
 
  	fgroups = kcalloc(func->ngroups, sizeof(*fgroups), GFP_KERNEL);
  	if (!fgroups)

Applied.
M

#5 lore raw

PATCH 4/4 pinctrl: zynqmp: Avoid using uninitialised variable

In reply to Andrew Goodbody

In zynqmp_pinconf_set if param is PIN_CFG_IOSTANDARD or PIN_CONFIG_POWER_SOURCE and zynqmp_pm_pinctrl_get_config returns an error then value will not be assigned to when its value is tested to be not equal to arg. Add code to only test value not equal to arg if ret is false.

This issue was found by Smatch.

---
 drivers/pinctrl/pinctrl-zynqmp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-zynqmp.c +2 -2
index 27dadbff8ca..665b76a7d4d 100644
@@ -460,14 +460,14 @@ static int zynqmp_pinconf_set(struct udevice *dev, unsigned int pin,
 	case PIN_CFG_IOSTANDARD:
 		param = PM_PINCTRL_CONFIG_VOLTAGE_STATUS;
 		ret = zynqmp_pm_pinctrl_get_config(pin, param, &value);
-		if (arg != value)
+		if (!ret && arg != value)
 			dev_warn(dev, "Invalid IO Standard requested for pin %d\n",
 				 pin);
 		break;
 	case PIN_CONFIG_POWER_SOURCE:
 		param = PM_PINCTRL_CONFIG_VOLTAGE_STATUS;
 		ret = zynqmp_pm_pinctrl_get_config(pin, param, &value);
-		if (arg != value)
+		if (!ret && arg != value)
 			dev_warn(dev, "Invalid IO Standard requested for pin %d\n",
 				 pin);
 		break;
Signature · 1 line
2.39.5
maintainer Applied
#6 lore raw

Re: [PATCH 4/4] pinctrl: zynqmp: Avoid using uninitialised variable

Quoted 25 lines · Andrew Goodbody

In zynqmp_pinconf_set if param is PIN_CFG_IOSTANDARD or PIN_CONFIG_POWER_SOURCE and zynqmp_pm_pinctrl_get_config returns an error then value will not be assigned to when its value is tested to be not equal to arg. Add code to only test value not equal to arg if ret is false.

This issue was found by Smatch.

---
  drivers/pinctrl/pinctrl-zynqmp.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/pinctrl-zynqmp.c +1 -1
index 27dadbff8ca..665b76a7d4d 100644
@@ -460,14 +460,14 @@ static int zynqmp_pinconf_set(struct udevice *dev, unsigned int pin,
  	case PIN_CFG_IOSTANDARD:
  		param = PM_PINCTRL_CONFIG_VOLTAGE_STATUS;
  		ret = zynqmp_pm_pinctrl_get_config(pin, param, &value);
-		if (arg != value)
+		if (!ret && arg != value)
  			dev_warn(dev, "Invalid IO Standard requested for pin %d\n",

drivers/pinctrl/pinctrl-zynqmp.c static int zynqmp_pinconf_set(struct udevice *dev, unsigned int pin, · line 473

Quoted 10 lines
drivers/pinctrl/pinctrl-zynqmp.c +1 -1
  				 pin);
  		break;
  	case PIN_CONFIG_POWER_SOURCE:
  		param = PM_PINCTRL_CONFIG_VOLTAGE_STATUS;
  		ret = zynqmp_pm_pinctrl_get_config(pin, param, &value);
-		if (arg != value)
+		if (!ret && arg != value)
  			dev_warn(dev, "Invalid IO Standard requested for pin %d\n",
  				 pin);
  		break;

Applied.
M

#7 lore raw

Re: (subset) [PATCH 0/4] pinctrl: Address some issues reported by Smatch

In reply to Andrew Goodbody
Quoted 4 lines · Andrew Goodbody

Smatch reported some issues with pinctrl drivers. This includes unreachable code, duplicated code and uninitialised variables.

Applied to u-boot/next, thanks!

[1/4] pinctrl: single: Remove unreachable code

      commit: 64204ab107b51c60e490292ed1eda40a9a64d7d9
[2/4] pinctrl: stmfx: Remove duplicated code
      commit: 4a2f360bd280b2b5af1c5daffbc189590c83c995
Signature · 1 line
Tom