]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
PM: sleep: Rearrange dpm_async_fn() and async state clearing
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 25 Feb 2025 16:39:40 +0000 (17:39 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 3 Mar 2025 13:38:51 +0000 (14:38 +0100)
In preparation for subsequent changes, move the power.completion
reinitialization along with clearing power.work_in_progress into a
separate function called dpm_clear_async_state() and rearrange
dpm_async_fn() to get rid of unnecessary indentation.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://patch.msgid.link/8494650.T7Z3S40VBb@rjwysocki.net
drivers/base/power/main.c

index edf5a4af8b03f7b72fa442ab2e8f847e77c5070c..d240dc352b1f90a536cdf1906c6350b6f5ead5a9 100644 (file)
@@ -599,27 +599,34 @@ static bool is_async(struct device *dev)
 
 static bool dpm_async_fn(struct device *dev, async_func_t func)
 {
-       reinit_completion(&dev->power.completion);
+       if (!is_async(dev))
+               return false;
 
-       if (is_async(dev)) {
-               dev->power.work_in_progress = true;
+       dev->power.work_in_progress = true;
 
-               get_device(dev);
+       get_device(dev);
 
-               if (async_schedule_dev_nocall(func, dev))
-                       return true;
+       if (async_schedule_dev_nocall(func, dev))
+               return true;
+
+       put_device(dev);
 
-               put_device(dev);
-       }
        /*
-        * Because async_schedule_dev_nocall() above has returned false or it
-        * has not been called at all, func() is not running and it is safe to
-        * update the work_in_progress flag without extra synchronization.
+        * async_schedule_dev_nocall() above has returned false, so func() is
+        * not running and it is safe to update power.work_in_progress without
+        * extra synchronization.
         */
        dev->power.work_in_progress = false;
+
        return false;
 }
 
+static void dpm_clear_async_state(struct device *dev)
+{
+       reinit_completion(&dev->power.completion);
+       dev->power.work_in_progress = false;
+}
+
 /**
  * device_resume_noirq - Execute a "noirq resume" callback for given device.
  * @dev: Device to handle.
@@ -729,8 +736,10 @@ static void dpm_noirq_resume_devices(pm_message_t state)
         * Trigger the resume of "async" devices upfront so they don't have to
         * wait for the "non-async" ones they don't depend on.
         */
-       list_for_each_entry(dev, &dpm_noirq_list, power.entry)
+       list_for_each_entry(dev, &dpm_noirq_list, power.entry) {
+               dpm_clear_async_state(dev);
                dpm_async_fn(dev, async_resume_noirq);
+       }
 
        while (!list_empty(&dpm_noirq_list)) {
                dev = to_device(dpm_noirq_list.next);
@@ -869,8 +878,10 @@ void dpm_resume_early(pm_message_t state)
         * Trigger the resume of "async" devices upfront so they don't have to
         * wait for the "non-async" ones they don't depend on.
         */
-       list_for_each_entry(dev, &dpm_late_early_list, power.entry)
+       list_for_each_entry(dev, &dpm_late_early_list, power.entry) {
+               dpm_clear_async_state(dev);
                dpm_async_fn(dev, async_resume_early);
+       }
 
        while (!list_empty(&dpm_late_early_list)) {
                dev = to_device(dpm_late_early_list.next);
@@ -1042,8 +1053,10 @@ void dpm_resume(pm_message_t state)
         * Trigger the resume of "async" devices upfront so they don't have to
         * wait for the "non-async" ones they don't depend on.
         */
-       list_for_each_entry(dev, &dpm_suspended_list, power.entry)
+       list_for_each_entry(dev, &dpm_suspended_list, power.entry) {
+               dpm_clear_async_state(dev);
                dpm_async_fn(dev, async_resume);
+       }
 
        while (!list_empty(&dpm_suspended_list)) {
                dev = to_device(dpm_suspended_list.next);
@@ -1320,6 +1333,7 @@ static int dpm_noirq_suspend_devices(pm_message_t state)
 
                list_move(&dev->power.entry, &dpm_noirq_list);
 
+               dpm_clear_async_state(dev);
                if (dpm_async_fn(dev, async_suspend_noirq))
                        continue;
 
@@ -1497,6 +1511,7 @@ int dpm_suspend_late(pm_message_t state)
 
                list_move(&dev->power.entry, &dpm_late_early_list);
 
+               dpm_clear_async_state(dev);
                if (dpm_async_fn(dev, async_suspend_late))
                        continue;
 
@@ -1764,6 +1779,7 @@ int dpm_suspend(pm_message_t state)
 
                list_move(&dev->power.entry, &dpm_suspended_list);
 
+               dpm_clear_async_state(dev);
                if (dpm_async_fn(dev, async_suspend))
                        continue;