* [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection
@ 2026-03-02 10:54 Pengpeng Hou
2026-03-04 10:43 ` Zhongqiu Han
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Pengpeng Hou @ 2026-03-02 10:54 UTC (permalink / raw)
To: Rafael J . Wysocki; +Cc: linux-pm, linux-kernel, Pengpeng Hou
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.
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);
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection
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
2026-03-04 22:56 ` kernel test robot
2026-03-04 23:07 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: Zhongqiu Han @ 2026-03-04 10:43 UTC (permalink / raw)
To: Pengpeng Hou, Rafael J . Wysocki; +Cc: linux-pm, linux-kernel, zhongqiu.han
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection
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
@ 2026-03-04 22:56 ` kernel test robot
2026-03-04 23:07 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-03-04 22:56 UTC (permalink / raw)
To: Pengpeng Hou, Rafael J . Wysocki
Cc: llvm, oe-kbuild-all, linux-pm, linux-kernel, Pengpeng Hou
Hi Pengpeng,
kernel test robot noticed the following build errors:
[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on rafael-pm/bleeding-edge amd-pstate/linux-next amd-pstate/bleeding-edge linus/master v7.0-rc2 next-20260303]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Pengpeng-Hou/PM-Move-to_device-out-of-CONFIG_PM_SLEEP-protection/20260302-190351
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20260302105456.4134882-1-pengpeng.hou%40isrc.iscas.ac.cn
patch subject: [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection
config: x86_64-allnoconfig (https://download.01.org/0day-ci/archive/20260305/202603050651.Tp7mTeNL-lkp@intel.com/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260305/202603050651.Tp7mTeNL-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603050651.Tp7mTeNL-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from drivers/base/core.c:38:
>> drivers/base/power/power.h:163:50: error: no member named 'entry' in 'struct dev_pm_info'
163 | return container_of(entry, struct device, power.entry);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
include/linux/container_of.h:21:49: note: expanded from macro 'container_of'
21 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
22 | __same_type(*(ptr), void), \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 | "pointer type mismatch in container_of()"); \
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/compiler_types.h:617:74: note: expanded from macro '__same_type'
617 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
| ^
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
77 | #define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
In file included from drivers/base/core.c:38:
>> drivers/base/power/power.h:163:9: error: no member named 'entry' in 'dev_pm_info'
163 | return container_of(entry, struct device, power.entry);
| ^ ~~~~~~
include/linux/container_of.h:24:21: note: expanded from macro 'container_of'
24 | ((type *)(__mptr - offsetof(type, member))); })
| ^ ~~~~~~
include/linux/stddef.h:16:32: note: expanded from macro 'offsetof'
16 | #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
| ^ ~~~~~~
2 errors generated.
vim +163 drivers/base/power/power.h
160
161 static inline struct device *to_device(struct list_head *entry)
162 {
> 163 return container_of(entry, struct device, power.entry);
164 }
165
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection
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
2026-03-04 22:56 ` kernel test robot
@ 2026-03-04 23:07 ` kernel test robot
2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-03-04 23:07 UTC (permalink / raw)
To: Pengpeng Hou, Rafael J . Wysocki
Cc: oe-kbuild-all, linux-pm, linux-kernel, Pengpeng Hou
Hi Pengpeng,
kernel test robot noticed the following build errors:
[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on rafael-pm/bleeding-edge amd-pstate/linux-next amd-pstate/bleeding-edge linus/master v7.0-rc2 next-20260304]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Pengpeng-Hou/PM-Move-to_device-out-of-CONFIG_PM_SLEEP-protection/20260302-190351
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20260302105456.4134882-1-pengpeng.hou%40isrc.iscas.ac.cn
patch subject: [PATCH] PM: Move to_device() out of CONFIG_PM_SLEEP protection
config: sh-se7751_defconfig (https://download.01.org/0day-ci/archive/20260305/202603050624.gml2vPY4-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260305/202603050624.gml2vPY4-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202603050624.gml2vPY4-lkp@intel.com/
All errors (new ones prefixed by >>):
In file included from include/linux/bits.h:30,
from include/linux/ioport.h:14,
from include/linux/acpi.h:13,
from drivers/base/core.c:11:
drivers/base/power/power.h: In function 'to_device':
>> drivers/base/power/power.h:163:56: error: 'struct dev_pm_info' has no member named 'entry'
163 | return container_of(entry, struct device, power.entry);
| ^
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:21:9: note: in expansion of macro 'static_assert'
21 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:21:23: note: in expansion of macro '__same_type'
21 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
drivers/base/power/power.h:163:16: note: in expansion of macro 'container_of'
163 | return container_of(entry, struct device, power.entry);
| ^~~~~~~~~~~~
include/linux/compiler_types.h:617:27: error: expression in static assertion is not an integer
617 | #define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: in definition of macro '__static_assert'
78 | #define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
| ^~~~
include/linux/container_of.h:21:9: note: in expansion of macro 'static_assert'
21 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~~~
include/linux/container_of.h:21:23: note: in expansion of macro '__same_type'
21 | static_assert(__same_type(*(ptr), ((type *)0)->member) || \
| ^~~~~~~~~~~
drivers/base/power/power.h:163:16: note: in expansion of macro 'container_of'
163 | return container_of(entry, struct device, power.entry);
| ^~~~~~~~~~~~
In file included from include/uapi/linux/posix_types.h:5,
from include/uapi/linux/types.h:14,
from include/linux/types.h:5,
from include/linux/kasan-checks.h:5,
from include/asm-generic/rwonce.h:26,
from ./arch/sh/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:372,
from include/linux/cleanup.h:5,
from include/linux/acpi.h:11:
>> include/linux/stddef.h:16:33: error: 'struct dev_pm_info' has no member named 'entry'
16 | #define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
| ^~~~~~~~~~~~~~~~~~
include/linux/container_of.h:24:28: note: in expansion of macro 'offsetof'
24 | ((type *)(__mptr - offsetof(type, member))); })
| ^~~~~~~~
drivers/base/power/power.h:163:16: note: in expansion of macro 'container_of'
163 | return container_of(entry, struct device, power.entry);
| ^~~~~~~~~~~~
vim +163 drivers/base/power/power.h
160
161 static inline struct device *to_device(struct list_head *entry)
162 {
> 163 return container_of(entry, struct device, power.entry);
164 }
165
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-03-04 23:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2026-03-04 22:56 ` kernel test robot
2026-03-04 23:07 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox