lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210408205858.51751-3-masahiroy@kernel.org>
Date:   Fri,  9 Apr 2021 05:58:58 +0900
From:   Masahiro Yamada <masahiroy@...nel.org>
To:     linux-kbuild@...r.kernel.org
Cc:     linux-gpio@...r.kernel.org, Arnd Bergmann <arnd@...db.de>,
        Paul Cercueil <paul@...pouillou.net>,
        Masahiro Yamada <masahiroy@...nel.org>,
        Len Brown <len.brown@...el.com>, Pavel Machek <pavel@....cz>,
        "Rafael J. Wysocki" <rjw@...ysocki.net>,
        linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org
Subject: [PATCH 2/2] pm: allow drivers to drop #ifdef and __maybe_unused from pm callbacks

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@...nel.org>
---

 include/linux/pm.h | 67 +++++++++++++++++-----------------------------
 1 file changed, 24 insertions(+), 43 deletions(-)

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ