Skip to contentSkip to conversation

driver core: Provide device_match_acpi_handle() helper

PATCH Superseded Andy Shevchenko 4 participants 8 messages Oct 7, 2021 – Oct 14, 2021

Subsystems (6)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/3 driver core: Provide device_match_acpi_handle() helper

We have couple of users of this helper, make it available for them.

---
v3: no changes

 drivers/base/core.c        | 6 ++++++
 include/linux/device/bus.h | 1 +
 2 files changed, 7 insertions(+)
drivers/base/core.c +6 -0
index b67ebe6a323c..fd034d742447 100644
@@ -4838,6 +4838,12 @@ int device_match_acpi_dev(struct device *dev, const void *adev)
 }
 EXPORT_SYMBOL(device_match_acpi_dev);
 
+int device_match_acpi_handle(struct device *dev, const void *handle)
+{
+	return ACPI_HANDLE(dev) == handle;
+}
+EXPORT_SYMBOL(device_match_acpi_handle);
+
 int device_match_any(struct device *dev, const void *unused)
 {
 	return 1;
include/linux/device/bus.h +1 -0
index 062777a45a74..a039ab809753 100644
@@ -143,6 +143,7 @@ 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 device_match_acpi_handle(struct device *dev, const void *handle);
 int device_match_any(struct device *dev, const void *unused);
 
 /* iterator helpers for buses */
Signature · 1 line
2.33.0
#1 lore raw

PATCH v3 2/3 i2c: acpi: Replace custom function with device_match_acpi_handle()

Since driver core provides a generic device_match_acpi_handle() we may replace the custom one with it. This unifies code to find an adapter with the similar one which finds a client.

---
v3: no changes

 drivers/i2c/i2c-core-acpi.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
drivers/i2c/i2c-core-acpi.c +9 -13
index 7ea2ac712a57..0aea776cd4c9 100644
@@ -398,24 +398,20 @@ u32 i2c_acpi_find_bus_speed(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(i2c_acpi_find_bus_speed);
 
-static int i2c_acpi_find_match_adapter(struct device *dev, const void *data)
-{
-	struct i2c_adapter *adapter = i2c_verify_adapter(dev);
-
-	if (!adapter)
-		return 0;
-
-	return ACPI_HANDLE(dev) == (acpi_handle)data;
-}
-
 struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
 {
+	struct i2c_adapter *adapter;
 	struct device *dev;
 
-	dev = bus_find_device(&i2c_bus_type, NULL, handle,
-			      i2c_acpi_find_match_adapter);
+	dev = bus_find_device(&i2c_bus_type, NULL, handle, device_match_acpi_handle);
+	if (!dev)
+		return NULL;
+
+	adapter = i2c_verify_adapter(dev);
+	if (!adapter)
+		put_device(dev);
 
-	return dev ? i2c_verify_adapter(dev) : NULL;
+	return adapter;
 }
 EXPORT_SYMBOL_GPL(i2c_acpi_find_adapter_by_handle);
 
Signature · 1 line
2.33.0
Acked-by on v3 2/3
#2 lore raw

Re: [PATCH v3 2/3] i2c: acpi: Replace custom function with device_match_acpi_handle()

Quoted 5 lines · Andy Shevchenko

Since driver core provides a generic device_match_acpi_handle() we may replace the custom one with it. This unifies code to find an adapter with the similar one which finds a client.

Fine with me:

#3 lore raw

PATCH v3 3/3 gpiolib: acpi: Replace custom code with device_match_acpi_handle()

In reply to Andy Shevchenko

Since driver core provides a generic device_match_acpi_handle() we may replace the custom code with it.

---
v3: amended the expression (Rafael)

 drivers/gpio/gpiolib-acpi.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/gpio/gpiolib-acpi.c +1 -4
index 47712b6903b5..985e8589c58b 100644
@@ -95,10 +95,7 @@ static bool acpi_gpio_deferred_req_irqs_done;
 
 static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
 {
-	if (!gc->parent)
-		return false;
-
-	return ACPI_HANDLE(gc->parent) == data;
+	return gc->parent && device_match_acpi_handle(gc->parent, data);
 }
 
 /**
Signature · 1 line
2.33.0
#4 lore raw
In reply to Andy Shevchenko
Quoted 2 lines · Andy Shevchenko

We have couple of users of this helper, make it available for them.

"a couple"?

Quoted 13 lines

---
v3: no changes

 drivers/base/core.c        | 6 ++++++
 include/linux/device/bus.h | 1 +
 2 files changed, 7 insertions(+)
drivers/base/core.c +0 -0
index b67ebe6a323c..fd034d742447 100644

drivers/base/core.c int device_match_acpi_dev(struct device *dev, const void *adev) · line 4841

Quoted 4 lines
drivers/base/core.c +1 -0
@@ -4838,6 +4838,12 @@ int device_match_acpi_dev(struct device *dev, const void *adev)
 }
 EXPORT_SYMBOL(device_match_acpi_dev);
 
+int device_match_acpi_handle(struct device *dev, const void *handle)

Hmmm. Should the second arg be of type acpi_handle?

And doesn't this function belong to the ACPI core? It is related to acpi_bus_get_device() and such which are located there.

Quoted 23 lines
drivers/base/core.c +5 -0
+{
+       return ACPI_HANDLE(dev) == handle;
+}
+EXPORT_SYMBOL(device_match_acpi_handle);
+
 int device_match_any(struct device *dev, const void *unused)
 {
        return 1;
include/linux/device/bus.h +1 -1
index 062777a45a74..a039ab809753 100644
@@ -143,6 +143,7 @@ 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 device_match_acpi_handle(struct device *dev, const void *handle);
 int device_match_any(struct device *dev, const void *unused);
 
 /* iterator helpers for buses */
--

2.33.0

#5 lore raw
Quoted 6 lines · Rafael J. Wysocki
Quoted 2 lines · Andy Shevchenko

We have couple of users of this helper, make it available for them.

"a couple"?

Yep.

Quoted 5 lines
Quoted 3 lines

EXPORT_SYMBOL(device_match_acpi_dev);

+int device_match_acpi_handle(struct device *dev, const void *handle)

Hmmm. Should the second arg be of type acpi_handle?

acpi_handle is not defined as struct and it means the header, where the prototype is declared, will require acpi.h to be included. Besides that the whole set of device_match_*() is done by the same prototype, so it can be used in bus_find_device() calls.

Quoted 2 lines

And doesn't this function belong to the ACPI core? It is related to acpi_bus_get_device() and such which are located there.

Same as above. I don't think so.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#6 lore raw
Quoted 13 lines · Andy Shevchenko
Quoted 6 lines · Rafael J. Wysocki
Quoted 2 lines · Andy Shevchenko

We have couple of users of this helper, make it available for them.

"a couple"?

Yep.

Quoted 2 lines
Quoted 2 lines

EXPORT_SYMBOL(device_match_acpi_dev);

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+int device_match_acpi_handle(struct device *dev, const void *handle)

Hmmm. Should the second arg be of type acpi_handle?

acpi_handle is not defined as struct and it means the header, where the prototype is declared, will require acpi.h to be included. Besides that the whole set of device_match_*() is done by the same prototype, so it can be used in bus_find_device() calls.

Ah, OK, it's for bus_find_device().

Quoted 4 lines
Quoted 2 lines

And doesn't this function belong to the ACPI core? It is related to acpi_bus_get_device() and such which are located there.

Same as above. I don't think so.

I see, but any chance to improve the changelog?

#7 lore raw
Quoted 24 lines · Rafael J. Wysocki
Quoted 13 lines · Andy Shevchenko
Quoted 6 lines · Rafael J. Wysocki
Quoted 2 lines · Andy Shevchenko

We have couple of users of this helper, make it available for them.

"a couple"?

Yep.

Quoted 2 lines
Quoted 2 lines

EXPORT_SYMBOL(device_match_acpi_dev);

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+int device_match_acpi_handle(struct device *dev, const void *handle)

Hmmm. Should the second arg be of type acpi_handle?

acpi_handle is not defined as struct and it means the header, where the prototype is declared, will require acpi.h to be included. Besides that the whole set of device_match_*() is done by the same prototype, so it can be used in bus_find_device() calls.

Quoted 8 lines

Ah, OK, it's for bus_find_device().

Quoted 4 lines
Quoted 2 lines

And doesn't this function belong to the ACPI core? It is related to acpi_bus_get_device() and such which are located there.

Same as above. I don't think so.

I see, but any chance to improve the changelog?

I will drop this from my testing tree and wait for a new version with a better changelog.

thanks,

greg k-h