* [PATCH] power: supply: cros_charge-control: Fix signedness bug in charge_behaviour_store()
@ 2024-07-04 15:20 Dan Carpenter
2024-07-04 18:16 ` Thomas Weißschuh
2024-07-05 1:55 ` Tzung-Bi Shih
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-07-04 15:20 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Thomas Weißschuh, Benson Leung, Guenter Roeck,
Sebastian Reichel, Tzung-Bi Shih, chrome-platform, linux-pm,
linux-kernel, kernel-janitors
The C standard is vague about the signedness of enums, but in this case
here, they are treated as unsigned so the error handling does not work.
Use an int type to fix this.
Fixes: c6ed48ef5259 ("power: supply: add ChromeOS EC based charge control driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
drivers/power/supply/cros_charge-control.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c
index 73d7f2dc0fa3..3183a13eefd0 100644
--- a/drivers/power/supply/cros_charge-control.c
+++ b/drivers/power/supply/cros_charge-control.c
@@ -204,14 +204,13 @@ static ssize_t charge_behaviour_store(struct device *dev, struct device_attribut
{
struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr,
CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR);
- enum power_supply_charge_behaviour behaviour;
int ret;
- behaviour = power_supply_charge_behaviour_parse(EC_CHARGE_CONTROL_BEHAVIOURS, buf);
- if (behaviour < 0)
- return behaviour;
+ ret = power_supply_charge_behaviour_parse(EC_CHARGE_CONTROL_BEHAVIOURS, buf);
+ if (ret < 0)
+ return ret;
- priv->current_behaviour = behaviour;
+ priv->current_behaviour = ret;
ret = cros_chctl_configure_ec(priv);
if (ret < 0)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] power: supply: cros_charge-control: Fix signedness bug in charge_behaviour_store()
2024-07-04 15:20 [PATCH] power: supply: cros_charge-control: Fix signedness bug in charge_behaviour_store() Dan Carpenter
@ 2024-07-04 18:16 ` Thomas Weißschuh
2024-07-05 1:55 ` Tzung-Bi Shih
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2024-07-04 18:16 UTC (permalink / raw)
To: Dan Carpenter
Cc: Benson Leung, Guenter Roeck, Sebastian Reichel, Tzung-Bi Shih,
chrome-platform, linux-pm, linux-kernel, kernel-janitors
Hi Dan,
Thanks!
On 2024-07-04 10:20:03+0000, Dan Carpenter wrote:
> The C standard is vague about the signedness of enums, but in this case
> here, they are treated as unsigned so the error handling does not work.
> Use an int type to fix this.
>
> Fixes: c6ed48ef5259 ("power: supply: add ChromeOS EC based charge control driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Acked-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> drivers/power/supply/cros_charge-control.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/power/supply/cros_charge-control.c b/drivers/power/supply/cros_charge-control.c
> index 73d7f2dc0fa3..3183a13eefd0 100644
> --- a/drivers/power/supply/cros_charge-control.c
> +++ b/drivers/power/supply/cros_charge-control.c
> @@ -204,14 +204,13 @@ static ssize_t charge_behaviour_store(struct device *dev, struct device_attribut
> {
> struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(&attr->attr,
> CROS_CHCTL_ATTR_CHARGE_BEHAVIOUR);
> - enum power_supply_charge_behaviour behaviour;
> int ret;
>
> - behaviour = power_supply_charge_behaviour_parse(EC_CHARGE_CONTROL_BEHAVIOURS, buf);
> - if (behaviour < 0)
> - return behaviour;
> + ret = power_supply_charge_behaviour_parse(EC_CHARGE_CONTROL_BEHAVIOURS, buf);
> + if (ret < 0)
> + return ret;
>
> - priv->current_behaviour = behaviour;
> + priv->current_behaviour = ret;
>
> ret = cros_chctl_configure_ec(priv);
> if (ret < 0)
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] power: supply: cros_charge-control: Fix signedness bug in charge_behaviour_store()
2024-07-04 15:20 [PATCH] power: supply: cros_charge-control: Fix signedness bug in charge_behaviour_store() Dan Carpenter
2024-07-04 18:16 ` Thomas Weißschuh
@ 2024-07-05 1:55 ` Tzung-Bi Shih
1 sibling, 0 replies; 3+ messages in thread
From: Tzung-Bi Shih @ 2024-07-05 1:55 UTC (permalink / raw)
To: Dan Carpenter
Cc: Thomas Weißschuh, Thomas Weißschuh, Benson Leung,
Guenter Roeck, Sebastian Reichel, chrome-platform, linux-pm,
linux-kernel, kernel-janitors
On Thu, Jul 04, 2024 at 10:20:03AM -0500, Dan Carpenter wrote:
> The C standard is vague about the signedness of enums, but in this case
> here, they are treated as unsigned so the error handling does not work.
> Use an int type to fix this.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-next
Thanks!
[1/1] power: supply: cros_charge-control: Fix signedness bug in charge_behaviour_store()
commit: 4baf1cc54433ff7c6e5178517bc8768001416681
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-07-05 1:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-04 15:20 [PATCH] power: supply: cros_charge-control: Fix signedness bug in charge_behaviour_store() Dan Carpenter
2024-07-04 18:16 ` Thomas Weißschuh
2024-07-05 1:55 ` Tzung-Bi Shih
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).