From: Andrzej Hajda <a.hajda@samsung.com>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Len Brown <len.brown@intel.com>, Pavel Machek <pavel@ucw.cz>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andrzej Hajda <a.hajda@samsung.com>,
Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Arnd Bergmann <arnd@arndb.de>
Subject: [PATCH] PM / core: refactor PM_OPS initializers
Date: Mon, 14 May 2018 10:21:46 +0200 [thread overview]
Message-ID: <20180514082146.4318-1-a.hajda@samsung.com> (raw)
In-Reply-To: <CGME20180514082201eucas1p1549ae992aeeef0906a2cccb5da96533f@eucas1p1.samsung.com>
With current implementation of PM_OPS initializers users should annotate
all PM callbacks with __maybe_unused attribute to prevent compiler from
complaining in case respective option is not enabled. Using ternary
operator with IS_ENABLED(symbol) as a condition allows to avoid marking
these functions with __maybe_unused.
Solution was tested successfully with multiple versions of gcc since
4.9.4 up to 7.2.1. No functional changes has been observed and callbacks
were compiled out if not used, as before.
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
include/linux/pm.h | 61 ++++++++++++++++++----------------------------
1 file changed, 24 insertions(+), 37 deletions(-)
diff --git a/include/linux/pm.h b/include/linux/pm.h
index e723b78d8357..59f333922c15 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -313,50 +313,37 @@ struct dev_pm_ops {
int (*runtime_idle)(struct device *dev);
};
-#ifdef CONFIG_PM_SLEEP
+#define PM_SLEEP_PTR(ptr) (IS_ENABLED(CONFIG_PM_SLEEP) ? (ptr) : NULL)
+#define PM_PTR(ptr) (IS_ENABLED(CONFIG_PM) ? (ptr) : NULL)
+
#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
--
2.17.0
next parent reply other threads:[~2018-05-14 8:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20180514082201eucas1p1549ae992aeeef0906a2cccb5da96533f@eucas1p1.samsung.com>
2018-05-14 8:21 ` Andrzej Hajda [this message]
2018-05-14 11:51 ` kbuild test robot
2018-05-14 11:51 ` kbuild test robot
2018-05-14 12:07 ` Andrzej Hajda
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=20180514082146.4318-1-a.hajda@samsung.com \
--to=a.hajda@samsung.com \
--cc=arnd@arndb.de \
--cc=b.zolnierkie@samsung.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®