power: supply: max77705: Fix two static checker issues
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
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.
--- drivers/power/supply/max77705_charger.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/power/supply/max77705_charger.c +14 -6
@@ -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
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")Signed-off-by Dan Carpenter <[email protected]>---
Best regards,
Krzysztof
PATCH 2/2 power: supply: max77705: Fix error code in max77705_get_health()
In reply to Dan CarpenterReturn -EINVAL if the health is bad. Don't return success.
--- drivers/power/supply/max77705_charger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 ; }return max77705_get_battery_health (charger, val); }
Signature · 1 line
2.47.2
Re: [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health()
Quoted 13 lines · Dan Carpenter
Return
-EINVALif the health is bad. Don't return success.Fixes a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")Signed-off-by Dan Carpenter <[email protected]>--- drivers/power/supply/max77705_charger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/supply/max77705_charger.c +0
-0
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
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
-EINVALif the health is bad. Don't return success.Fixes a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")Signed-off-by Dan Carpenter <[email protected]>--- drivers/power/supply/max77705_charger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/power/supply/max77705_charger.c +0
-0drivers/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
-EINVALin such case.
Quoted 5 lines
Second, if
get_vbus_statesucceeded, 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
Sebastian Reichel
AppliedRe: (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues
In reply to Dan CarpenterQuoted 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 inmax77705_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]>
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 inmax77705_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