public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: Dhruva Gole <d-gole@ti.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Linux PM <linux-pm@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>
Subject: Re: [PATCH v1] cpuidle: Fail cpuidle device registration if there is one already
Date: Fri, 19 Sep 2025 10:39:28 +0530	[thread overview]
Message-ID: <20250919050928.6sprmdpz2pwgydcc@lcpd911> (raw)
In-Reply-To: <3374815.aeNJFYEL58@rafael.j.wysocki>

Hi Rafael,

On Sep 18, 2025 at 23:19:20 +0200, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.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@intel.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 ?

> +	}
> +
>  	for (i = 0; i < drv->state_count; i++) {
>  		if (drv->states[i].flags & CPUIDLE_FLAG_UNUSABLE)
>  			dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_DRIVER;
> @@ -648,7 +654,7 @@ static int __cpuidle_register_device(str
>  			dev->states_usage[i].disable |= CPUIDLE_STATE_DISABLED_BY_USER;
>  	}
>  
> -	per_cpu(cpuidle_devices, dev->cpu) = dev;
> +	per_cpu(cpuidle_devices, cpu) = dev;
>  	list_add(&dev->device_list, &cpuidle_detected_devices);
>  
>  	ret = cpuidle_coupled_register_device(dev);
> 
> 
> 
> 

-- 
Best regards,
Dhruva Gole
Texas Instruments Incorporated

  reply	other threads:[~2025-09-19  5:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-18 21:19 [PATCH v1] cpuidle: Fail cpuidle device registration if there is one already Rafael J. Wysocki
2025-09-19  5:09 ` Dhruva Gole [this message]
2025-09-19 11:14   ` Rafael J. Wysocki

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=20250919050928.6sprmdpz2pwgydcc@lcpd911 \
    --to=d-gole@ti.com \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox