diff mbox series

[2/5] PM: core: Redefine pm_ptr() macro

Message ID 20211207002102.26414-3-paul@crapouillou.net (mailing list archive)
State Not Applicable
Headers show
Series Rework pm_ptr() and *_PM_OPS macros | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 17230 this patch: 17230
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 3091 this patch: 3091
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 16668 this patch: 16668
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 12 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Paul Cercueil Dec. 7, 2021, 12:20 a.m. UTC
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>
---
 include/linux/pm.h | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

Comments

Jonathan Cameron Dec. 16, 2021, 11:10 a.m. UTC | #1
On Tue,  7 Dec 2021 00:20:59 +0000
Paul Cercueil <paul@crapouillou.net> wrote:

> 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>

> ---
>  include/linux/pm.h | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/include/linux/pm.h b/include/linux/pm.h
> index 1d8209c09686..b88ac7dcf2a2 100644
> --- a/include/linux/pm.h
> +++ b/include/linux/pm.h
> @@ -373,11 +373,7 @@ 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
> +#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))
>  
>  /*
>   * PM_EVENT_ messages
diff mbox series

Patch

diff --git a/include/linux/pm.h b/include/linux/pm.h
index 1d8209c09686..b88ac7dcf2a2 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -373,11 +373,7 @@  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
+#define pm_ptr(_ptr) PTR_IF(IS_ENABLED(CONFIG_PM), (_ptr))
 
 /*
  * PM_EVENT_ messages