Linux-ACPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb
       [not found] <1560534863-15115-1-git-send-email-suzuki.poulose@arm.com>
@ 2019-06-14 17:53 ` Suzuki K Poulose
  2019-06-17 22:08   ` Rafael J. Wysocki
  2019-06-14 17:54 ` [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
  1 sibling, 1 reply; 7+ messages in thread
From: Suzuki K Poulose @ 2019-06-14 17:53 UTC (permalink / raw)
  To: linux-kernel; +Cc: gregkh, rafael, suzuki.poulose, Len Brown, linux-acpi

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.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
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)
 	    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);
 
-- 
2.7.4


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

* [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device
       [not found] <1560534863-15115-1-git-send-email-suzuki.poulose@arm.com>
  2019-06-14 17:53 ` [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb Suzuki K Poulose
@ 2019-06-14 17:54 ` Suzuki K Poulose
  2019-06-17 22:07   ` Rafael J. Wysocki
  1 sibling, 1 reply; 7+ messages in thread
From: Suzuki K Poulose @ 2019-06-14 17:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: gregkh, rafael, suzuki.poulose, Len Brown, linux-acpi, linux-spi,
	Mark Brown

Add a generic helper to match a device by the ACPI_COMPANION device.
This will be later used for providing wrappers for
(bus/class/driver)_find_device().

Cc: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org
Cc: linux-spi@vger.kernel.org
Cc: Mark Brown <broonie@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
 drivers/base/core.c    | 6 ++++++
 include/linux/device.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index b827ca1..597095b 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3346,3 +3346,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
 	return dev->devt == *(dev_t *)pdevt;
 }
 EXPORT_SYMBOL_GPL(device_match_devt);
+
+int device_match_acpi_dev(struct device *dev, const void *adev)
+{
+	return ACPI_COMPANION(dev) == adev;
+}
+EXPORT_SYMBOL(device_match_acpi_dev);
diff --git a/include/linux/device.h b/include/linux/device.h
index f315692..a03b50d 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
 int device_match_of_node(struct device *dev, const void *np);
 int device_match_fwnode(struct device *dev, const void *fwnode);
 int device_match_devt(struct device *dev, const void *pdevt);
+int device_match_acpi_dev(struct device *dev, const void *adev);
 
 int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
 		     int (*fn)(struct device *dev, void *data));
-- 
2.7.4


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

* Re: [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-14 17:54 ` [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
@ 2019-06-17 22:07   ` Rafael J. Wysocki
  2019-06-18  8:38     ` Suzuki K Poulose
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-06-17 22:07 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Linux Kernel Mailing List, Greg Kroah-Hartman, Rafael J. Wysocki,
	Len Brown, ACPI Devel Maling List, linux-spi, Mark Brown

On Fri, Jun 14, 2019 at 7:55 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> Add a generic helper to match a device by the ACPI_COMPANION device.
> This will be later used for providing wrappers for
> (bus/class/driver)_find_device().
>
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Cc: linux-spi@vger.kernel.org
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

Please fold this change into the patch adding users of device_match_acpi_dev().

> ---
>  drivers/base/core.c    | 6 ++++++
>  include/linux/device.h | 1 +
>  2 files changed, 7 insertions(+)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index b827ca1..597095b 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -3346,3 +3346,9 @@ int device_match_devt(struct device *dev, const void *pdevt)
>         return dev->devt == *(dev_t *)pdevt;
>  }
>  EXPORT_SYMBOL_GPL(device_match_devt);
> +
> +int device_match_acpi_dev(struct device *dev, const void *adev)
> +{
> +       return ACPI_COMPANION(dev) == adev;
> +}
> +EXPORT_SYMBOL(device_match_acpi_dev);
> diff --git a/include/linux/device.h b/include/linux/device.h
> index f315692..a03b50d 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -166,6 +166,7 @@ void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
>  int device_match_of_node(struct device *dev, const void *np);
>  int device_match_fwnode(struct device *dev, const void *fwnode);
>  int device_match_devt(struct device *dev, const void *pdevt);
> +int device_match_acpi_dev(struct device *dev, const void *adev);
>
>  int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
>                      int (*fn)(struct device *dev, void *data));
> --
> 2.7.4
>

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

* Re: [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb
  2019-06-14 17:53 ` [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb Suzuki K Poulose
@ 2019-06-17 22:08   ` Rafael J. Wysocki
  2019-06-24  3:20     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-06-17 22:08 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Linux Kernel Mailing List, Greg Kroah-Hartman, Rafael J. Wysocki,
	Len Brown, ACPI Devel Maling List

On Fri, Jun 14, 2019 at 7:54 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> 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.
>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> Cc: Len Brown <lenb@kernel.org>
> Cc: linux-acpi@vger.kernel.org
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>

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

Or if you want me to take this patch, please let me know.

> ---
>  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)
>             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);
>
> --
> 2.7.4
>

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

* Re: [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-17 22:07   ` Rafael J. Wysocki
@ 2019-06-18  8:38     ` Suzuki K Poulose
  2019-06-18  8:40       ` Rafael J. Wysocki
  0 siblings, 1 reply; 7+ messages in thread
From: Suzuki K Poulose @ 2019-06-18  8:38 UTC (permalink / raw)
  To: rafael; +Cc: linux-kernel, gregkh, lenb, linux-acpi, linux-spi, broonie

Hi Rafael,

On 17/06/2019 23:07, Rafael J. Wysocki wrote:
> On Fri, Jun 14, 2019 at 7:55 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>>
>> Add a generic helper to match a device by the ACPI_COMPANION device.
>> This will be later used for providing wrappers for
>> (bus/class/driver)_find_device().
>>
>> Cc: Len Brown <lenb@kernel.org>
>> Cc: linux-acpi@vger.kernel.org
>> Cc: linux-spi@vger.kernel.org
>> Cc: Mark Brown <broonie@kernel.org>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
>> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> Please fold this change into the patch adding users of device_match_acpi_dev().

There are variants of this by class/bus/driver and all of them are introduced
as separate patches with the respective users. If we do for this, we have to
do the same for other matches as well.

i.e, [ device_match_by_attr + class_find_device_by_attr & users + 
driver_find_device_by_attr & users + bus_find_device_by_attr & users ]

And that becomes a large chunk, which could make the review painful.

If you would still like that approach, I could do that in the next revision.

Cheers
Suzuki

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

* Re: [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device
  2019-06-18  8:38     ` Suzuki K Poulose
@ 2019-06-18  8:40       ` Rafael J. Wysocki
  0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki @ 2019-06-18  8:40 UTC (permalink / raw)
  To: Suzuki K Poulose
  Cc: Rafael J. Wysocki, Linux Kernel Mailing List, Greg Kroah-Hartman,
	Len Brown, ACPI Devel Maling List, linux-spi, Mark Brown

On Tue, Jun 18, 2019 at 10:38 AM Suzuki K Poulose
<suzuki.poulose@arm.com> wrote:
>
> Hi Rafael,
>
> On 17/06/2019 23:07, Rafael J. Wysocki wrote:
> > On Fri, Jun 14, 2019 at 7:55 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
> >>
> >> Add a generic helper to match a device by the ACPI_COMPANION device.
> >> This will be later used for providing wrappers for
> >> (bus/class/driver)_find_device().
> >>
> >> Cc: Len Brown <lenb@kernel.org>
> >> Cc: linux-acpi@vger.kernel.org
> >> Cc: linux-spi@vger.kernel.org
> >> Cc: Mark Brown <broonie@kernel.org>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >> Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> >> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> >
> > Please fold this change into the patch adding users of device_match_acpi_dev().
>
> There are variants of this by class/bus/driver and all of them are introduced
> as separate patches with the respective users. If we do for this, we have to
> do the same for other matches as well.
>
> i.e, [ device_match_by_attr + class_find_device_by_attr & users +
> driver_find_device_by_attr & users + bus_find_device_by_attr & users ]
>
> And that becomes a large chunk, which could make the review painful.
>
> If you would still like that approach, I could do that in the next revision.

Yes, please.

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

* Re: [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb
  2019-06-17 22:08   ` Rafael J. Wysocki
@ 2019-06-24  3:20     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 7+ messages in thread
From: Greg Kroah-Hartman @ 2019-06-24  3:20 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Suzuki K Poulose, Linux Kernel Mailing List, Len Brown,
	ACPI Devel Maling List

On Tue, Jun 18, 2019 at 12:08:45AM +0200, Rafael J. Wysocki wrote:
> On Fri, Jun 14, 2019 at 7:54 PM Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
> >
> > 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.
> >
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> > Cc: "Rafael J. Wysocki" <rafael@kernel.org>
> > Cc: Len Brown <lenb@kernel.org>
> > Cc: linux-acpi@vger.kernel.org
> > Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> 
> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> Or if you want me to take this patch, please let me know.

I'll take it now, thanks.

greg k-h

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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1560534863-15115-1-git-send-email-suzuki.poulose@arm.com>
2019-06-14 17:53 ` [PATCH v2 03/28] acpi: utils: Cleanup acpi_dev_match_cb Suzuki K Poulose
2019-06-17 22:08   ` Rafael J. Wysocki
2019-06-24  3:20     ` Greg Kroah-Hartman
2019-06-14 17:54 ` [PATCH v2 09/28] drivers: Add generic match helper by ACPI_COMPANION device Suzuki K Poulose
2019-06-17 22:07   ` Rafael J. Wysocki
2019-06-18  8:38     ` Suzuki K Poulose
2019-06-18  8:40       ` Rafael J. Wysocki

Linux-ACPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \
		linux-acpi@vger.kernel.org linux-acpi@archiver.kernel.org
	public-inbox-index linux-acpi


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi


AGPL code for this site: git clone https://public-inbox.org/ public-inbox