From: Hongbo Yao yaohongbo@huawei.com
hulk inclusion category: bugfix bugzilla: 26326 CVE: NA
------------------------------------------------- Introduce boolean function system_in_hibernation() returning 'true' when the system carrying out hibernation.
Some device drivers or syscore need such a function to check if it is in the phase of hibernation.
Signed-off-by: Hongbo Yao yaohongbo@huawei.com Reviewed-by: Hanjun Guo guohanjun@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- include/linux/suspend.h | 2 ++ kernel/power/hibernate.c | 11 +++++++++++ 2 files changed, 13 insertions(+)
diff --git a/include/linux/suspend.h b/include/linux/suspend.h index 50e81bf..aff2489 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -414,6 +414,7 @@ static inline void __init register_nosave_region_late(unsigned long b, unsigned extern void hibernation_set_ops(const struct platform_hibernation_ops *ops); extern int hibernate(void); extern bool system_entering_hibernation(void); +extern bool system_in_hibernation(void); extern bool hibernation_available(void); asmlinkage int swsusp_save(void); extern struct pbe *restore_pblist; @@ -427,6 +428,7 @@ static inline void swsusp_unset_page_free(struct page *p) {} static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {} static inline int hibernate(void) { return -ENOSYS; } static inline bool system_entering_hibernation(void) { return false; } +static inline bool system_in_hibernation(void) { return false; } static inline bool hibernation_available(void) { return false; } #endif /* CONFIG_HIBERNATION */
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c index f5ce9f7..72ef9df 100644 --- a/kernel/power/hibernate.c +++ b/kernel/power/hibernate.c @@ -104,6 +104,15 @@ bool system_entering_hibernation(void) } EXPORT_SYMBOL(system_entering_hibernation);
+/* To let some devices or syscore know if system carrying out hibernation*/ +static bool carry_out_hibernation; + +bool system_in_hibernation(void) +{ + return carry_out_hibernation; +} +EXPORT_SYMBOL(system_in_hibernation); + #ifdef CONFIG_PM_DEBUG static void hibernation_debug_sleep(void) { @@ -711,6 +720,7 @@ int hibernate(void) }
pr_info("hibernation entry\n"); + carry_out_hibernation = true; pm_prepare_console(); error = __pm_notifier_call_chain(PM_HIBERNATION_PREPARE, -1, &nr_calls); if (error) { @@ -781,6 +791,7 @@ int hibernate(void) atomic_inc(&snapshot_device_available); Unlock: unlock_system_sleep(); + carry_out_hibernation = false; pr_info("hibernation exit\n");
return error;