All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-gpio@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Paul Cercueil <paul@crapouillou.net>,
	Masahiro Yamada <masahiroy@kernel.org>,
	Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org
Subject: [PATCH 2/2] pm: allow drivers to drop #ifdef and __maybe_unused from pm callbacks
Date: Fri,  9 Apr 2021 05:58:58 +0900	[thread overview]
Message-ID: <20210408205858.51751-3-masahiroy@kernel.org> (raw)
In-Reply-To: <20210408205858.51751-1-masahiroy@kernel.org>

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

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


  parent reply	other threads:[~2021-04-08 21:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08 20:58 [PATCH 0/2] linux/kconfig.h: move IF_ENABLED() out of <linux/kconfig.h> Masahiro Yamada
2021-04-08 20:58 ` [PATCH 1/2] linux/kconfig.h: replace IF_ENABLED() with PTR_IF() in <linux/kernel.h> Masahiro Yamada
2021-04-09  8:15   ` Paul Cercueil
2021-04-09  8:30     ` Masahiro Yamada
2021-04-09  9:38       ` Paul Cercueil
2021-04-09  9:24   ` Andy Shevchenko
2021-04-10  3:52     ` Masahiro Yamada
2021-04-08 20:58 ` Masahiro Yamada [this message]
2021-04-08 21:29   ` [PATCH 2/2] pm: allow drivers to drop #ifdef and __maybe_unused from pm callbacks Arnd Bergmann
2021-04-09  3:17     ` Masahiro Yamada
2021-04-08 23:49   ` kernel test robot
2021-04-08 23:49     ` kernel test robot
2021-04-08 23:55   ` kernel test robot
2021-04-08 23:55     ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210408205858.51751-3-masahiroy@kernel.org \
    --to=masahiroy@kernel.org \
    --cc=arnd@arndb.de \
    --cc=len.brown@intel.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=paul@crapouillou.net \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.