[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAJZ5v0hCaLebTwtm36dxxG0NBOc1DVPj9cjYHKOWm5kApNa1TQ@mail.gmail.com>
Date: Fri, 19 Sep 2025 13:14:10 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Dhruva Gole <d-gole@...com>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>, Linux PM <linux-pm@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>, Daniel Lezcano <daniel.lezcano@...aro.org>
Subject: Re: [PATCH v1] cpuidle: Fail cpuidle device registration if there is
one already
Hi,
On Fri, Sep 19, 2025 at 7:09 AM Dhruva Gole <d-gole@...com> wrote:
>
> Hi Rafael,
>
> On Sep 18, 2025 at 23:19:20 +0200, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
> >
> > Refuse to register a cpuidle device if the given CPU has a cpuidle
> > device already and print a message regarding it.
> >
> > Without this, an attempt to register a new cpuidle device without
> > unregistering the existing one leads to the removal of the existing
> > cpuidle device without removing its sysfs interface.
> >
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@...el.com>
> > ---
> > drivers/cpuidle/cpuidle.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > --- a/drivers/cpuidle/cpuidle.c
> > +++ b/drivers/cpuidle/cpuidle.c
> > @@ -635,11 +635,17 @@ static void __cpuidle_device_init(struct
> > static int __cpuidle_register_device(struct cpuidle_device *dev)
> > {
> > struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
> > + unsigned int cpu = dev->cpu;
> > int i, ret;
> >
> > if (!try_module_get(drv->owner))
> > return -EINVAL;
> >
> > + if (per_cpu(cpuidle_devices, cpu)) {
> > + pr_info("CPU%d: cpuidle device already registered\n", cpu);
> > + return -EEXIST;
>
> Here we return prematurely after a try_module_get right?
> Do we need a module_put() similar to how you do it later by calling
> unregister_device function by checking ret = cpuidle_coupled_register_device ?
Good catch, thanks!
I need to move the new check above the driver module reference counting.
Powered by blists - more mailing lists