Skip to contentSkip to conversation

PM/Suspend: Avoid code duplication in suspend statistics update

PATCH Applied Marcos Paulo de Souza 3 participants 3 messages Feb 2, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PM/Suspend: Avoid code duplication in suspend statistics update

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.

---
 include/linux/suspend.h |   16 ++++++++++++++++
 kernel/power/main.c     |    6 +-----
 kernel/power/suspend.c  |    6 +-----
 3 files changed, 18 insertions(+), 10 deletions(-)
include/linux/suspend.h +16 -0
index 91784a4..313fef1 100644
@@ -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.
  *
kernel/power/main.c +1 -5
index 9824b41e..83947af 100644
@@ -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
 
kernel/power/suspend.c +1 -5
index 4fd51be..7fd84b5 100644
@@ -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;
Signature · 1 line
1.7.7.6
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Marcos Paulo de Souza

The code

       if (error) {
               suspend_stats.fail++;
               dpm_save_failed_errno(error);
       } else
               suspend_stats.success++;
Quoted 7 lines

Appears in the kernel/power/main.c and kernel/power/suspend.c.

This patch just creates a new function to avoid duplicated code.

---

Looks good to me :-)

Regards,
Srivatsa S. Bhat

#2 lore raw
Quoted 13 lines · Srivatsa S. Bhat
Quoted 11 lines · Marcos Paulo de Souza

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.

Quoted 8 lines
Quoted 3 lines

---

Looks good to me :-)

Applied.

Thanks,
Rafael