lkml.org 
[lkml]   [2008]   [Mar]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH RFC] introduce pm_call() macro to get rid of most #ifdef CONFIG_PM
Currently drivers handle CONFIG_PM this way:

#ifdef CONFIG_PM
drv_suspend() {}
drv_resume() {}
#else
#define drv_suspend NULL
#define drv_resume NULL
#endif

struct driver drv = {
.suspend = drv_suspend,
.resume = drv_resume,
};

With this patch, the code above converts into:

drv_suspend() {}
drv_resume() {}

struct driver drv = {
.suspend = pm_call(drv_suspend),
.resume = pm_call(drv_resume),
};

GCC will optimize away suspend/resume calls if they're really
not used.

Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---
include/linux/pm.h | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/include/linux/pm.h b/include/linux/pm.h
index 015b735..6e0b9c2 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -114,6 +114,13 @@ typedef struct pm_message {
int event;
} pm_message_t;

+#ifdef CONFIG_PM
+#define pm_call(x) (x)
+#else
+/* avoid `defined but not used' warning */
+#define pm_call(x) ((x) - 1 ? NULL : NULL)
+#endif /* CONFIG_PM */
+
/*
* Several driver power state transitions are externally visible, affecting
* the state of pending I/O queues and (for drivers that touch hardware)
--
1.5.4.3

\
 
 \ /
  Last update: 2008-03-03 01:07    [W:0.083 / U:0.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site