public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] driver core: Simplify driver API device_find_child_by_name() implementation
@ 2024-07-20  1:21 Zijun Hu
  2024-07-31 12:53 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: Zijun Hu @ 2024-07-20  1:21 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki; +Cc: Zijun Hu, linux-kernel, Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

Simplify device_find_child_by_name() implementation by using present
driver APIs device_find_child() and device_match_name().

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/core.c    | 15 +++------------
 include/linux/device.h |  4 ++++
 2 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 730cae66607c..22ab4b8a2bcd 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4089,18 +4089,9 @@ EXPORT_SYMBOL_GPL(device_find_child);
 struct device *device_find_child_by_name(struct device *parent,
 					 const char *name)
 {
-	struct klist_iter i;
-	struct device *child;
-
-	if (!parent)
-		return NULL;
-
-	klist_iter_init(&parent->p->klist_children, &i);
-	while ((child = next_device(&i)))
-		if (sysfs_streq(dev_name(child), name) && get_device(child))
-			break;
-	klist_iter_exit(&i);
-	return child;
+	/* TODO: remove type cast after const device_find_child() prototype */
+	return device_find_child(parent, (void *)name,
+				 (int (*)(struct device *, void *))device_match_name);
 }
 EXPORT_SYMBOL_GPL(device_find_child_by_name);
 
diff --git a/include/linux/device.h b/include/linux/device.h
index 34eb20f5966f..685ffd2dc867 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -47,6 +47,9 @@ struct dev_pin_info;
 struct dev_iommu;
 struct msi_device_data;
 
+/* TODO: unify device match() parameter of driver APIs to this signature */
+typedef int (*device_match_t)(struct device *dev, const void *data);
+
 /**
  * struct subsys_interface - interfaces to device functions
  * @name:       name of the device function
@@ -1073,6 +1076,7 @@ int device_for_each_child(struct device *dev, void *data,
 			  int (*fn)(struct device *dev, void *data));
 int device_for_each_child_reverse(struct device *dev, void *data,
 				  int (*fn)(struct device *dev, void *data));
+/* TODO: change type of @data to const void * and @match to device_match_t */
 struct device *device_find_child(struct device *dev, void *data,
 				 int (*match)(struct device *dev, void *data));
 struct device *device_find_child_by_name(struct device *parent,

---
base-commit: b57d5ffc3ab507d0e19fc8b90b19c76af43fb790
change-id: 20240720-simplify_drv_api-058f9f3584c2

Best regards,
-- 
Zijun Hu <quic_zijuhu@quicinc.com>


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

end of thread, other threads:[~2024-08-01  0:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-20  1:21 [PATCH] driver core: Simplify driver API device_find_child_by_name() implementation Zijun Hu
2024-07-31 12:53 ` Greg Kroah-Hartman
2024-07-31 16:04   ` Zijun Hu
2024-07-31 16:21     ` Greg Kroah-Hartman
2024-08-01  0:08       ` Zijun Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox