From: sashiko-bot@kernel.org
To: "Molnár Máté" <matemolnar88@gmail.com>
Cc: devicetree@vger.kernel.org, linux-input@vger.kernel.org,
mfd@lists.linux.dev, robh@kernel.org, conor+dt@kernel.org,
dmitry.torokhov@gmail.com, lee@kernel.org
Subject: Re: [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table
Date: Sun, 06 Dec 2026 03:24:24 +0000 [thread overview]
Message-ID: <sashiko-outbox-252122@kernel.org> (raw)
In-Reply-To: <20261206-axp192-v7-7-0200fc77da53@gmail.com>
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [Medium] power: axp20x_battery: probe race on bat_info and batt in ocv
capacity path
- [Low] power: axp20x_battery: missing has_fg in axp717_data retains
unused bat_info
- [Low] power: axp20x_battery: unconditional CURRENT_NOW read in ocv
capacity path
- [Low] power: axp20x_battery: stray board codename in
axp20x_battery_ocv_capacity()
- [Low] power: axp20x_battery: axp192_battery_props duplicates
axp20x_battery_props
--
commit a78f3397c5935dce53f82b239be5baaf83190c73
Author: Molnár Máté <matemolnar88@gmail.com>
power: axp20x_battery: Estimate AXP192 capacity from the OCV table
This commit estimates battery capacity from the battery's OCV table on
PMICs without a fuel gauge, exposes POWER_SUPPLY_PROP_CAPACITY on AXP192,
and keeps the parsed battery info around after probe for those PMICs.
> diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c
> index b55089a81e17d..3c3cf349f9dda 100644
> --- a/drivers/power/supply/axp20x_battery.c
> +++ b/drivers/power/supply/axp20x_battery.c
[ ... ]
> @@ -285,6 +288,50 @@ static int axp717_get_constant_charge_current(struct axp20x_batt_ps *axp,
[ ... ]
> + ret = axp20x_battery_get_prop(axp20x_batt->batt,
> + POWER_SUPPLY_PROP_CURRENT_NOW, &i);
> + if (ret)
> + return ret;
> +
> + if (info->factory_internal_resistance_uohm > 0)
> + v.intval -= div_s64((s64)i.intval *
> + info->factory_internal_resistance_uohm,
> + 1000000);
[Severity: Low]
Should the POWER_SUPPLY_PROP_CURRENT_NOW read be moved inside the
factory_internal_resistance_uohm check?
When factory-internal-resistance-micro-ohms is omitted from devicetree,
power_supply_get_battery_info() leaves factory_internal_resistance_uohm at
-EINVAL and i.intval is discarded. Reading CURRENT_NOW unconditionally
triggers unnecessary volatile I2C reads on every capacity query and fails
capacity estimation if the unused current channel returns an error.
> +
> + /* ponytail: no temperature sensor wired up, assume 20 C */
> + ret = power_supply_batinfo_ocv2cap(info, v.intval, 20);
[Severity: Low]
This isn't a bug, but "ponytail" looks like a leftover out-of-tree board
codename in a generic PMIC driver comment.
[ ... ]
> @@ -955,6 +1006,7 @@ static enum power_supply_property axp192_battery_props[] = {
> POWER_SUPPLY_PROP_HEALTH,
> POWER_SUPPLY_PROP_VOLTAGE_MAX,
> POWER_SUPPLY_PROP_VOLTAGE_MIN,
> + POWER_SUPPLY_PROP_CAPACITY,
> };
[Severity: Low]
With POWER_SUPPLY_PROP_CAPACITY added, axp192_battery_props[] is now
identical to axp20x_battery_props[]. Can axp192_batt_ps_desc reuse
axp20x_battery_props directly and drop the duplicate array?
> @@ -1237,7 +1289,11 @@ static int axp20x_power_probe(struct platform_device *pdev)
>
> if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) {
> axp20x_batt->data->set_bat_info(pdev, axp20x_batt, info);
> - power_supply_put_battery_info(axp20x_batt->batt, info);
> + /* Without a fuel gauge the OCV table is used for the capacity */
> + if (axp20x_batt->data->has_fg)
> + power_supply_put_battery_info(axp20x_batt->batt, info);
[Severity: Low]
Does gating power_supply_put_battery_info() on data->has_fg retain an
unused battery_info allocation on AXP717?
axp717_data omits .has_fg = true even though AXP717 has a hardware fuel
gauge and axp717_battery_get_prop() reads AXP717_BATT_PERCENT_DATA
directly without ever using axp20x_batt->bat_info.
> + else
> + axp20x_batt->bat_info = info;
> }
[Severity: Medium]
Can concurrent sysfs readers race with axp20x_power_probe() on
axp20x_batt->bat_info and axp20x_batt->batt?
devm_power_supply_register() calls device_add() and sets
psy->initialized = true before returning, so userspace (such as udev or
UPower) can read capacity while probe is still storing axp20x_batt->batt
and axp20x_batt->bat_info:
CPU0 CPU1
axp20x_power_probe()
devm_power_supply_register()
device_add()
psy->initialized = true
axp20x_batt->batt = psy
...
axp20x_batt->bat_info = info
sysfs read capacity
axp20x_battery_ocv_capacity()
info = axp20x_batt->bat_info
axp20x_battery_get_prop(
axp20x_batt->batt, ...)
<-- NULL deref if reordered
Both pointers are written and read with plain accesses and no locking or
release/acquire ordering. Early readers before bat_info is stored get
spurious -ENODATA, and on weakly-ordered architectures CPU1 can observe a
non-NULL bat_info alongside uninitialized *info fields or a stale NULL
axp20x_batt->batt, leading to a NULL pointer dereference in
power_supply_get_drvdata().
In addition, __power_supply_register() already parses and stores
psy->battery_info before device_add() for POWER_SUPPLY_TYPE_BATTERY
devices, so keeping bat_info duplicates that allocation. Passing psy from
axp20x_battery_get_prop() into axp20x_battery_ocv_capacity() and reading
psy->battery_info avoids the probe race, the bat_info field, and the
duplicate allocation.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-axp192-v7-0-0200fc77da53@gmail.com?part=7
next prev parent reply other threads:[~2026-12-06 3:24 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 3:08 [PATCH v7 0/9] Add the remaining AXP192 PMIC support Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 1/9] dt-bindings: iio: adc: axp209: Add AXP192 compatible Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 2/9] dt-bindings: power: axp20x-battery: " Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 3/9] regulator: axp20x: Add support for AXP192 Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:22 ` sashiko-bot
2026-12-06 3:08 ` [PATCH v7 4/9] power: axp20x_battery: Add constant charge current table Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:24 ` sashiko-bot
2026-12-06 3:08 ` [PATCH v7 5/9] power: axp20x_battery: Support battery status without fuel gauge Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:23 ` sashiko-bot
2026-12-06 3:08 ` [PATCH v7 6/9] power: axp20x_battery: Add support for AXP192 Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:08 ` [PATCH v7 7/9] power: axp20x_battery: Estimate AXP192 capacity from the OCV table Molnár Máté
2026-12-06 3:08 ` Molnár Máté via B4 Relay
2026-12-06 3:24 ` sashiko-bot [this message]
2026-12-06 3:09 ` [PATCH v7 8/9] Input: axp20x-pek: Add AXP192 support Molnár Máté
2026-12-06 3:09 ` Molnár Máté via B4 Relay
2026-12-06 3:21 ` sashiko-bot
2026-12-06 3:09 ` [PATCH v7 9/9] mfd: axp20x: Add the AXP192 power key cell Molnár Máté
2026-12-06 3:09 ` Molnár Máté via B4 Relay
2026-12-06 3:18 ` sashiko-bot
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=sashiko-outbox-252122@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=lee@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=matemolnar88@gmail.com \
--cc=mfd@lists.linux.dev \
--cc=robh@kernel.org \
--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.