]> git.baikalelectronics.ru Git - kernel.git/commit
PM: core: Redefine pm_ptr() macro
authorPaul Cercueil <paul@crapouillou.net>
Tue, 7 Dec 2021 00:20:59 +0000 (00:20 +0000)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 17 Dec 2021 15:04:14 +0000 (16:04 +0100)
commit30d4e8120229624473a427bfe44ac6e709c4aaac
treefaa4859074ce3c549812753c428bfd1de92c7e51
parent534f2f84b974ede7e71d4a293f1edc8a0ed86874
PM: core: Redefine pm_ptr() macro

The pm_ptr() macro was previously conditionally defined, according to
the value of the CONFIG_PM option. This meant that the pointed structure
was either referenced (if CONFIG_PM was set), or never referenced (if
CONFIG_PM was not set), causing it to be detected as unused by the
compiler.

This worked fine, but required the __maybe_unused compiler attribute to
be used to every symbol pointed to by a pointer wrapped with pm_ptr().

We can do better. With this change, the pm_ptr() is now defined the
same, independently of the value of CONFIG_PM. It now uses the (?:)
ternary operator to conditionally resolve to its argument. Since the
condition is known at compile time, the compiler will then choose to
discard the unused symbols, which won't need to be tagged with
__maybe_unused anymore.

This pm_ptr() macro is usually used with pointers to dev_pm_ops
structures created with SIMPLE_DEV_PM_OPS() or similar macros. These do
use a __maybe_unused flag, which is now useless with this change, so it
later can be removed. However in the meantime it causes no harm, and all
the drivers still compile fine with the new pm_ptr() macro.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
include/linux/pm.h