[v3,1/2] freezer: Add processes_frozen()

Message ID 20221127-snd-freeze-v3-1-a2eda731ca14@chromium.org
State New
Headers
Series ALSA: core: Fix deadlock when shutdown a frozen userspace |

Commit Message

Ricardo Ribalda Nov. 28, 2022, 9:10 a.m. UTC
  Add a way to let the drivers know if the processes are frozen.

This is needed by drivers that are waiting for processes to end on their
shutdown path.

Signed-off-by: Ricardo Ribalda <ribalda@chromium.org>
---
 include/linux/freezer.h |  2 ++
 kernel/freezer.c        | 11 +++++++++++
 2 files changed, 13 insertions(+)
  

Patch

diff --git a/include/linux/freezer.h b/include/linux/freezer.h
index b303472255be..ca861ace0689 100644
--- a/include/linux/freezer.h
+++ b/include/linux/freezer.h
@@ -47,6 +47,7 @@  extern int freeze_processes(void);
 extern int freeze_kernel_threads(void);
 extern void thaw_processes(void);
 extern void thaw_kernel_threads(void);
+bool processes_frozen(void);
 
 static inline bool try_to_freeze(void)
 {
@@ -80,6 +81,7 @@  static inline int freeze_processes(void) { return -ENOSYS; }
 static inline int freeze_kernel_threads(void) { return -ENOSYS; }
 static inline void thaw_processes(void) {}
 static inline void thaw_kernel_threads(void) {}
+static inline bool processes_frozen(void) { return false; }
 
 static inline bool try_to_freeze(void) { return false; }
 
diff --git a/kernel/freezer.c b/kernel/freezer.c
index 4fad0e6fca64..08828c4e12fd 100644
--- a/kernel/freezer.c
+++ b/kernel/freezer.c
@@ -233,3 +233,14 @@  bool set_freezable(void)
 	return try_to_freeze();
 }
 EXPORT_SYMBOL(set_freezable);
+
+/**
+ * processes_frozen - Check if the processes are frozen
+ *
+ * Let drivers know if they shall wait for processes.
+ */
+bool processes_frozen(void)
+{
+	return pm_freezing;
+}
+EXPORT_SYMBOL(processes_frozen);