Re: [PATCH] power: supply: bq25630: Release battery information after setup

Sebastian Reichel <[email protected]>
Newsgroups org.kernel.vger.linux-pm
Message-ID <amfC7EN4d_72zLqH@venus>
Hi,

On Mon, Jul 27, 2026 at 02:43:37PM +0200, Waqar Hameed wrote:
> On Mon, Jul 27, 2026 at 17:37 +0800 Linmao Li <[email protected]> wrote:
> 
> > data->batinfo is only used by bq25630_setup() to program the initial
> > charge limits, but power_supply_get_battery_info() allocates it on
> > psy->dev, so it stays around for the lifetime of the device. Nothing
> > else in the driver uses it. Release it right after setup, as bq256xx
> > and bq257xx do.
> >
> > Signed-off-by: Linmao Li <[email protected]>
> > ---
> >  drivers/power/supply/bq25630_charger.c | 5 ++---
> >  1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/power/supply/bq25630_charger.c b/drivers/power/supply/bq25630_charger.c
> > index 165f8c67b4895..efcdb1f5bc351 100644
> > --- a/drivers/power/supply/bq25630_charger.c
> > +++ b/drivers/power/supply/bq25630_charger.c
> > @@ -1045,10 +1045,9 @@ static int bq25630_probe(struct i2c_client *client)
> >  		return dev_err_probe(data->dev, ret, "Could not request IRQ\n");
> >  
> >  	ret = bq25630_setup(data);
> > -	if (ret)
> > -		return ret;
> > +	power_supply_put_battery_info(data->psy, data->batinfo);
> >  
> > -	return 0;
> > +	return ret;
> >  }
> >  
> >  static const struct of_device_id bq25630_of_match[] = {
> 
> The initial thought was that `batinfo` could/would be used elsewhere,
> but as you point out, it's currently not. A better design is then to
> move the `power_supply_get_battery_info()` into `bq25630_setup()`, in
> order to scope the `get/put()`. So let's get `batinfo` there, just
> before using it, and have an error/clean-up-path there as well.

Agreed. Keeping an invalid pointer makes no sense.

The setup routine is also a good candidate for the new
.init callback now available in struct power_supply_desc,
so that the registers are initialized before the device
is exposed to the system.

Greetings,

-- Sebastian
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmpnxHAACgkQ2O7X88g7
+prGVQ//eNA6uJh4EZCUhxWFMKXSnhKVR81uq1rDW4iJOonoruQ7zAG12hIjWDf+
qR7auzrypE5BDa2SVHhok0QWH6pC1Alk83Sc8Qd+o8xaiWkAh0Qi2GCl61CbNnxB
hYq0rVxZkqiw7cQ3xmuQTPrnKZo9s7964aT/GsbHpdTY2C9t9cVynF9fsIE5yqby
Ox6pWTpeI04HHp/2gN8NlYoFqpGnB671f8IYM0jzYU7LucB/NRYm4iA35mwaUiat
iENe/+wm4ukM04fAOiukUFcVAAtNIok8gLewBywEthwd4/G4jRV/bk6BFpfqkoNd
s7LPzgJSIKdjT3U8PLPUINRImxlUj98uVdbnfs7FAX/DkhY6dPP94z7UZUQh4XuX
Bii1cgyMN/mIiiGit2SxEad2v9Z3ROZB8Lq0KMuyAoQHMgziTUdfXl39PJRl76p5
TitSDS0viX3j0EssPSowJUpMGzuRNeePcotfZFXWlW8ha1BWAVNvfW7CWTVoCmUC
r1+ZGg4hmYpgC5BppuwMHrYPhFDQNHBEkOqN1M6+EkPOdLeao1sQLK5hiYdbrNuy
EoxHf4nr0/IFb6xdfJ7s6tYy6KPnuA83PvtDFDuT2+mtr1BzA7DLVyfqMGzVCzfz
svC6hdqeDHTYJKXRlmIMWAydCD67tynPGm5yML6FkifQb8j5+8k=
=PnnC
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.