Skip to contentSkip to conversation

regulator: tps65219: fix Wextra warning

PATCH In review Arnd Bergmann 3 participants 5 messages Dec 15, 2022 – Jan 20, 2023

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

PATCH 1/1 regulator: tps65219: fix Wextra warning

From: Arnd Bergmann <[email protected]>

gcc warns about an invalid pointer comparison when building with -Wextra enabled:

drivers/regulator/tps65219-regulator.c: In function 'tps65219_regulator_probe':
drivers/regulator/tps65219-regulator.c:370:26: error: ordered comparison of pointer with integer zero [-Werror=extra]
370 | if (rdev < 0) {
| ^

It appears that the intention here was to check for an error code, rather than the pointer, so adapt the code to propagate the error from the called function instead.

Fixes c12ac5fc3e0a ("regulator: drivers: Add TI TPS65219 PMIC regulators support")
---
 drivers/regulator/tps65219-regulator.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/regulator/tps65219-regulator.c +3 -3
index c484c943e467..fea3998334b1 100644
@@ -366,11 +366,11 @@ static int tps65219_regulator_probe(struct platform_device *pdev)
 		irq_data[i].dev = tps->dev;
 		irq_data[i].type = irq_type;
 
-		tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
-		if (rdev < 0) {
+		error = tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
+		if (error) {
 			dev_err(tps->dev, "Failed to get rdev for %s\n",
 				irq_type->regulator_name);
-			return -EINVAL;
+			return error;
 		}
 		irq_data[i].rdev = rdev;
 
Signature · 1 line
2.35.1
maintainer
#1 lore raw

drivers/regulator/tps65219-regulator.c static int tps65219_regulator_probe(struct platform_device *pdev) · line 373

Quoted 8 lines · Arnd Bergmann
drivers/regulator/tps65219-regulator.c +3 -3
-		tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
-		if (rdev < 0) {
+		error = tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
+		if (error) {
 			dev_err(tps->dev, "Failed to get rdev for %s\n",
 				irq_type->regulator_name);
-			return -EINVAL;
+			return error;

This will shut up the warning but is leaving the use of the uninitialised rdev (which I'm kind of disappointed the static checkers didn't pick up on). rdev needs to be passed by reference into the function, or set from the return value.

#2 lore raw
Quoted 15 lines · Mark Brown

drivers/regulator/tps65219-regulator.c static int tps65219_regulator_probe(struct platform_device *pdev) · line 373

Quoted 8 lines · Arnd Bergmann
drivers/regulator/tps65219-regulator.c +3 -3
-		tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
-		if (rdev < 0) {
+		error = tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
+		if (error) {
 			dev_err(tps->dev, "Failed to get rdev for %s\n",
 				irq_type->regulator_name);
-			return -EINVAL;
+			return error;

This will shut up the warning but is leaving the use of the uninitialised rdev (which I'm kind of disappointed the static checkers didn't pick up on). rdev needs to be passed by reference into the function, or set from the return value.

Right, I didn't look far enough to see what the function is actually trying to do here, and that it completely fails to do that.

I see that the bug was introduced between the first [1] and second []2] version of the driver, but don't see why. I'll leave it up to Jerome to address the problem, he's still in the middle of posting the rest of the series that has not yet been merged, so it makes sense for him to test it all together.

Arnd

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

#3 lore raw
Quoted 28 lines · Arnd Bergmann
Quoted 15 lines · Mark Brown

drivers/regulator/tps65219-regulator.c static int tps65219_regulator_probe(struct platform_device *pdev) · line 373

Quoted 8 lines · Arnd Bergmann
drivers/regulator/tps65219-regulator.c +3 -3
-		tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
-		if (rdev < 0) {
+		error = tps65219_get_rdev_by_name(irq_type->regulator_name, rdevtbl, rdev);
+		if (error) {
 			dev_err(tps->dev, "Failed to get rdev for %s\n",
 				irq_type->regulator_name);
-			return -EINVAL;
+			return error;

This will shut up the warning but is leaving the use of the uninitialised rdev (which I'm kind of disappointed the static checkers didn't pick up on). rdev needs to be passed by reference into the function, or set from the return value.

Right, I didn't look far enough to see what the function is actually trying to do here, and that it completely fails to do that.

I see that the bug was introduced between the first [1] and second []2] version of the driver, but don't see why. I'll leave it up to Jerome to address the problem, he's still in the middle of posting the rest of the series that has not yet been merged, so it makes sense for him to test it all together.

Quoted 4 lines

Arnd

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/

It looks like you merged another workaround from Randy Dunlap now as commit 2bbba115c3c9 ("regulator: tps65219: use IS_ERR() to detect an error pointer"), but I think that one is just as wrong as the one I submitted:
the 'rdev' variable still remains uninitialized, and checking its value after it has already been used is not helpful.

Arnd

maintainer
#4 lore raw
Quoted 5 lines · Arnd Bergmann

It looks like you merged another workaround from Randy Dunlap now as commit 2bbba115c3c9 ("regulator: tps65219: use IS_ERR() to detect an error pointer"), but I think that one is just as wrong as the one I submitted:
the 'rdev' variable still remains uninitialized, and checking its value after it has already been used is not helpful.

Right, that's just changing the way the result is parsed, it's nothing to do with making sure things are initialised. It's just a coccinelle style thing.