The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
To: Pengpeng Hou <pengpeng.hou@isrc.iscas.ac.cn>,
	"Rafael J . Wysocki" <rafael@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	zhongqiu.han@oss.qualcomm.com
Subject: Re: [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection
Date: Wed, 4 Mar 2026 18:43:16 +0800	[thread overview]
Message-ID: <706e901b-9152-4a88-b5fa-7ab611665136@oss.qualcomm.com> (raw)
In-Reply-To: <20260302105456.4134882-1-pengpeng.hou@isrc.iscas.ac.cn>

On 3/2/2026 6:54 PM, Pengpeng Hou wrote:
> The helper function to_device() is used to convert a list_head structure
> (specifically from dev->power.entry) back to the corresponding struct
> device. Currently, this function is only available when CONFIG_PM_SLEEP
> is enabled. However, some generic power management code may need to iterate
> through the device list even if sleep states (suspend/hibernate) are not
> supported.

Hi Pengpeng,

Thank you for the patch. However, I have some concerns about this
change:

1.Your commit message states that "some generic power management code
may need to iterate through the device list even if sleep states are not
supported." Could you please provide a concrete example of such code?

2.The to_device() function accesses dev->power.entry, which is only
present when CONFIG_PM_SLEEP is enabled:

struct dev_pm_info {
	...
#ifdef CONFIG_PM_SLEEP
	struct list_head	entry;
}

This means any code trying to use to_device() with CONFIG_PM_SLEEP=n 
would _FAIL_ to compile when actually called.


> 
> There are currently two approaches for moving the function.The first one:
> judging from the current conditions where the function is called, all calls
> are not wrapped by any macros, so it is appropriate to move the function
> definition to the global scope.The second one: if the compilation of the
> files where the function is called is controlled by CONFIG_PM, it is more
> appropriate to move the function definition into CONFIG_PM.
> 
> To ensure that the availability of the function is consistent with its
> usage scenarios and to avoid undefined reference compilation errors, the
> first approach is adopted.
> 
> Signed-off-by: Pengpeng Hou <pengpeng.hou@isrc.iscas.ac.cn>
> ---
>   drivers/base/power/power.h | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
> index 922ed457d..0a40bb546 100644
> --- a/drivers/base/power/power.h
> +++ b/drivers/base/power/power.h
> @@ -106,10 +106,6 @@ extern int pm_async_enabled;
>   /* drivers/base/power/main.c */
>   extern struct list_head dpm_list;	/* The active device list */
>   
> -static inline struct device *to_device(struct list_head *entry)
> -{
> -	return container_of(entry, struct device, power.entry);
> -}
>   
>   extern void device_pm_sleep_init(struct device *dev);
>   extern void device_pm_add(struct device *);
> @@ -162,6 +158,11 @@ static inline int pm_wakeup_source_sysfs_add(struct device *parent)
>   
>   #endif /* !CONFIG_PM_SLEEP */
>   
> +static inline struct device *to_device(struct list_head *entry)
> +{
> +	return container_of(entry, struct device, power.entry);
> +}
> +
>   static inline void device_pm_init(struct device *dev)
>   {
>   	device_pm_init_common(dev);


-- 
Thx and BRs,
Zhongqiu Han

  reply	other threads:[~2026-03-04 10:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 10:54 [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection Pengpeng Hou
2026-03-04 10:43 ` Zhongqiu Han [this message]
2026-03-04 22:56 ` kernel test robot
2026-03-04 23:07 ` kernel test robot

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=706e901b-9152-4a88-b5fa-7ab611665136@oss.qualcomm.com \
    --to=zhongqiu.han@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=pengpeng.hou@isrc.iscas.ac.cn \
    --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