All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/2] ACPI: LPSS: Replace loop with first entry retrieval
@ 2022-08-29 14:11 Andy Shevchenko
  2022-08-29 14:11 ` [PATCH v1 2/2] ACPI: LPSS: Deduplicate skipping device in acpi_lpss_create_device() Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2022-08-29 14:11 UTC (permalink / raw)
  To: linux-acpi, linux-kernel; +Cc: Rafael J. Wysocki, Len Brown, Andy Shevchenko

After the commit 6505e452371d ("ACPI: LPSS: Use the helper
acpi_dev_get_memory_resources()") the list is empty or
contains only resource of IORESOURCE_MEM type. Hence, no
need to check for the type, and since we break after the
first found, no need to iterate over full list. That said,
replace loop with first entry retrieval.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/acpi_lpss.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index 4f6cba8fe8de..c39a0a88f3a3 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -656,16 +656,14 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
 	if (ret < 0)
 		goto err_out;
 
-	list_for_each_entry(rentry, &resource_list, node)
-		if (resource_type(rentry->res) == IORESOURCE_MEM) {
-			if (dev_desc->prv_size_override)
-				pdata->mmio_size = dev_desc->prv_size_override;
-			else
-				pdata->mmio_size = resource_size(rentry->res);
-			pdata->mmio_base = ioremap(rentry->res->start,
-						   pdata->mmio_size);
-			break;
-		}
+	rentry = list_first_entry_or_null(&resource_list, struct resource_entry, node);
+	if (rentry) {
+		if (dev_desc->prv_size_override)
+			pdata->mmio_size = dev_desc->prv_size_override;
+		else
+			pdata->mmio_size = resource_size(rentry->res);
+		pdata->mmio_base = ioremap(rentry->res->start, pdata->mmio_size);
+	}
 
 	acpi_dev_free_resource_list(&resource_list);
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v1 2/2] ACPI: LPSS: Deduplicate skipping device in acpi_lpss_create_device()
  2022-08-29 14:11 [PATCH v1 1/2] ACPI: LPSS: Replace loop with first entry retrieval Andy Shevchenko
@ 2022-08-29 14:11 ` Andy Shevchenko
  2022-09-03 18:49   ` Rafael J. Wysocki
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2022-08-29 14:11 UTC (permalink / raw)
  To: linux-acpi, linux-kernel; +Cc: Rafael J. Wysocki, Len Brown, Andy Shevchenko

Add a new label to deduplicate skipping device code in the
acpi_lpss_create_device(). No functional change intended.

While at it, convert the last conditional to use the classical
pattern, i.e.

	if (err)
		...handle err...

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/acpi/acpi_lpss.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index c39a0a88f3a3..7a73528aa9c2 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -670,9 +670,7 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
 	if (!pdata->mmio_base) {
 		/* Avoid acpi_bus_attach() instantiating a pdev for this dev. */
 		adev->pnp.type.platform_id = 0;
-		/* Skip the device, but continue the namespace scan. */
-		ret = 0;
-		goto err_out;
+		goto out_free;
 	}
 
 	pdata->adev = adev;
@@ -683,11 +681,8 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
 
 	if (dev_desc->flags & LPSS_CLK) {
 		ret = register_device_clock(adev, pdata);
-		if (ret) {
-			/* Skip the device, but continue the namespace scan. */
-			ret = 0;
-			goto err_out;
-		}
+		if (ret)
+			goto out_free;
 	}
 
 	/*
@@ -699,15 +694,19 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
 
 	adev->driver_data = pdata;
 	pdev = acpi_create_platform_device(adev, dev_desc->properties);
-	if (!IS_ERR_OR_NULL(pdev)) {
-		acpi_lpss_create_device_links(adev, pdev);
-		return 1;
+	if (IS_ERR_OR_NULL(pdev)) {
+		adev->driver_data = NULL;
+		ret = PTR_ERR(pdev);
+		goto err_out;
 	}
 
-	ret = PTR_ERR(pdev);
-	adev->driver_data = NULL;
+	acpi_lpss_create_device_links(adev, pdev);
+	return 1;
 
- err_out:
+out_free:
+	/* Skip the device, but continue the namespace scan */
+	ret = 0;
+err_out:
 	kfree(pdata);
 	return ret;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 2/2] ACPI: LPSS: Deduplicate skipping device in acpi_lpss_create_device()
  2022-08-29 14:11 ` [PATCH v1 2/2] ACPI: LPSS: Deduplicate skipping device in acpi_lpss_create_device() Andy Shevchenko
@ 2022-09-03 18:49   ` Rafael J. Wysocki
  0 siblings, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2022-09-03 18:49 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: ACPI Devel Maling List, Linux Kernel Mailing List,
	Rafael J. Wysocki, Len Brown

On Mon, Aug 29, 2022 at 4:11 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> Add a new label to deduplicate skipping device code in the
> acpi_lpss_create_device(). No functional change intended.
>
> While at it, convert the last conditional to use the classical
> pattern, i.e.
>
>         if (err)
>                 ...handle err...
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/acpi/acpi_lpss.c | 27 +++++++++++++--------------
>  1 file changed, 13 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
> index c39a0a88f3a3..7a73528aa9c2 100644
> --- a/drivers/acpi/acpi_lpss.c
> +++ b/drivers/acpi/acpi_lpss.c
> @@ -670,9 +670,7 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
>         if (!pdata->mmio_base) {
>                 /* Avoid acpi_bus_attach() instantiating a pdev for this dev. */
>                 adev->pnp.type.platform_id = 0;
> -               /* Skip the device, but continue the namespace scan. */
> -               ret = 0;
> -               goto err_out;
> +               goto out_free;
>         }
>
>         pdata->adev = adev;
> @@ -683,11 +681,8 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
>
>         if (dev_desc->flags & LPSS_CLK) {
>                 ret = register_device_clock(adev, pdata);
> -               if (ret) {
> -                       /* Skip the device, but continue the namespace scan. */
> -                       ret = 0;
> -                       goto err_out;
> -               }
> +               if (ret)
> +                       goto out_free;
>         }
>
>         /*
> @@ -699,15 +694,19 @@ static int acpi_lpss_create_device(struct acpi_device *adev,
>
>         adev->driver_data = pdata;
>         pdev = acpi_create_platform_device(adev, dev_desc->properties);
> -       if (!IS_ERR_OR_NULL(pdev)) {
> -               acpi_lpss_create_device_links(adev, pdev);
> -               return 1;
> +       if (IS_ERR_OR_NULL(pdev)) {
> +               adev->driver_data = NULL;
> +               ret = PTR_ERR(pdev);
> +               goto err_out;
>         }
>
> -       ret = PTR_ERR(pdev);
> -       adev->driver_data = NULL;
> +       acpi_lpss_create_device_links(adev, pdev);
> +       return 1;
>
> - err_out:
> +out_free:
> +       /* Skip the device, but continue the namespace scan */
> +       ret = 0;
> +err_out:
>         kfree(pdata);
>         return ret;
>  }
> --

Applied along with the [2/2] as 6.1 material, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-03 18:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 14:11 [PATCH v1 1/2] ACPI: LPSS: Replace loop with first entry retrieval Andy Shevchenko
2022-08-29 14:11 ` [PATCH v1 2/2] ACPI: LPSS: Deduplicate skipping device in acpi_lpss_create_device() Andy Shevchenko
2022-09-03 18:49   ` Rafael J. Wysocki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.