diff mbox series

[02/24] PM: hibernate: factor out a helper to find the resume device

Message ID 20230523074535.249802-3-hch@lst.de (mailing list archive)
State Awaiting Upstream, archived
Delegated to: Mike Snitzer
Headers show
Series [01/24] driver core: return bool from driver_probe_done | expand

Commit Message

Christoph Hellwig May 23, 2023, 7:45 a.m. UTC
Split the logic to find the resume device out software_resume and into
a separate helper to start unwindig the convoluted goto logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 kernel/power/hibernate.c | 72 +++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 35 deletions(-)

Comments

Rafael J. Wysocki May 23, 2023, 6:25 p.m. UTC | #1
On Tue, May 23, 2023 at 9:45 AM Christoph Hellwig <hch@lst.de> wrote:
>
> Split the logic to find the resume device out software_resume and into
> a separate helper to start unwindig the convoluted goto logic.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Acked-by: Rafael J. Wysocki <rafael@kernel.org>

> ---
>  kernel/power/hibernate.c | 72 +++++++++++++++++++++-------------------
>  1 file changed, 37 insertions(+), 35 deletions(-)
>
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index 30d1274f03f625..07279506366255 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -910,6 +910,41 @@ int hibernate_quiet_exec(int (*func)(void *data), void *data)
>  }
>  EXPORT_SYMBOL_GPL(hibernate_quiet_exec);
>
> +static int find_resume_device(void)
> +{
> +       if (!strlen(resume_file))
> +               return -ENOENT;
> +
> +       pm_pr_dbg("Checking hibernation image partition %s\n", resume_file);
> +
> +       if (resume_delay) {
> +               pr_info("Waiting %dsec before reading resume device ...\n",
> +                       resume_delay);
> +               ssleep(resume_delay);
> +       }
> +
> +       /* Check if the device is there */
> +       swsusp_resume_device = name_to_dev_t(resume_file);
> +       if (swsusp_resume_device)
> +               return 0;
> +
> +       /*
> +        * Some device discovery might still be in progress; we need to wait for
> +        * this to finish.
> +        */
> +       wait_for_device_probe();
> +       if (resume_wait) {
> +               while (!(swsusp_resume_device = name_to_dev_t(resume_file)))
> +                       msleep(10);
> +               async_synchronize_full();
> +       }
> +
> +       swsusp_resume_device = name_to_dev_t(resume_file);
> +       if (!swsusp_resume_device)
> +               return -ENODEV;
> +       return 0;
> +}
> +
>  /**
>   * software_resume - Resume from a saved hibernation image.
>   *
> @@ -949,45 +984,12 @@ static int software_resume(void)
>
>         snapshot_test = false;
>
> -       if (swsusp_resume_device)
> -               goto Check_image;
> -
> -       if (!strlen(resume_file)) {
> -               error = -ENOENT;
> -               goto Unlock;
> -       }
> -
> -       pm_pr_dbg("Checking hibernation image partition %s\n", resume_file);
> -
> -       if (resume_delay) {
> -               pr_info("Waiting %dsec before reading resume device ...\n",
> -                       resume_delay);
> -               ssleep(resume_delay);
> -       }
> -
> -       /* Check if the device is there */
> -       swsusp_resume_device = name_to_dev_t(resume_file);
>         if (!swsusp_resume_device) {
> -               /*
> -                * Some device discovery might still be in progress; we need
> -                * to wait for this to finish.
> -                */
> -               wait_for_device_probe();
> -
> -               if (resume_wait) {
> -                       while ((swsusp_resume_device = name_to_dev_t(resume_file)) == 0)
> -                               msleep(10);
> -                       async_synchronize_full();
> -               }
> -
> -               swsusp_resume_device = name_to_dev_t(resume_file);
> -               if (!swsusp_resume_device) {
> -                       error = -ENODEV;
> +               error = find_resume_device();
> +               if (error)
>                         goto Unlock;
> -               }
>         }
>
> - Check_image:
>         pm_pr_dbg("Hibernation image partition %d:%d present\n",
>                 MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));
>
> --
> 2.39.2
>

--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
diff mbox series

Patch

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 30d1274f03f625..07279506366255 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -910,6 +910,41 @@  int hibernate_quiet_exec(int (*func)(void *data), void *data)
 }
 EXPORT_SYMBOL_GPL(hibernate_quiet_exec);
 
+static int find_resume_device(void)
+{
+	if (!strlen(resume_file))
+		return -ENOENT;
+
+	pm_pr_dbg("Checking hibernation image partition %s\n", resume_file);
+
+	if (resume_delay) {
+		pr_info("Waiting %dsec before reading resume device ...\n",
+			resume_delay);
+		ssleep(resume_delay);
+	}
+
+	/* Check if the device is there */
+	swsusp_resume_device = name_to_dev_t(resume_file);
+	if (swsusp_resume_device)
+		return 0;
+
+	/*
+	 * Some device discovery might still be in progress; we need to wait for
+	 * this to finish.
+	 */
+	wait_for_device_probe();
+	if (resume_wait) {
+		while (!(swsusp_resume_device = name_to_dev_t(resume_file)))
+			msleep(10);
+		async_synchronize_full();
+	}
+
+	swsusp_resume_device = name_to_dev_t(resume_file);
+	if (!swsusp_resume_device)
+		return -ENODEV;
+	return 0;
+}
+
 /**
  * software_resume - Resume from a saved hibernation image.
  *
@@ -949,45 +984,12 @@  static int software_resume(void)
 
 	snapshot_test = false;
 
-	if (swsusp_resume_device)
-		goto Check_image;
-
-	if (!strlen(resume_file)) {
-		error = -ENOENT;
-		goto Unlock;
-	}
-
-	pm_pr_dbg("Checking hibernation image partition %s\n", resume_file);
-
-	if (resume_delay) {
-		pr_info("Waiting %dsec before reading resume device ...\n",
-			resume_delay);
-		ssleep(resume_delay);
-	}
-
-	/* Check if the device is there */
-	swsusp_resume_device = name_to_dev_t(resume_file);
 	if (!swsusp_resume_device) {
-		/*
-		 * Some device discovery might still be in progress; we need
-		 * to wait for this to finish.
-		 */
-		wait_for_device_probe();
-
-		if (resume_wait) {
-			while ((swsusp_resume_device = name_to_dev_t(resume_file)) == 0)
-				msleep(10);
-			async_synchronize_full();
-		}
-
-		swsusp_resume_device = name_to_dev_t(resume_file);
-		if (!swsusp_resume_device) {
-			error = -ENODEV;
+		error = find_resume_device();
+		if (error)
 			goto Unlock;
-		}
 	}
 
- Check_image:
 	pm_pr_dbg("Hibernation image partition %d:%d present\n",
 		MAJOR(swsusp_resume_device), MINOR(swsusp_resume_device));