PM/Suspend: Avoid code duplication in suspend statistics update
Subsystems (2)
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.
Suggested-by Srivatsa S. Bhat <[email protected]>
Signed-off-by Marcos Paulo de Souza <[email protected]>
--- 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
@@ -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
@@ -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
@@ -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
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.candkernel/power/suspend.c.This patch just creates a new function to avoid duplicated code.
Suggested-by Srivatsa S. Bhat <[email protected]>Signed-off-by Marcos Paulo de Souza <[email protected]>---
Looks good to me :-)
Acked-by Srivatsa S. Bhat <[email protected]>
Regards,
Srivatsa S. Bhat
Rafael J. Wysocki
AppliedQuoted 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.candkernel/power/suspend.c.This patch just creates a new function to avoid duplicated code.
Quoted 8 lines
Quoted 3 lines
Suggested-by Srivatsa S. Bhat <[email protected]>Signed-off-by Marcos Paulo de Souza <[email protected]>---
Looks good to me :-)
Acked-by Srivatsa S. Bhat <[email protected]>
Applied.
Thanks,
Rafael