PM / Suspend: Avoid code duplication in suspend statistics update
Marcos Paulo de Souza [Sat, 4 Feb 2012 21:26:13 +0000 (22:26 +0100)]
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>
Acked-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

include/linux/suspend.h
kernel/power/main.c
kernel/power/suspend.c

index ac1c114..b901918 100644 (file)
@@ -95,6 +95,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.
  *
index 8c5014a..b1e3248 100644 (file)
@@ -296,11 +296,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
 
index 560a639..03bc92b 100644 (file)
@@ -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;