From: Marcos Paulo de Souza <marcos.mage@gmail.com>
To: len.brown@intel.com
Cc: pavel@ucw.cz, rjw@sisk.pl, linux-pm@vger.kernel.org,
srivatsa.bhat@linux.vnet.ibm.com, linux-kernel@vger.kernel.org,
Marcos Paulo de Souza <marcos.mage@gmail.com>
Subject: [PATCH] PM/Suspend: Avoid code duplication in suspend statistics update
Date: Wed, 1 Feb 2012 23:39:36 -0200 [thread overview]
Message-ID: <1328146776-1766-1-git-send-email-marcos.mage@gmail.com> (raw)
The code
if (error) {
suspend_stats.fail++;
dpm_save_failed_errno(error);
} else
suspend_stats.success++;
Appears in the kernel/power/main.c and kernel/power/suspend.c.
This patch just creates a new function to avoid duplicated code.
Suggested-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Marcos Paulo de Souza <marcos.mage@gmail.com>
---
include/linux/suspend.h | 16 ++++++++++++++++
kernel/power/main.c | 6 +-----
kernel/power/suspend.c | 6 +-----
3 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 91784a4..313fef1 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -91,6 +91,22 @@ static inline void dpm_save_failed_step(enum suspend_stat_step step)
}
/**
+ * suspend_stats_update - Update success/failure statistics of suspend-to-ram
+ *
+ * @error: Value returned by enter_state() function
+ */
+static inline void suspend_stats_update(int error)
+{
+ if (error) {
+ suspend_stats.fail++;
+ dpm_save_failed_errno(error);
+ } else {
+ suspend_stats.success++;
+ }
+}
+
+
+/**
* struct platform_suspend_ops - Callbacks for managing platform dependent
* system sleep states.
*
diff --git a/kernel/power/main.c b/kernel/power/main.c
index 9824b41e..83947af 100644
--- a/kernel/power/main.c
+++ b/kernel/power/main.c
@@ -292,11 +292,7 @@ static ssize_t state_store(struct kobject *kobj, struct kobj_attribute *attr,
}
if (state < PM_SUSPEND_MAX && *s) {
error = enter_state(state);
- if (error) {
- suspend_stats.fail++;
- dpm_save_failed_errno(error);
- } else
- suspend_stats.success++;
+ suspend_stats_update(error);
}
#endif
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 4fd51be..7fd84b5 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -321,11 +321,7 @@ int pm_suspend(suspend_state_t state)
int ret;
if (state > PM_SUSPEND_ON && state < PM_SUSPEND_MAX) {
ret = enter_state(state);
- if (ret) {
- suspend_stats.fail++;
- dpm_save_failed_errno(ret);
- } else
- suspend_stats.success++;
+ suspend_stats_update(ret);
return ret;
}
return -EINVAL;
--
1.7.7.6
next reply other threads:[~2012-02-02 1:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-02 1:39 Marcos Paulo de Souza [this message]
2012-02-02 1:50 ` Srivatsa S. Bhat
2012-02-02 19:37 ` Rafael J. Wysocki
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=1328146776-1766-1-git-send-email-marcos.mage@gmail.com \
--to=marcos.mage@gmail.com \
--cc=len.brown@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=rjw@sisk.pl \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
/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
Powered by JetHome