Re: [PATCH v2 2/4] power: supply: core: Allow getting battery info before psy is registered

From: Alexey Charkov

Date: Thu Sep 10 2026 - 06:06:45 EST


Hello Sebastian,

On Wed, Sep 9, 2026 at 11:52 PM Sebastian Reichel
<sebastian.reichel@xxxxxxxxxxxxx> wrote:
>
> Hello Alexey,
>
> On Wed, Sep 09, 2026 at 07:41:45PM +0400, Alexey Charkov wrote:
> > Some power supplies, such as battery chargers, may need to program the
> > device parameters based on what their connected battery allows. Current
> > API requires registering the power supply to access battery information,
> > which is problematic because a registered power supply is immediately
> > available to the rest of the system, but the battery parameters may not
> > be set yet in the charger.
> >
> > Given that the battery info helpers really only need a fwnode and a struct
> > device to hang devres-allocated resourses on, add a pure dev-based get/put
> > API alongside the existing psy-based one, which can be used to query the
> > battery information before registering the power supply.
>
> Use the new init callback for that, which got introduced in the v7.3
> cycle:
>
> c1eb5905fdce ("power: supply: Add registration init callback")
>
> See for example fdece8642eca ("power: supply: bq25630: Initialize
> hardware before exposing the power supply") for a driver that was
> converted to this.

Indeed, that should work quite neatly, thank you for pointing it out
(I've missed that addition). I'll then drop patch 2 and rework patches
3 and 4 to use the init callback. I believe they can then form a
separate mini-series only touching the driver but not the core.

Patch 1 still stands on its own, though, as it prevents a
use-after-free during teardown. Would you mind giving that a look?

Thanks a lot,
Alexey