Skip to contentSkip to conversation

power: supply: max77705: Fix two static checker issues

PATCH Applied Dan Carpenter 3 participants 8 messages Mar 21, 2025 – Apr 28, 2025 Power supply

lore
Share & tools
lore
#0 lore raw

cover power: supply: max77705: Fix two static checker issues

Fix some error handling and an error code bug.

Dan Carpenter (2):
power: supply: max77705: Fix workqueue error handling in probe
power: supply: max77705: Fix error code in max77705_get_health()

 drivers/power/supply/max77705_charger.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/2 power: supply: max77705: Fix workqueue error handling in probe

The create_singlethread_workqueue() doesn't return error pointers, it returns NULL. Also cleanup the workqueue on the error paths.

Fixes a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")
---
 drivers/power/supply/max77705_charger.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/power/supply/max77705_charger.c +14 -6
index eec5e9ef795e..329b430d0e50 100644
@@ -545,20 +545,28 @@ static int max77705_charger_probe(struct i2c_client *i2c)
 		return dev_err_probe(dev, ret, "failed to add irq chip\n");
 
 	chg->wqueue = create_singlethread_workqueue(dev_name(dev));
-	if (IS_ERR(chg->wqueue))
-		return dev_err_probe(dev, PTR_ERR(chg->wqueue), "failed to create workqueue\n");
+	if (!chg->wqueue)
+		return dev_err_probe(dev, -ENOMEM, "failed to create workqueue\n");
 
 	ret = devm_work_autocancel(dev, &chg->chgin_work, max77705_chgin_isr_work);
-	if (ret)
-		return dev_err_probe(dev, ret, "failed to initialize interrupt work\n");
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to initialize interrupt work\n");
+		goto destroy_wq;
+	}
 
 	max77705_charger_initialize(chg);
 
 	ret = max77705_charger_enable(chg);
-	if (ret)
-		return dev_err_probe(dev, ret, "failed to enable charge\n");
+	if (ret) {
+		dev_err_probe(dev, ret, "failed to enable charge\n");
+		goto destroy_wq;
+	}
 
 	return devm_add_action_or_reset(dev, max77705_charger_disable, chg);
+
+destroy_wq:
+	destroy_workqueue(chg->wqueue);
+	return ret;
 }
 
 static const struct of_device_id max77705_charger_of_match[] = {
Signature · 1 line
2.47.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] power: supply: max77705: Fix workqueue error handling in probe

Quoted 6 lines · Dan Carpenter

The create_singlethread_workqueue() doesn't return error pointers, it returns NULL. Also cleanup the workqueue on the error paths.

Fixes a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")

---

Best regards,
Krzysztof

#3 lore raw

PATCH 2/2 power: supply: max77705: Fix error code in max77705_get_health()

In reply to Dan Carpenter

Return -EINVAL if the health is bad. Don't return success.

Fixes a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")
---
 drivers/power/supply/max77705_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/max77705_charger.c +1 -1
index 329b430d0e50..0e347353c41e 100644
@@ -285,7 +285,7 @@ static int max77705_get_health(struct max77705_charger_data *charger, int *val)
 	if (is_online) {
 		ret = max77705_get_vbus_state(regmap, val);
 		if (ret || (*val != POWER_SUPPLY_HEALTH_GOOD))
-			return ret;
+			return -EINVAL;
 	}
 	return max77705_get_battery_health(charger, val);
 }
Signature · 1 line
2.47.2
#4 lore raw

Re: [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health()

Quoted 13 lines · Dan Carpenter

Return -EINVAL if the health is bad. Don't return success.

Fixes a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")
---
 drivers/power/supply/max77705_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/max77705_charger.c +0 -0
index 329b430d0e50..0e347353c41e 100644

drivers/power/supply/max77705_charger.c static int max77705_get_health(struct max77705_charger_data *charger, int *val) · line 288

Quoted 5 lines
drivers/power/supply/max77705_charger.c +1 -1
@@ -285,7 +285,7 @@ static int max77705_get_health(struct max77705_charger_data *charger, int *val)
 	if (is_online) {
 		ret = max77705_get_vbus_state(regmap, val);
 		if (ret || (*val != POWER_SUPPLY_HEALTH_GOOD))
-			return ret;
+			return -EINVAL;

I don't think this is right. First, your commit msg should mention why returning -EINVAL in such case.

Second, if get_vbus_state succeeded, but 'val' is not good (e.g. overvoltage), the callback is supposed to return 0 as success of retrieving the data, no? So the user-space can read 'val' and figure out whatever it needs to figure out (overvoltage).

The EINVAL is when the data could not be read, thus user-space should ignore 'val'.

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health()

Quoted 24 lines · Krzysztof Kozlowski
Quoted 13 lines · Dan Carpenter

Return -EINVAL if the health is bad. Don't return success.

Fixes a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")
---
 drivers/power/supply/max77705_charger.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/supply/max77705_charger.c +0 -0
index 329b430d0e50..0e347353c41e 100644

drivers/power/supply/max77705_charger.c static int max77705_get_health(struct max77705_charger_data *charger, int *val) · line 288

Quoted 5 lines
drivers/power/supply/max77705_charger.c +1 -1
@@ -285,7 +285,7 @@ static int max77705_get_health(struct max77705_charger_data *charger, int *val)
 	if (is_online) {
 		ret = max77705_get_vbus_state(regmap, val);
 		if (ret || (*val != POWER_SUPPLY_HEALTH_GOOD))
-			return ret;
+			return -EINVAL;

I don't think this is right. First, your commit msg should mention why returning -EINVAL in such case.

Quoted 5 lines

Second, if get_vbus_state succeeded, but 'val' is not good (e.g. overvoltage), the callback is supposed to return 0 as success of retrieving the data, no? So the user-space can read 'val' and figure out whatever it needs to figure out (overvoltage).

Yeah. What you're saying makes sense, especially in context. I misread the code.

regards,
dan carpenter

#6 lore raw

Re: (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues

In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

Fix some error handling and an error code bug.

Dan Carpenter (2):
power: supply: max77705: Fix workqueue error handling in probe
power: supply: max77705: Fix error code in max77705_get_health()

drivers/power/supply/max77705_charger.c | 22 +++++++++++++++-------

 1 file changed, 15 insertions(+), 7 deletions(-)

[...]

Applied, thanks!

[1/2] power: supply: max77705: Fix workqueue error handling in probe

      commit: 11741b8e382d34b13277497ab91123d8b0b5c2db

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>
#7 lore raw

Re: (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues

Hi,

Quoted 10 lines · Sebastian Reichel
Quoted 9 lines · Dan Carpenter

Fix some error handling and an error code bug.

Dan Carpenter (2):
power: supply: max77705: Fix workqueue error handling in probe
power: supply: max77705: Fix error code in max77705_get_health()

drivers/power/supply/max77705_charger.c | 22 +++++++++++++++-------

 1 file changed, 15 insertions(+), 7 deletions(-)
Quoted 6 lines
Quoted 1 line

[...]

Applied, thanks!

[1/2] power: supply: max77705: Fix workqueue error handling in probe

      commit: 11741b8e382d34b13277497ab91123d8b0b5c2db

I've queued it, since it improves the driver. But the workqueue also needs to be released when the module is removed. So I think the destroy_workqueue() should happen via devm_add_action_or_reset() instead of what this patch is doing.

Greetings,

-- Sebastian