Skip to contentSkip to conversation

power: regulator: Fix incorrect use of binary and

PATCH Applied Andrew Goodbody 2 participants 3 messages Sep 1, 2025 – Sep 24, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 power: regulator: Fix incorrect use of binary and

In regulator_list_autoset there is a test for ret being non-zero and error being zero but it uses the binary '&' instead of the logical '&&' which could well lead to unexpected results. Correct this to use the logical '&&' instead.

This issue found by Smatch.

---
Changes in v2:
- Ignore -EALREADY errors from autoset
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/power/regulator/regulator-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/regulator/regulator-uclass.c +1 -1
index 09567eb9dbb..7aa47c918ad 100644
@@ -389,7 +389,7 @@ int regulator_list_autoset(const char *list_platname[],
 		ret = regulator_autoset_by_name(list_platname[i], &dev);
 		if (ret != -EMEDIUMTYPE && verbose)
 			regulator_show(dev, ret);
-		if (ret & !error)
+		if (ret && ret != -EALREADY && !error)
 			error = ret;
 
 		if (list_devp)

---
base-commit: 7027b445cc0bfb86204ecb1f1fe596f5895048d9
change-id: 20250703-regulator_uclass_fix-d9457eff7fe9

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Andrew Goodbody

In regulator_list_autoset there is a test for ret being non-zero and error being zero but it uses the binary '&' instead of the logical '&&' which could well lead to unexpected results. Correct this to use the logical '&&' instead.

This issue found by Smatch.

#2 lore raw
In reply to Andrew Goodbody

From: Peng Fan <[email protected]>

Quoted 8 lines · Andrew Goodbody

In regulator_list_autoset there is a test for ret being non-zero and error being zero but it uses the binary '&' instead of the logical '&&' which could well lead to unexpected results. Correct this to use the logical '&&' instead.

This issue found by Smatch.

[...]

Applied, thanks!

[1/1] power: regulator: Fix incorrect use of binary and

      commit: 6c98e6014b3a36933860d02cb757565ec2fc80a4

Best regards,

Signature · 1 line
Peng Fan <[email protected]>