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]
Date:   Sat, 16 Mar 2019 00:59:27 -0400
From:   Yangtao Li <tiny.windzz@...il.com>
To:     rjw@...ysocki.net, len.brown@...el.com, pavel@....cz,
        gregkh@...uxfoundation.org
Cc:     linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org,
        Yangtao Li <tiny.windzz@...il.com>
Subject: [PATCH 3/4] PM / core: Introduce ASYNC_RESUME_FUNC() helper macro

The async_resume_noirq, async_resume_early, async_resume functions
are basically the same. As we have seen:

static void async_xxx(void *data, async_cookie_t cookie)
{
	struct device *dev = (struct device *)data;
	int error;

	error = device_xxx(dev, pm_transition, true);
	if (error)
		pm_dev_err(dev, pm_transition, " async", error);
	put_device(dev);
}

The ASYNC_RESUME_FUNC() helper macro can decrease code duplication.

Signed-off-by: Yangtao Li <tiny.windzz@...il.com>
---
 drivers/base/power/main.c | 46 +++++++++++++--------------------------
 1 file changed, 15 insertions(+), 31 deletions(-)

diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 6026bda5e787..d512bee9d9ca 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -728,18 +728,21 @@ static int __func(struct device *dev) 					\
 	return __device_ ## __name(dev, pm_transition, false);		\
 }
 
-static void async_resume_noirq(void *data, async_cookie_t cookie)
-{
-	struct device *dev = (struct device *)data;
-	int error;
-
-	error = device_resume_noirq(dev, pm_transition, true);
-	if (error)
-		pm_dev_err(dev, pm_transition, " async", error);
-
-	put_device(dev);
+#define ASYNC_RESUME_FUNC(__func, __name)				\
+static void __func(void *data, async_cookie_t cookie)			\
+{									\
+	struct device *dev = (struct device *)data;			\
+	int error;							\
+									\
+	error = device_ ## __name(dev, pm_transition, true);		\
+	if (error)							\
+		pm_dev_err(dev, pm_transition, " async", error);	\
+									\
+	put_device(dev);						\
 }
 
+ASYNC_RESUME_FUNC(async_resume_noirq, resume_noirq);
+
 void dpm_noirq_resume_devices(pm_message_t state)
 {
 	struct device *dev;
@@ -876,17 +879,7 @@ static int device_resume_early(struct device *dev, pm_message_t state, bool asyn
 	return error;
 }
 
-static void async_resume_early(void *data, async_cookie_t cookie)
-{
-	struct device *dev = (struct device *)data;
-	int error;
-
-	error = device_resume_early(dev, pm_transition, true);
-	if (error)
-		pm_dev_err(dev, pm_transition, " async", error);
-
-	put_device(dev);
-}
+ASYNC_RESUME_FUNC(async_resume_early, resume_early);
 
 /**
  * dpm_resume_early - Execute "early resume" callbacks for all devices.
@@ -1035,16 +1028,7 @@ static int device_resume(struct device *dev, pm_message_t state, bool async)
 	return error;
 }
 
-static void async_resume(void *data, async_cookie_t cookie)
-{
-	struct device *dev = (struct device *)data;
-	int error;
-
-	error = device_resume(dev, pm_transition, true);
-	if (error)
-		pm_dev_err(dev, pm_transition, " async", error);
-	put_device(dev);
-}
+ASYNC_RESUME_FUNC(async_resume, resume);
 
 /**
  * dpm_resume - Execute "resume" callbacks for non-sysdev devices.
-- 
2.17.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ