Re: [PATCH net-next v6 04/12] net: pse-pd: Add support for PSE power domains
From: Kory Maincent
Date: Thu Mar 20 2025 - 11:48:09 EST
On Mon, 17 Mar 2025 10:59:02 +0100
Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx> wrote:
> On Tue, Mar 04, 2025 at 11:18:53AM +0100, Kory Maincent wrote:
> > +static int pse_register_pw_ds(struct pse_controller_dev *pcdev)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < pcdev->nr_lines; i++) {
> > + struct regulator_dev *rdev = pcdev->pi[i].rdev;
> > + struct pse_power_domain *pw_d;
> > + struct regulator *supply;
> > + bool present = false;
> > + unsigned long index;
> > +
> > + /* No regulator or regulator parent supply registered.
> > + * We need a regulator parent to register a PSE power
> > domain
> > + */
> > + if (!rdev || !rdev->supply)
> > + continue;
> > +
>
> Should we use xa_lock() before iteration over the map?
I am scratching my head to find out the case where it may be needed.
The only case I think of is two PSE controller with PSE PI using the same power
supply. Which is not a good idea for well distributing power.
In this case we could have two pse_register_pw_ds running concurrently and we
could have issues. Not only the iteration over the map should be protected but
also the content of the pw_d entry. Also when we unbind one of the PSE
controller it will remove all the PSE power domains event if they are used
by another PSE. :/
I need to add refcount and lock on the PSE power domains to fix this case!
> > + xa_for_each(&pse_pw_d_map, index, pw_d) {
> > + /* Power supply already registered as a PSE power
> > + * domain.
> > + */
> > + if (regulator_is_equal(pw_d->supply,
> > rdev->supply)) {
> > + present = true;
> > + pcdev->pi[i].pw_d = pw_d;
> > + break;
> > + }
> > + }
> > + if (present)
> > + continue;
> > +
> > + pw_d = devm_pse_alloc_pw_d(pcdev->dev);
> > + if (IS_ERR_OR_NULL(pw_d))
> > + return PTR_ERR(pw_d);
>
> It is better to break the loop and roll back previous allocations.
This will be done by pse_flush_pw_ds called by devm_pse_controller_release as
the pse_controller_register failed.
Regards,
--
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com