All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pan Chuang" <panchuang@vivo.com>
Cc: Frank.Li@kernel.org, imx@lists.linux.dev
Subject: Re: [PATCH 28/43] power: supply: pf1550-charger: Remove redundant dev_err()/dev_err_probe()
Date: Thu, 09 Jul 2026 03:57:26 +0000	[thread overview]
Message-ID: <20260709035727.701DF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709033428.362970-29-panchuang@vivo.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Pre-existing issues:
- [High] Inverted logic when turning on the charger based on battery presence in `pf1550_reg_init()`.
- [High] Use-after-free vulnerability during driver unbind or probe failure due to incorrect `devm` registration order.
- [High] Guaranteed probe failure for device trees omitting the optional `constant-charge-voltage-max-microvolt` property due to unhandled `-EINVAL`.
- [Medium] Resource leak of `struct power_supply_battery_info` due to uncalled `power_supply_put_battery_info()`.
--

--- Patch [28]: [PATCH 28/43] power: supply: pf1550-charger: Remove redundant dev_err()/dev_err_probe() ---
commit 7f7745c9eb293f3e6b24f5df79b35be592a07130
Author: Pan Chuang <panchuang@vivo.com>

power: supply: pf1550-charger: Remove redundant dev_err()/dev_err_probe()
    
The devm_request_threaded_irq() and devm_request_irq() now automatically
log detailed error messages on failure. This eliminates the need for
driver-specific dev_err() and dev_err_probe() calls.

> diff --git a/drivers/power/supply/pf1550-charger.c b/drivers/power/supply/pf1550-charger.c
> index 41036f4cb64a0..94fe81bab5a21 100644
> --- a/drivers/power/supply/pf1550-charger.c
> +++ b/drivers/power/supply/pf1550-charger.c
> @@ -612,8 +612,7 @@ static int pf1550_charger_probe(struct platform_device *pdev)
>  						IRQF_NO_SUSPEND,
>  						"pf1550-charger", chg);
>  		if (ret)
> -			return dev_err_probe(&pdev->dev, ret,
> -					     "failed irq request\n");
> +			return ret;
>  	}
>  
>  	pf1550_dt_parse_dev_info(chg);

[Severity: High]
This is a pre-existing issue, but does this devm registration order leave 
a use-after-free window during device unbind?

In drivers/power/supply/pf1550-charger.c:pf1550_charger_probe(), the delayed
works are registered before the power supplies:

	ret = devm_delayed_work_autocancel(chg->dev, &chg->vbus_sense_work,
					   pf1550_chg_vbus_work);
	...
	chg->charger = devm_power_supply_register(&pdev->dev,
						  &pf1550_charger_desc,
						  &psy_cfg);

Since devres cleans up in reverse order, the power supplies will be freed
first. If pf1550_chg_vbus_work executes before the work is canceled, it
will call power_supply_changed(chg->battery) on a freed power supply
pointer.


[Severity: Medium]
This is a pre-existing issue, but does this code leak the battery info
structure?

Looking at pf1550_dt_parse_dev_info(), it calls power_supply_get_battery_info():

	if (power_supply_get_battery_info(chg->charger, &info))
		chg->constant_volt = PF1550_DEFAULT_CONSTANT_VOLT;
	else
		chg->constant_volt = info->constant_charge_voltage_max_uv;

The same call also occurs in pf1550_reg_init(). However, there are no
matching calls to power_supply_put_battery_info() in the driver to free the
memory allocated by these lookups.


[Severity: High]
This is a pre-existing issue, but does this code handle missing devicetree
properties correctly?

In pf1550_dt_parse_dev_info():

	if (power_supply_get_battery_info(chg->charger, &info))
		chg->constant_volt = PF1550_DEFAULT_CONSTANT_VOLT;
	else
		chg->constant_volt = info->constant_charge_voltage_max_uv;

If the devicetree lacks the optional constant-charge-voltage-max-microvolt
property, info->constant_charge_voltage_max_uv is set to -EINVAL. This
negative error code is then cast to the u32 chg->constant_volt, which
becomes 4294967274 and guarantees a failure in later upper-bound checks.


[Severity: High]
This is a pre-existing issue, but is the logic for enabling the charger
inverted here?

Looking at pf1550_reg_init():

	if (power_supply_get_battery_info(chg->charger, &info)) {
		ret = regmap_write(chg->pf1550->regmap,
				   PF1550_CHARG_REG_CHG_OPER,
				   PF1550_CHG_BAT_ON);

Since power_supply_get_battery_info() returns 0 on success and an error code
like -ENODEV on failure, this condition evaluates to true only when the
battery info lookup fails. This appears to turn on the charger exactly when
the battery is missing or misconfigured.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709033428.362970-1-panchuang@vivo.com?part=28

  reply	other threads:[~2026-07-09  3:57 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09  3:33 [PATCH 00/43] power: Remove redundant error messages on IRQ request failure Pan Chuang
2026-07-09  3:33 ` [PATCH 01/43] power: reset: pwr-mlxbf: Remove redundant dev_err()/dev_err_probe() Pan Chuang
2026-07-09  3:33 ` [PATCH 02/43] power: supply: 88pm860x_battery: " Pan Chuang
2026-07-09  3:33 ` [PATCH 03/43] power: supply: 88pm860x_charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 04/43] power: supply: ab8500_btemp: " Pan Chuang
2026-07-10 19:38   ` Linus Walleij
2026-07-09  3:33 ` [PATCH 05/43] power: supply: ab8500_charger: " Pan Chuang
2026-07-10 19:39   ` Linus Walleij
2026-07-09  3:33 ` [PATCH 06/43] power: supply: ab8500_fg: " Pan Chuang
2026-07-10 19:39   ` Linus Walleij
2026-07-09  3:33 ` [PATCH 07/43] power: supply: act8945a_charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 08/43] power: supply: axp20x_ac_power: " Pan Chuang
2026-07-09  3:33 ` [PATCH 09/43] power: supply: axp20x_usb_power: " Pan Chuang
2026-07-09  3:33 ` [PATCH 10/43] power: supply: axp288_charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 11/43] power: supply: axp288_fuel_gauge: " Pan Chuang
2026-07-09  3:33 ` [PATCH 12/43] power: supply: bq24190_charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 13/43] power: supply: bq24257_charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 14/43] power: supply: bq24735-charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 15/43] power: supply: bq256xx_charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 16/43] power: supply: bq257xx_charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 17/43] power: supply: cpcap-battery: " Pan Chuang
2026-07-09  3:33 ` [PATCH 18/43] power: supply: cpcap-charger: " Pan Chuang
2026-07-09  3:33 ` [PATCH 19/43] power: supply: da9150-fg: " Pan Chuang
2026-07-09  3:33 ` [PATCH 20/43] power: supply: generic-adc-battery: " Pan Chuang
2026-07-09  3:34 ` [PATCH 21/43] power: supply: max14656_charger_detector: " Pan Chuang
2026-07-09  3:34 ` [PATCH 22/43] power: supply: max77759_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 23/43] power: supply: max8903_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 24/43] power: supply: max8971_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 25/43] power: supply: mp2629_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 26/43] power: supply: mt6360_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 27/43] power: supply: mt6370-charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 28/43] power: supply: pf1550-charger: " Pan Chuang
2026-07-09  3:57   ` sashiko-bot [this message]
2026-07-14  0:24   ` Samuel Kayode
2026-07-09  3:34 ` [PATCH 29/43] power: supply: qcom_smbb: " Pan Chuang
2026-07-09  3:34 ` [PATCH 30/43] power: supply: qcom_smbx: " Pan Chuang
2026-07-09  3:34 ` [PATCH 31/43] power: supply: rk817_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 32/43] power: supply: rn5t618_power: " Pan Chuang
2026-07-09  3:34 ` [PATCH 33/43] power: supply: rt9455_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 34/43] power: supply: rt9467-charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 35/43] power: supply: rt9471: " Pan Chuang
2026-07-09  3:34 ` [PATCH 36/43] power: supply: sbs-charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 37/43] power: supply: sc27xx_fuel_gauge: " Pan Chuang
2026-07-09  3:34 ` [PATCH 38/43] power: supply: surface-rt-ec: " Pan Chuang
2026-07-09  3:34 ` [PATCH 39/43] power: supply: tps65090-charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 40/43] power: supply: tps65217_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 41/43] power: supply: twl4030_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 42/43] power: supply: twl6030_charger: " Pan Chuang
2026-07-09  3:34 ` [PATCH 43/43] power: supply: ucs1002_power: " Pan Chuang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260709035727.701DF1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=panchuang@vivo.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.