Message ID | 20210408205858.51751-3-masahiroy@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | linux/kconfig.h: move IF_ENABLED() out of <linux/kconfig.h> | expand |
On Thu, Apr 8, 2021 at 11:00 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > Drivers typically surround suspend and resume callbacks with #ifdef > CONFIG_PM(_SLEEP) or mark them as __maybe_unused in order to avoid > -Wunused-const-variable warnings. > > With this commit, drivers will be able to remove #ifdef CONFIG_PM(_SLEEP) > and __maybe_unsed because unused functions are dropped by the compiler > instead of the preprocessor. > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> I tried this before and could not get it to work right. > > -#ifdef CONFIG_PM_SLEEP > +#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), _ptr) > +#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), _ptr) > + > #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ > - .suspend = suspend_fn, \ > - .resume = resume_fn, \ > - .freeze = suspend_fn, \ > - .thaw = resume_fn, \ > - .poweroff = suspend_fn, \ > - .restore = resume_fn, > -#else > -#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) > -#endif > + .suspend = pm_sleep_ptr(suspend_fn), \ > + .resume = pm_sleep_ptr(resume_fn), \ > + .freeze = pm_sleep_ptr(suspend_fn), \ > + .thaw = pm_sleep_ptr(resume_fn), \ > + .poweroff = pm_sleep_ptr(suspend_fn), \ > + .restore = pm_sleep_ptr(resume_fn), The problem that I think you inevitably hit is that you run into a missing declaration for any driver that still uses an #ifdef around a static function. The only way I can see us doing this is to create a new set of macros that behave like the version you propose here but leave the old macros in place until the last such #ifdef has been removed. Arnd
Hi Masahiro, I love your patch! Yet something to improve: [auto build test ERROR on pinctrl/devel] [also build test ERROR on pm/linux-next soc/for-next linus/master v5.12-rc6] [cannot apply to next-20210408] [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] url: https://github.com/0day-ci/linux/commits/Masahiro-Yamada/linux-kconfig-h-move-IF_ENABLED-out-of-linux-kconfig-h/20210409-050128 base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel config: nds32-randconfig-r004-20210408 (attached as .config) compiler: nds32le-linux-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/01dfb9e1a54c14b3f491c3a5e93f1e8756042567 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Masahiro-Yamada/linux-kconfig-h-move-IF_ENABLED-out-of-linux-kconfig-h/20210409-050128 git checkout 01dfb9e1a54c14b3f491c3a5e93f1e8756042567 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nds32 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): In file included from drivers/input/rmi4/rmi_spi.c:7: drivers/input/rmi4/rmi_spi.c:507:26: error: 'rmi_spi_suspend' undeclared here (not in a function); did you mean 'rmi_driver_suspend'? 507 | SET_SYSTEM_SLEEP_PM_OPS(rmi_spi_suspend, rmi_spi_resume) | ^~~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:308:14: note: in expansion of macro 'pm_sleep_ptr' 308 | .suspend = pm_sleep_ptr(suspend_fn), \ | ^~~~~~~~~~~~ drivers/input/rmi4/rmi_spi.c:507:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 507 | SET_SYSTEM_SLEEP_PM_OPS(rmi_spi_suspend, rmi_spi_resume) | ^~~~~~~~~~~~~~~~~~~~~~~ drivers/input/rmi4/rmi_spi.c:507:43: error: 'rmi_spi_resume' undeclared here (not in a function); did you mean 'rmi_spi_pm'? 507 | SET_SYSTEM_SLEEP_PM_OPS(rmi_spi_suspend, rmi_spi_resume) | ^~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:309:14: note: in expansion of macro 'pm_sleep_ptr' 309 | .resume = pm_sleep_ptr(resume_fn), \ | ^~~~~~~~~~~~ drivers/input/rmi4/rmi_spi.c:507:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 507 | SET_SYSTEM_SLEEP_PM_OPS(rmi_spi_suspend, rmi_spi_resume) | ^~~~~~~~~~~~~~~~~~~~~~~ >> drivers/input/rmi4/rmi_spi.c:508:21: error: 'rmi_spi_runtime_suspend' undeclared here (not in a function) 508 | SET_RUNTIME_PM_OPS(rmi_spi_runtime_suspend, rmi_spi_runtime_resume, | ^~~~~~~~~~~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:332:21: note: in expansion of macro 'pm_ptr' 332 | .runtime_suspend = pm_ptr(suspend_fn), \ | ^~~~~~ drivers/input/rmi4/rmi_spi.c:508:2: note: in expansion of macro 'SET_RUNTIME_PM_OPS' 508 | SET_RUNTIME_PM_OPS(rmi_spi_runtime_suspend, rmi_spi_runtime_resume, | ^~~~~~~~~~~~~~~~~~ >> drivers/input/rmi4/rmi_spi.c:508:46: error: 'rmi_spi_runtime_resume' undeclared here (not in a function) 508 | SET_RUNTIME_PM_OPS(rmi_spi_runtime_suspend, rmi_spi_runtime_resume, | ^~~~~~~~~~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:333:21: note: in expansion of macro 'pm_ptr' 333 | .runtime_resume = pm_ptr(resume_fn), \ | ^~~~~~ drivers/input/rmi4/rmi_spi.c:508:2: note: in expansion of macro 'SET_RUNTIME_PM_OPS' 508 | SET_RUNTIME_PM_OPS(rmi_spi_runtime_suspend, rmi_spi_runtime_resume, | ^~~~~~~~~~~~~~~~~~ -- In file included from include/linux/list.h:9, from include/linux/rculist.h:10, from include/linux/pid.h:5, from include/linux/sched.h:14, from include/linux/ratelimit.h:6, from include/linux/dev_printk.h:16, from include/linux/device.h:15, from include/linux/backlight.h:12, from drivers/video/backlight/ams369fg06.c:11: >> drivers/video/backlight/ams369fg06.c:541:45: error: 'ams369fg06_suspend' undeclared here (not in a function); did you mean 'ams369fg06_probe'? 541 | static SIMPLE_DEV_PM_OPS(ams369fg06_pm_ops, ams369fg06_suspend, | ^~~~~~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:308:14: note: in expansion of macro 'pm_sleep_ptr' 308 | .suspend = pm_sleep_ptr(suspend_fn), \ | ^~~~~~~~~~~~ include/linux/pm.h:342:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 342 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ | ^~~~~~~~~~~~~~~~~~~~~~~ drivers/video/backlight/ams369fg06.c:541:8: note: in expansion of macro 'SIMPLE_DEV_PM_OPS' 541 | static SIMPLE_DEV_PM_OPS(ams369fg06_pm_ops, ams369fg06_suspend, | ^~~~~~~~~~~~~~~~~ >> drivers/video/backlight/ams369fg06.c:542:4: error: 'ams369fg06_resume' undeclared here (not in a function); did you mean 'ams369fg06_remove'? 542 | ams369fg06_resume); | ^~~~~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:309:14: note: in expansion of macro 'pm_sleep_ptr' 309 | .resume = pm_sleep_ptr(resume_fn), \ | ^~~~~~~~~~~~ include/linux/pm.h:342:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 342 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ | ^~~~~~~~~~~~~~~~~~~~~~~ drivers/video/backlight/ams369fg06.c:541:8: note: in expansion of macro 'SIMPLE_DEV_PM_OPS' 541 | static SIMPLE_DEV_PM_OPS(ams369fg06_pm_ops, ams369fg06_suspend, | ^~~~~~~~~~~~~~~~~ -- In file included from include/linux/delay.h:22, from drivers/video/backlight/vgg2432a4.c:11: >> drivers/video/backlight/vgg2432a4.c:246:44: error: 'vgg2432a4_suspend' undeclared here (not in a function); did you mean 'vgg2432a4_client'? 246 | static SIMPLE_DEV_PM_OPS(vgg2432a4_pm_ops, vgg2432a4_suspend, vgg2432a4_resume); | ^~~~~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:308:14: note: in expansion of macro 'pm_sleep_ptr' 308 | .suspend = pm_sleep_ptr(suspend_fn), \ | ^~~~~~~~~~~~ include/linux/pm.h:342:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 342 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ | ^~~~~~~~~~~~~~~~~~~~~~~ drivers/video/backlight/vgg2432a4.c:246:8: note: in expansion of macro 'SIMPLE_DEV_PM_OPS' 246 | static SIMPLE_DEV_PM_OPS(vgg2432a4_pm_ops, vgg2432a4_suspend, vgg2432a4_resume); | ^~~~~~~~~~~~~~~~~ >> drivers/video/backlight/vgg2432a4.c:246:63: error: 'vgg2432a4_resume' undeclared here (not in a function); did you mean 'vgg2432a4_remove'? 246 | static SIMPLE_DEV_PM_OPS(vgg2432a4_pm_ops, vgg2432a4_suspend, vgg2432a4_resume); | ^~~~~~~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:309:14: note: in expansion of macro 'pm_sleep_ptr' 309 | .resume = pm_sleep_ptr(resume_fn), \ | ^~~~~~~~~~~~ include/linux/pm.h:342:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 342 | SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ | ^~~~~~~~~~~~~~~~~~~~~~~ drivers/video/backlight/vgg2432a4.c:246:8: note: in expansion of macro 'SIMPLE_DEV_PM_OPS' 246 | static SIMPLE_DEV_PM_OPS(vgg2432a4_pm_ops, vgg2432a4_suspend, vgg2432a4_resume); | ^~~~~~~~~~~~~~~~~ vim +/rmi_spi_runtime_suspend +508 drivers/input/rmi4/rmi_spi.c 8d99758dee31ff Andrew Duggan 2016-03-10 505 8d99758dee31ff Andrew Duggan 2016-03-10 506 static const struct dev_pm_ops rmi_spi_pm = { 8d99758dee31ff Andrew Duggan 2016-03-10 @507 SET_SYSTEM_SLEEP_PM_OPS(rmi_spi_suspend, rmi_spi_resume) 8d99758dee31ff Andrew Duggan 2016-03-10 @508 SET_RUNTIME_PM_OPS(rmi_spi_runtime_suspend, rmi_spi_runtime_resume, 8d99758dee31ff Andrew Duggan 2016-03-10 509 NULL) 8d99758dee31ff Andrew Duggan 2016-03-10 510 }; 8d99758dee31ff Andrew Duggan 2016-03-10 511 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Hi Masahiro, I love your patch! Yet something to improve: [auto build test ERROR on pinctrl/devel] [also build test ERROR on pm/linux-next soc/for-next linus/master v5.12-rc6] [cannot apply to next-20210408] [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] url: https://github.com/0day-ci/linux/commits/Masahiro-Yamada/linux-kconfig-h-move-IF_ENABLED-out-of-linux-kconfig-h/20210409-050128 base: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl.git devel config: xtensa-randconfig-r023-20210408 (attached as .config) compiler: xtensa-linux-gcc (GCC) 9.3.0 reproduce (this is a W=1 build): wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # https://github.com/0day-ci/linux/commit/01dfb9e1a54c14b3f491c3a5e93f1e8756042567 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Masahiro-Yamada/linux-kconfig-h-move-IF_ENABLED-out-of-linux-kconfig-h/20210409-050128 git checkout 01dfb9e1a54c14b3f491c3a5e93f1e8756042567 # save the attached .config to linux build tree COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=xtensa If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <lkp@intel.com> All errors (new ones prefixed by >>): In file included from include/linux/delay.h:22, from sound/pci/hda/hda_intel.c:23: >> sound/pci/hda/hda_intel.c:1182:26: error: 'azx_suspend' undeclared here (not in a function) 1182 | SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume) | ^~~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:308:14: note: in expansion of macro 'pm_sleep_ptr' 308 | .suspend = pm_sleep_ptr(suspend_fn), \ | ^~~~~~~~~~~~ sound/pci/hda/hda_intel.c:1182:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 1182 | SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume) | ^~~~~~~~~~~~~~~~~~~~~~~ >> sound/pci/hda/hda_intel.c:1182:39: error: 'azx_resume' undeclared here (not in a function) 1182 | SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume) | ^~~~~~~~~~ include/linux/kernel.h:41:38: note: in definition of macro 'PTR_IF' 41 | #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) | ^~~ include/linux/pm.h:309:14: note: in expansion of macro 'pm_sleep_ptr' 309 | .resume = pm_sleep_ptr(resume_fn), \ | ^~~~~~~~~~~~ sound/pci/hda/hda_intel.c:1182:2: note: in expansion of macro 'SET_SYSTEM_SLEEP_PM_OPS' 1182 | SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume) | ^~~~~~~~~~~~~~~~~~~~~~~ vim +/azx_suspend +1182 sound/pci/hda/hda_intel.c 6eb827d23577a4 Takashi Iwai 2012-12-12 1180 b8dfc4624162c0 Mengdong Lin 2012-08-23 1181 static const struct dev_pm_ops azx_pm = { b8dfc4624162c0 Mengdong Lin 2012-08-23 @1182 SET_SYSTEM_SLEEP_PM_OPS(azx_suspend, azx_resume) 3e6db33aaf1d42 Xiong Zhang 2015-12-18 1183 #ifdef CONFIG_PM_SLEEP f5dac54d9d9382 Kai-Heng Feng 2020-10-27 1184 .prepare = azx_prepare, f5dac54d9d9382 Kai-Heng Feng 2020-10-27 1185 .complete = azx_complete, 3e6db33aaf1d42 Xiong Zhang 2015-12-18 1186 .freeze_noirq = azx_freeze_noirq, 3e6db33aaf1d42 Xiong Zhang 2015-12-18 1187 .thaw_noirq = azx_thaw_noirq, 3e6db33aaf1d42 Xiong Zhang 2015-12-18 1188 #endif 6eb827d23577a4 Takashi Iwai 2012-12-12 1189 SET_RUNTIME_PM_OPS(azx_runtime_suspend, azx_runtime_resume, azx_runtime_idle) b8dfc4624162c0 Mengdong Lin 2012-08-23 1190 }; b8dfc4624162c0 Mengdong Lin 2012-08-23 1191 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
On Fri, Apr 9, 2021 at 6:30 AM Arnd Bergmann <arnd@arndb.de> wrote: > > On Thu, Apr 8, 2021 at 11:00 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > Drivers typically surround suspend and resume callbacks with #ifdef > > CONFIG_PM(_SLEEP) or mark them as __maybe_unused in order to avoid > > -Wunused-const-variable warnings. > > > > With this commit, drivers will be able to remove #ifdef CONFIG_PM(_SLEEP) > > and __maybe_unsed because unused functions are dropped by the compiler > > instead of the preprocessor. > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > I tried this before and could not get it to work right. > > > > > -#ifdef CONFIG_PM_SLEEP > > +#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), _ptr) > > +#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), _ptr) > > + > > #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ > > - .suspend = suspend_fn, \ > > - .resume = resume_fn, \ > > - .freeze = suspend_fn, \ > > - .thaw = resume_fn, \ > > - .poweroff = suspend_fn, \ > > - .restore = resume_fn, > > -#else > > -#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) > > -#endif > > + .suspend = pm_sleep_ptr(suspend_fn), \ > > + .resume = pm_sleep_ptr(resume_fn), \ > > + .freeze = pm_sleep_ptr(suspend_fn), \ > > + .thaw = pm_sleep_ptr(resume_fn), \ > > + .poweroff = pm_sleep_ptr(suspend_fn), \ > > + .restore = pm_sleep_ptr(resume_fn), > > The problem that I think you inevitably hit is that you run into a missing > declaration for any driver that still uses an #ifdef around a static > function. > > The only way I can see us doing this is to create a new set of > macros that behave like the version you propose here but leave > the old macros in place until the last such #ifdef has been removed. > > Arnd Agh, you are right. We cannot change all the callsites atomically due to the huge amount of users.
diff --git a/include/linux/pm.h b/include/linux/pm.h index 482313a8ccfc..ca764566692a 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -301,50 +301,37 @@ struct dev_pm_ops { int (*runtime_idle)(struct device *dev); }; -#ifdef CONFIG_PM_SLEEP +#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), _ptr) +#define pm_sleep_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM_SLEEP), _ptr) + #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ - .suspend = suspend_fn, \ - .resume = resume_fn, \ - .freeze = suspend_fn, \ - .thaw = resume_fn, \ - .poweroff = suspend_fn, \ - .restore = resume_fn, -#else -#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) -#endif + .suspend = pm_sleep_ptr(suspend_fn), \ + .resume = pm_sleep_ptr(resume_fn), \ + .freeze = pm_sleep_ptr(suspend_fn), \ + .thaw = pm_sleep_ptr(resume_fn), \ + .poweroff = pm_sleep_ptr(suspend_fn), \ + .restore = pm_sleep_ptr(resume_fn), -#ifdef CONFIG_PM_SLEEP #define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ - .suspend_late = suspend_fn, \ - .resume_early = resume_fn, \ - .freeze_late = suspend_fn, \ - .thaw_early = resume_fn, \ - .poweroff_late = suspend_fn, \ - .restore_early = resume_fn, -#else -#define SET_LATE_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) -#endif + .suspend_late = pm_sleep_ptr(suspend_fn), \ + .resume_early = pm_sleep_ptr(resume_fn), \ + .freeze_late = pm_sleep_ptr(suspend_fn), \ + .thaw_early = pm_sleep_ptr(resume_fn), \ + .poweroff_late = pm_sleep_ptr(suspend_fn), \ + .restore_early = pm_sleep_ptr(resume_fn), -#ifdef CONFIG_PM_SLEEP #define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \ - .suspend_noirq = suspend_fn, \ - .resume_noirq = resume_fn, \ - .freeze_noirq = suspend_fn, \ - .thaw_noirq = resume_fn, \ - .poweroff_noirq = suspend_fn, \ - .restore_noirq = resume_fn, -#else -#define SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) -#endif + .suspend_noirq = pm_sleep_ptr(suspend_fn), \ + .resume_noirq = pm_sleep_ptr(resume_fn), \ + .freeze_noirq = pm_sleep_ptr(suspend_fn), \ + .thaw_noirq = pm_sleep_ptr(resume_fn), \ + .poweroff_noirq = pm_sleep_ptr(suspend_fn), \ + .restore_noirq = pm_sleep_ptr(resume_fn), -#ifdef CONFIG_PM #define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ - .runtime_suspend = suspend_fn, \ - .runtime_resume = resume_fn, \ - .runtime_idle = idle_fn, -#else -#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) -#endif + .runtime_suspend = pm_ptr(suspend_fn), \ + .runtime_resume = pm_ptr(resume_fn), \ + .runtime_idle = pm_ptr(idle_fn), /* * Use this if you want to use the same suspend and resume callbacks for suspend @@ -374,12 +361,6 @@ const struct dev_pm_ops __maybe_unused name = { \ SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \ } -#ifdef CONFIG_PM -#define pm_ptr(_ptr) (_ptr) -#else -#define pm_ptr(_ptr) NULL -#endif - /* * PM_EVENT_ messages *
Drivers typically surround suspend and resume callbacks with #ifdef CONFIG_PM(_SLEEP) or mark them as __maybe_unused in order to avoid -Wunused-const-variable warnings. With this commit, drivers will be able to remove #ifdef CONFIG_PM(_SLEEP) and __maybe_unsed because unused functions are dropped by the compiler instead of the preprocessor. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> --- include/linux/pm.h | 67 +++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 43 deletions(-)