linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ACPI: scan: Rearrange code related to acpi_get_device_data()
@ 2021-01-18 19:25 Rafael J. Wysocki
  2021-01-20 21:53 ` Hans de Goede
  0 siblings, 1 reply; 2+ messages in thread
From: Rafael J. Wysocki @ 2021-01-18 19:25 UTC (permalink / raw)
  To: Linux ACPI; +Cc: LKML, Hans de Goede

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

There are two callers of acpi_get_device_data(), acpi_bus_get_device()
and acpi_bus_get_acpi_device(), but only one of them takes the int
return value into account.  Moreover, the latter knows that it passes
a valid return pointer to acpi_get_device_data() and it properly
clears that pointer upfront, so it doesn't need acpi_get_device_data()
to do that.

For this reason, rearrange acpi_get_device_data() to return a strct
acpi_device pointer instead of an int and adapt its callers to that.

While at it, rename acpi_get_device_data() to handle_to_device(),
because the old name does not really reflect the functionality
provided by that function.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

On top of https://patchwork.kernel.org/project/linux-acpi/patch/20210115215752.389656-1-hdegoede@redhat.com/

---
 drivers/acpi/scan.c |   35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)

Index: linux-pm/drivers/acpi/scan.c
===================================================================
--- linux-pm.orig/drivers/acpi/scan.c
+++ linux-pm/drivers/acpi/scan.c
@@ -578,29 +578,31 @@ static void acpi_scan_drop_device(acpi_h
 	mutex_unlock(&acpi_device_del_lock);
 }
 
-static int acpi_get_device_data(acpi_handle handle, struct acpi_device **device,
-				void (*callback)(void *))
+static struct acpi_device *handle_to_device(acpi_handle handle,
+					    void (*callback)(void *))
 {
+	struct acpi_device *adev = NULL;
 	acpi_status status;
 
-	if (!device)
-		return -EINVAL;
-
-	*device = NULL;
-
 	status = acpi_get_data_full(handle, acpi_scan_drop_device,
-				    (void **)device, callback);
-	if (ACPI_FAILURE(status) || !*device) {
-		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
-				  handle));
-		return -ENODEV;
+				    (void **)&adev, callback);
+	if (ACPI_FAILURE(status) || !adev) {
+		acpi_handle_debug(handle, "No context!\n");
+		return NULL;
 	}
-	return 0;
+	return adev;
 }
 
 int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
 {
-	return acpi_get_device_data(handle, device, NULL);
+	if (!device)
+		return -EINVAL;
+
+	*device = handle_to_device(handle, NULL);
+	if (!*device)
+		return -ENODEV;
+
+	return 0;
 }
 EXPORT_SYMBOL(acpi_bus_get_device);
 
@@ -612,10 +614,7 @@ static void get_acpi_device(void *dev)
 
 struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
 {
-	struct acpi_device *adev = NULL;
-
-	acpi_get_device_data(handle, &adev, get_acpi_device);
-	return adev;
+	return handle_to_device(handle, get_acpi_device);
 }
 
 void acpi_bus_put_acpi_device(struct acpi_device *adev)




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

* Re: [PATCH] ACPI: scan: Rearrange code related to acpi_get_device_data()
  2021-01-18 19:25 [PATCH] ACPI: scan: Rearrange code related to acpi_get_device_data() Rafael J. Wysocki
@ 2021-01-20 21:53 ` Hans de Goede
  0 siblings, 0 replies; 2+ messages in thread
From: Hans de Goede @ 2021-01-20 21:53 UTC (permalink / raw)
  To: Rafael J. Wysocki, Linux ACPI; +Cc: LKML

Hi,

On 1/18/21 8:25 PM, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> There are two callers of acpi_get_device_data(), acpi_bus_get_device()
> and acpi_bus_get_acpi_device(), but only one of them takes the int
> return value into account.  Moreover, the latter knows that it passes
> a valid return pointer to acpi_get_device_data() and it properly
> clears that pointer upfront, so it doesn't need acpi_get_device_data()
> to do that.
> 
> For this reason, rearrange acpi_get_device_data() to return a strct
> acpi_device pointer instead of an int and adapt its callers to that.
> 
> While at it, rename acpi_get_device_data() to handle_to_device(),
> because the old name does not really reflect the functionality
> provided by that function.
> 
> No intentional functional impact.
> 
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Nice cleanup, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans


> ---
> 
> On top of https://patchwork.kernel.org/project/linux-acpi/patch/20210115215752.389656-1-hdegoede@redhat.com/
> 
> ---
>  drivers/acpi/scan.c |   35 +++++++++++++++++------------------
>  1 file changed, 17 insertions(+), 18 deletions(-)
> 
> Index: linux-pm/drivers/acpi/scan.c
> ===================================================================
> --- linux-pm.orig/drivers/acpi/scan.c
> +++ linux-pm/drivers/acpi/scan.c
> @@ -578,29 +578,31 @@ static void acpi_scan_drop_device(acpi_h
>  	mutex_unlock(&acpi_device_del_lock);
>  }
>  
> -static int acpi_get_device_data(acpi_handle handle, struct acpi_device **device,
> -				void (*callback)(void *))
> +static struct acpi_device *handle_to_device(acpi_handle handle,
> +					    void (*callback)(void *))
>  {
> +	struct acpi_device *adev = NULL;
>  	acpi_status status;
>  
> -	if (!device)
> -		return -EINVAL;
> -
> -	*device = NULL;
> -
>  	status = acpi_get_data_full(handle, acpi_scan_drop_device,
> -				    (void **)device, callback);
> -	if (ACPI_FAILURE(status) || !*device) {
> -		ACPI_DEBUG_PRINT((ACPI_DB_INFO, "No context for object [%p]\n",
> -				  handle));
> -		return -ENODEV;
> +				    (void **)&adev, callback);
> +	if (ACPI_FAILURE(status) || !adev) {
> +		acpi_handle_debug(handle, "No context!\n");
> +		return NULL;
>  	}
> -	return 0;
> +	return adev;
>  }
>  
>  int acpi_bus_get_device(acpi_handle handle, struct acpi_device **device)
>  {
> -	return acpi_get_device_data(handle, device, NULL);
> +	if (!device)
> +		return -EINVAL;
> +
> +	*device = handle_to_device(handle, NULL);
> +	if (!*device)
> +		return -ENODEV;
> +
> +	return 0;
>  }
>  EXPORT_SYMBOL(acpi_bus_get_device);
>  
> @@ -612,10 +614,7 @@ static void get_acpi_device(void *dev)
>  
>  struct acpi_device *acpi_bus_get_acpi_device(acpi_handle handle)
>  {
> -	struct acpi_device *adev = NULL;
> -
> -	acpi_get_device_data(handle, &adev, get_acpi_device);
> -	return adev;
> +	return handle_to_device(handle, get_acpi_device);
>  }
>  
>  void acpi_bus_put_acpi_device(struct acpi_device *adev)
> 
> 
> 


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

end of thread, other threads:[~2021-01-20 22:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18 19:25 [PATCH] ACPI: scan: Rearrange code related to acpi_get_device_data() Rafael J. Wysocki
2021-01-20 21:53 ` Hans de Goede

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).