diff mbox series

[01/13] acpi: utils: Cleanup acpi_dev_match_cb

Message ID 1559747630-28065-2-git-send-email-suzuki.poulose@arm.com
State Superseded
Headers show
Series [01/13] acpi: utils: Cleanup acpi_dev_match_cb | expand

Commit Message

Suzuki K Poulose June 5, 2019, 3:13 p.m. UTC
acpi_dev_match_cb match function modifies the "data" argument
to pass on a result which could be easily deduced from the result
of the bus_find_device() call at the caller site. Clean this
up in preparation to convert the "match" argument for bus_find_device
to accept a "const" data pointer, similar to class_find_device. This
would allow consolidating the match routines for these two APIs.

Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

---
 drivers/acpi/utils.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

-- 
2.7.4

Comments

Rafael J. Wysocki June 6, 2019, 9:14 a.m. UTC | #1
On Wed, Jun 5, 2019 at 5:14 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>

> acpi_dev_match_cb match function modifies the "data" argument

> to pass on a result which could be easily deduced from the result

> of the bus_find_device() call at the caller site. Clean this

> up in preparation to convert the "match" argument for bus_find_device

> to accept a "const" data pointer, similar to class_find_device. This

> would allow consolidating the match routines for these two APIs.


This changelog can be improved IMO.

In fact, the final goal here is to pass (const void *) as the second
argument to acpi_dev_match_cb() (which you could do right away in this
patch if I'm not mistaken) which is because you want to modify the
prototype of bus_find_device().

So why don't you write something like this in the changelog:

"The prototype of bus_find_device() will be unified with that of
class_find_device() subsequently, but for this purpose the callback
functions passed to it need to take (const void *) as the second
argument.  Consequently, they cannot modify the memory pointed to by
that argument which currently is not the case for acpi_dev_match_cb().
However, acpi_dev_match_cb() really need not modify the "match" object
passed to it, because acpi_dev_get_first_match_dev() which uses it via
bus_find_device() can easily convert the result of bus_find_device()
into the pointer to return.

For this reason, update acpi_dev_match_cb() to avoid the redundant
memory updates and change the type of its second argument to (const
void *)."

>

> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>

> Cc: Len Brown <lenb@kernel.org>

> Cc: linux-acpi@vger.kernel.org

> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

> ---

>  drivers/acpi/utils.c | 7 +------

>  1 file changed, 1 insertion(+), 6 deletions(-)

>

> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c

> index 7def63a..1391b63 100644

> --- a/drivers/acpi/utils.c

> +++ b/drivers/acpi/utils.c

> @@ -725,8 +725,6 @@ bool acpi_dev_found(const char *hid)

>  EXPORT_SYMBOL(acpi_dev_found);

>

>  struct acpi_dev_match_info {

> -       const char *dev_name;

> -       struct acpi_device *adev;

>         struct acpi_device_id hid[2];

>         const char *uid;

>         s64 hrv;

> @@ -746,9 +744,6 @@ static int acpi_dev_match_cb(struct device *dev, void *data)


And why not to change the type of the second arg to "const void *data" here?

>             strcmp(adev->pnp.unique_id, match->uid)))

>                 return 0;

>

> -       match->dev_name = acpi_dev_name(adev);

> -       match->adev = adev;

> -

>         if (match->hrv == -1)

>                 return 1;

>

> @@ -818,7 +813,7 @@ acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)

>         match.hrv = hrv;

>

>         dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);

> -       return dev ? match.adev : NULL;

> +       return dev ? to_acpi_device(dev) : NULL;

>  }

>  EXPORT_SYMBOL(acpi_dev_get_first_match_dev);

>

> --
Suzuki K Poulose June 6, 2019, 9:21 a.m. UTC | #2
Hi Rafael,

On 06/06/2019 10:14, Rafael J. Wysocki wrote:
> On Wed, Jun 5, 2019 at 5:14 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:

>>

>> acpi_dev_match_cb match function modifies the "data" argument

>> to pass on a result which could be easily deduced from the result

>> of the bus_find_device() call at the caller site. Clean this

>> up in preparation to convert the "match" argument for bus_find_device

>> to accept a "const" data pointer, similar to class_find_device. This

>> would allow consolidating the match routines for these two APIs.

> 

> This changelog can be improved IMO.


I agree. Will update it.

> 

> In fact, the final goal here is to pass (const void *) as the second

> argument to acpi_dev_match_cb() (which you could do right away in this

> patch if I'm not mistaken) which is because you want to modify the

> prototype of bus_find_device().

> 

> So why don't you write something like this in the changelog:

> 

> "The prototype of bus_find_device() will be unified with that of

> class_find_device() subsequently, but for this purpose the callback

> functions passed to it need to take (const void *) as the second

> argument.  Consequently, they cannot modify the memory pointed to by

> that argument which currently is not the case for acpi_dev_match_cb().

> However, acpi_dev_match_cb() really need not modify the "match" object

> passed to it, because acpi_dev_get_first_match_dev() which uses it via

> bus_find_device() can easily convert the result of bus_find_device()

> into the pointer to return.


Sure.

> For this reason, update acpi_dev_match_cb() to avoid the redundant

> memory updates and change the type of its second argument to (const

> void *)."


We can't do that quite yet, until we unify the prototype of the
bus_find_device().

>>

>> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>

>> Cc: Len Brown <lenb@kernel.org>

>> Cc: linux-acpi@vger.kernel.org

>> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

>> ---

>>   drivers/acpi/utils.c | 7 +------

>>   1 file changed, 1 insertion(+), 6 deletions(-)

>>

>> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c

>> index 7def63a..1391b63 100644

>> --- a/drivers/acpi/utils.c

>> +++ b/drivers/acpi/utils.c

>> @@ -725,8 +725,6 @@ bool acpi_dev_found(const char *hid)

>>   EXPORT_SYMBOL(acpi_dev_found);

>>

>>   struct acpi_dev_match_info {

>> -       const char *dev_name;

>> -       struct acpi_device *adev;

>>          struct acpi_device_id hid[2];

>>          const char *uid;

>>          s64 hrv;

>> @@ -746,9 +744,6 @@ static int acpi_dev_match_cb(struct device *dev, void *data)

> 

> And why not to change the type of the second arg to "const void *data" here?


Because, that would conflict with what bus_find_device() expects now. We make
the change only later. Since this change was a bit more intrusive than simply
changing the type of the parameter, I kept it as a preparatory patch.

Thanks for the review !

Suzuki
diff mbox series

Patch

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 7def63a..1391b63 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -725,8 +725,6 @@  bool acpi_dev_found(const char *hid)
 EXPORT_SYMBOL(acpi_dev_found);
 
 struct acpi_dev_match_info {
-	const char *dev_name;
-	struct acpi_device *adev;
 	struct acpi_device_id hid[2];
 	const char *uid;
 	s64 hrv;
@@ -746,9 +744,6 @@  static int acpi_dev_match_cb(struct device *dev, void *data)
 	    strcmp(adev->pnp.unique_id, match->uid)))
 		return 0;
 
-	match->dev_name = acpi_dev_name(adev);
-	match->adev = adev;
-
 	if (match->hrv == -1)
 		return 1;
 
@@ -818,7 +813,7 @@  acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv)
 	match.hrv = hrv;
 
 	dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
-	return dev ? match.adev : NULL;
+	return dev ? to_acpi_device(dev) : NULL;
 }
 EXPORT_SYMBOL(acpi_dev_get_first_match_dev);