* [PATCH 1/2] power: supply: max77705: Fix workqueue error handling in probe
2025-03-21 14:34 [PATCH 0/2] power: supply: max77705: Fix two static checker issues Dan Carpenter
@ 2025-03-21 14:34 ` Dan Carpenter
2025-03-22 16:48 ` Krzysztof Kozlowski
2025-03-21 14:34 ` [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health() Dan Carpenter
2025-04-28 22:18 ` (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues Sebastian Reichel
2 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2025-03-21 14:34 UTC (permalink / raw)
To: Dzmitry Sankouski
Cc: Sebastian Reichel, Krzysztof Kozlowski, Lee Jones, linux-pm,
linux-kernel
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 <dan.carpenter@linaro.org>
---
drivers/power/supply/max77705_charger.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply/max77705_charger.c
index eec5e9ef795e..329b430d0e50 100644
--- a/drivers/power/supply/max77705_charger.c
+++ b/drivers/power/supply/max77705_charger.c
@@ -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[] = {
--
2.47.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health()
2025-03-21 14:34 [PATCH 0/2] power: supply: max77705: Fix two static checker issues Dan Carpenter
2025-03-21 14:34 ` [PATCH 1/2] power: supply: max77705: Fix workqueue error handling in probe Dan Carpenter
@ 2025-03-21 14:34 ` Dan Carpenter
2025-03-26 17:14 ` Krzysztof Kozlowski
2025-04-28 22:18 ` (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues Sebastian Reichel
2 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2025-03-21 14:34 UTC (permalink / raw)
To: Dzmitry Sankouski
Cc: Sebastian Reichel, Lee Jones, Krzysztof Kozlowski, linux-pm,
linux-kernel
Return -EINVAL if the health is bad. Don't return success.
Fixes: a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/power/supply/max77705_charger.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply/max77705_charger.c
index 329b430d0e50..0e347353c41e 100644
--- a/drivers/power/supply/max77705_charger.c
+++ b/drivers/power/supply/max77705_charger.c
@@ -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);
}
--
2.47.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health()
2025-03-21 14:34 ` [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health() Dan Carpenter
@ 2025-03-26 17:14 ` Krzysztof Kozlowski
2025-03-26 17:27 ` Dan Carpenter
0 siblings, 1 reply; 8+ messages in thread
From: Krzysztof Kozlowski @ 2025-03-26 17:14 UTC (permalink / raw)
To: Dan Carpenter, Dzmitry Sankouski
Cc: Sebastian Reichel, Lee Jones, linux-pm, linux-kernel
On 21/03/2025 15:34, Dan Carpenter wrote:
> Return -EINVAL if the health is bad. Don't return success.
>
> Fixes: a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> drivers/power/supply/max77705_charger.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply/max77705_charger.c
> index 329b430d0e50..0e347353c41e 100644
> --- a/drivers/power/supply/max77705_charger.c
> +++ b/drivers/power/supply/max77705_charger.c
> @@ -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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health()
2025-03-26 17:14 ` Krzysztof Kozlowski
@ 2025-03-26 17:27 ` Dan Carpenter
0 siblings, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2025-03-26 17:27 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: Dzmitry Sankouski, Sebastian Reichel, Lee Jones, linux-pm,
linux-kernel
On Wed, Mar 26, 2025 at 06:14:13PM +0100, Krzysztof Kozlowski wrote:
> On 21/03/2025 15:34, Dan Carpenter wrote:
> > Return -EINVAL if the health is bad. Don't return success.
> >
> > Fixes: a6a494c8e3ce ("power: supply: max77705: Add charger driver for Maxim 77705")
> > Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> > ---
> > drivers/power/supply/max77705_charger.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/power/supply/max77705_charger.c b/drivers/power/supply/max77705_charger.c
> > index 329b430d0e50..0e347353c41e 100644
> > --- a/drivers/power/supply/max77705_charger.c
> > +++ b/drivers/power/supply/max77705_charger.c
> > @@ -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).
>
Yeah. What you're saying makes sense, especially in context. I misread
the code.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues
2025-03-21 14:34 [PATCH 0/2] power: supply: max77705: Fix two static checker issues Dan Carpenter
2025-03-21 14:34 ` [PATCH 1/2] power: supply: max77705: Fix workqueue error handling in probe Dan Carpenter
2025-03-21 14:34 ` [PATCH 2/2] power: supply: max77705: Fix error code in max77705_get_health() Dan Carpenter
@ 2025-04-28 22:18 ` Sebastian Reichel
2025-04-28 23:30 ` Sebastian Reichel
2 siblings, 1 reply; 8+ messages in thread
From: Sebastian Reichel @ 2025-04-28 22:18 UTC (permalink / raw)
To: Dzmitry Sankouski, Dan Carpenter
Cc: Krzysztof Kozlowski, Lee Jones, linux-kernel, linux-pm,
Sebastian Reichel
On Fri, 21 Mar 2025 17:34:00 +0300, Dan Carpenter wrote:
> 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,
--
Sebastian Reichel <sebastian.reichel@collabora.com>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues
2025-04-28 22:18 ` (subset) [PATCH 0/2] power: supply: max77705: Fix two static checker issues Sebastian Reichel
@ 2025-04-28 23:30 ` Sebastian Reichel
0 siblings, 0 replies; 8+ messages in thread
From: Sebastian Reichel @ 2025-04-28 23:30 UTC (permalink / raw)
To: Dzmitry Sankouski, Dan Carpenter
Cc: Krzysztof Kozlowski, Lee Jones, linux-kernel, linux-pm
[-- Attachment #1: Type: text/plain, Size: 939 bytes --]
Hi,
On Tue, Apr 29, 2025 at 12:18:43AM +0200, Sebastian Reichel wrote:
> On Fri, 21 Mar 2025 17:34:00 +0300, Dan Carpenter wrote:
> > 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
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread