diff mbox

[RFC/PATCH,1/3] pm: make PM macros more smart

Message ID 1386911905-2366-2-git-send-email-david.a.cohen@linux.intel.com (mailing list archive)
State RFC, archived
Headers show

Commit Message

David Cohen Dec. 13, 2013, 5:18 a.m. UTC
This patch makes SET_SYSTEM_SLEEP_PM_OPS() and SET_RUNTIME_PM_OPS() more
smart.

Despite those macros check for '#ifdef CONFIG_PM_SLEEP/RUNTIME' to avoid
setting the callbacks when such #ifdef's aren't defined, they don't
handle compiler to avoid messages like that:

drivers/usb/host/xhci-plat.c:200:12: warning: ‘xhci_plat_suspend’ defined but not used [-Wunused-function]
drivers/usb/host/xhci-plat.c:208:12: warning: ‘xhci_plat_resume’ defined but not used [-Wunused-function]

As result, those macros get rid of #ifdef's when setting callbacks but
not when implementing them.

With this patch, drivers using SET_*_PM_OPS() macros don't need to #ifdef
the callbacks implementation as well.

Signed-off-by: David Cohen <david.a.cohen@linux.intel.com>
---
 include/linux/pm.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Pavel Machek Dec. 15, 2013, 5:51 p.m. UTC | #1
On Thu 2013-12-12 21:18:23, David Cohen wrote:
> This patch makes SET_SYSTEM_SLEEP_PM_OPS() and SET_RUNTIME_PM_OPS() more
> smart.
> 
> Despite those macros check for '#ifdef CONFIG_PM_SLEEP/RUNTIME' to avoid
> setting the callbacks when such #ifdef's aren't defined, they don't
> handle compiler to avoid messages like that:
> 
> drivers/usb/host/xhci-plat.c:200:12: warning: ???xhci_plat_suspend??? defined but not used [-Wunused-function]
> drivers/usb/host/xhci-plat.c:208:12: warning: ???xhci_plat_resume??? defined but not used [-Wunused-function]
> 
> As result, those macros get rid of #ifdef's when setting callbacks but
> not when implementing them.
> 
> With this patch, drivers using SET_*_PM_OPS() macros don't need to #ifdef
> the callbacks implementation as well.

Well... Interesting trickery, but it means that resulting kernel
will be bigge due to the dead functions no?

That may be acceptable tradeoff, but I guess its worth discussing...
diff mbox

Patch

diff --git a/include/linux/pm.h b/include/linux/pm.h
index a224c7f5c377..41a0f3b42209 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -299,6 +299,8 @@  struct dev_pm_ops {
 	int (*runtime_idle)(struct device *dev);
 };
 
+#define MAKE_ME_NULL(fn) ((void *)((unsigned long)(fn) - (unsigned long)(fn)))
+
 #ifdef CONFIG_PM_SLEEP
 #define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
 	.suspend = suspend_fn, \
@@ -308,7 +310,9 @@  struct dev_pm_ops {
 	.poweroff = suspend_fn, \
 	.restore = resume_fn,
 #else
-#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn)
+#define SET_SYSTEM_SLEEP_PM_OPS(suspend_fn, resume_fn) \
+	.suspend = MAKE_ME_NULL(suspend_fn), \
+	.resume = MAKE_ME_NULL(resume_fn),
 #endif
 
 #ifdef CONFIG_PM_RUNTIME
@@ -317,7 +321,10 @@  struct dev_pm_ops {
 	.runtime_resume = resume_fn, \
 	.runtime_idle = idle_fn,
 #else
-#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn)
+#define SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn) \
+	.runtime_suspend = MAKE_ME_NULL(suspend_fn), \
+	.runtime_resume = MAKE_ME_NULL(resume_fn), \
+	.runtime_idle = MAKE_ME_NULL(idle_fn),
 #endif
 
 /*