netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/11] driver core: Constify API device_find_child()
@ 2024-12-11  0:08 Zijun Hu
  2024-12-11  0:08 ` [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name() Zijun Hu
                   ` (10 more replies)
  0 siblings, 11 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield, Takashi Sakamoto

This patch series is to constify the following API:
struct device *device_find_child(struct device *dev, void *data,
		int (*match)(struct device *dev, void *data));
To :
struct device *device_find_child(struct device *dev, const void *data,
				 device_match_t match);
typedef int (*device_match_t)(struct device *dev, const void *data);

Why to constify the API?

- Protect caller's match data @*data which is for comparison and lookup
  and the API does not actually need to modify @*data.

- Make the API's parameters (@match)() and @data have the same type as
  all of other device finding APIs (bus|class|driver)_find_device().

- All kinds of existing device matching functions can be directly taken
  as the API's argument, they were exported by driver core.

What to do?

- Patches [1/11, 3/11] prepare for constifying the API.

- Patch 4/11 constifies the API and adapt for its various subsystem usages.

- Remaining do cleanup for several usages with benefits brought above.

---
Changes in v4:
- Correct title and commit messages according to review comments
- Link to v3: https://lore.kernel.org/r/20241205-const_dfc_done-v3-0-1611f1486b5a@quicinc.com

Changes in v3:
- Solve build broken issue by squashing changes of various subsystem.
- Reduce recipients to try to send out full patch serial.
- Correct tiles and commit messages.
- Link to v2: https://lore.kernel.org/all/20241203-const_dfc_done-v2-0-7436a98c497f@quicinc.com

Changes in v2:
- Series v1 have no code review comments and are posted a long time ago, so may ignore differences.
- Link to v1: https://lore.kernel.org/r/20240811-const_dfc_done-v1-0-9d85e3f943cb@quicinc.com
- Motivation link: https://lore.kernel.org/lkml/917359cc-a421-41dd-93f4-d28937fe2325@icloud.com

---
Zijun Hu (11):
      libnvdimm: Replace namespace_match() with device_find_child_by_name()
      slimbus: core: Constify slim_eaddr_equal()
      bus: fsl-mc: Constify fsl_mc_device_match()
      driver core: Constify API device_find_child() then adapt for various usages
      driver core: Simplify API device_find_child_by_name() implementation
      driver core: Remove match_any()
      slimbus: core: Remove of_slim_match_dev()
      gpio: sim: Remove gpio_sim_dev_match_fwnode()
      driver core: Introduce an device matching API device_match_type()
      cxl/pmem: Replace match_nvdimm_bridge() with API device_match_type()
      usb: typec: class: Remove both cable_match() and partner_match()

 arch/sparc/kernel/vio.c                |  6 +++---
 drivers/base/core.c                    | 30 ++++++++++--------------------
 drivers/block/sunvdc.c                 |  6 +++---
 drivers/bus/fsl-mc/dprc-driver.c       |  8 ++++----
 drivers/cxl/core/pci.c                 |  4 ++--
 drivers/cxl/core/pmem.c                |  9 +++------
 drivers/cxl/core/region.c              | 21 ++++++++++++---------
 drivers/firewire/core-device.c         |  4 ++--
 drivers/firmware/arm_scmi/bus.c        |  4 ++--
 drivers/firmware/efi/dev-path-parser.c |  4 ++--
 drivers/gpio/gpio-sim.c                |  7 +------
 drivers/gpu/drm/mediatek/mtk_drm_drv.c |  2 +-
 drivers/hwmon/hwmon.c                  |  2 +-
 drivers/media/pci/mgb4/mgb4_core.c     |  4 ++--
 drivers/nvdimm/bus.c                   |  2 +-
 drivers/nvdimm/claim.c                 |  9 +--------
 drivers/pwm/core.c                     |  2 +-
 drivers/rpmsg/rpmsg_core.c             |  4 ++--
 drivers/scsi/qla4xxx/ql4_os.c          |  3 ++-
 drivers/scsi/scsi_transport_iscsi.c    | 10 +++++-----
 drivers/slimbus/core.c                 | 17 +++++------------
 drivers/thunderbolt/retimer.c          |  2 +-
 drivers/thunderbolt/xdomain.c          |  2 +-
 drivers/tty/serial/serial_core.c       |  4 ++--
 drivers/usb/typec/class.c              | 31 ++++++++++++++-----------------
 include/linux/device.h                 |  4 ++--
 include/linux/device/bus.h             |  1 +
 include/scsi/scsi_transport_iscsi.h    |  4 ++--
 net/dsa/dsa.c                          |  2 +-
 tools/testing/cxl/test/cxl.c           |  2 +-
 30 files changed, 90 insertions(+), 120 deletions(-)
---
base-commit: cdd30ebb1b9f36159d66f088b61aee264e649d7a
change-id: 20241201-const_dfc_done-aaec71e3bbea

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


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

* [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:23   ` Jonathan Cameron
  2025-01-02 18:17   ` Fan Ni
  2024-12-11  0:08 ` [PATCH v4 02/11] slimbus: core: Constify slim_eaddr_equal() Zijun Hu
                   ` (9 subsequent siblings)
  10 siblings, 2 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield

From: Zijun Hu <quic_zijuhu@quicinc.com>

Simplify nd_namespace_store() implementation by
using device_find_child_by_name().

Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/nvdimm/claim.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c
index 030dbde6b0882050c90fb8db106ec15b1baef7ca..9e84ab411564f9d5e7ceb687c6491562564552e3 100644
--- a/drivers/nvdimm/claim.c
+++ b/drivers/nvdimm/claim.c
@@ -67,13 +67,6 @@ bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
 	return claimed;
 }
 
-static int namespace_match(struct device *dev, void *data)
-{
-	char *name = data;
-
-	return strcmp(name, dev_name(dev)) == 0;
-}
-
 static bool is_idle(struct device *dev, struct nd_namespace_common *ndns)
 {
 	struct nd_region *nd_region = to_nd_region(dev->parent);
@@ -168,7 +161,7 @@ ssize_t nd_namespace_store(struct device *dev,
 		goto out;
 	}
 
-	found = device_find_child(dev->parent, name, namespace_match);
+	found = device_find_child_by_name(dev->parent, name);
 	if (!found) {
 		dev_dbg(dev, "'%s' not found under %s\n", name,
 				dev_name(dev->parent));

-- 
2.34.1


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

* [PATCH v4 02/11] slimbus: core: Constify slim_eaddr_equal()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
  2024-12-11  0:08 ` [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:25   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 03/11] bus: fsl-mc: Constify fsl_mc_device_match() Zijun Hu
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

bool slim_eaddr_equal(struct slim_eaddr *a, struct slim_eaddr *b)
does not modify @*a or @*b.

Constify it by simply changing its parameter type to
'const struct slim_eaddr *'.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/slimbus/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index 65e5515f7555e2eb840fedaf2dc4cc5d76dbc089..b5d5bbb9fdb6614ffd578f5754226b50e394f0df 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -328,7 +328,8 @@ void slim_report_absent(struct slim_device *sbdev)
 }
 EXPORT_SYMBOL_GPL(slim_report_absent);
 
-static bool slim_eaddr_equal(struct slim_eaddr *a, struct slim_eaddr *b)
+static bool slim_eaddr_equal(const struct slim_eaddr *a,
+			     const struct slim_eaddr *b)
 {
 	return (a->manf_id == b->manf_id &&
 		a->prod_code == b->prod_code &&

-- 
2.34.1


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

* [PATCH v4 03/11] bus: fsl-mc: Constify fsl_mc_device_match()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
  2024-12-11  0:08 ` [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name() Zijun Hu
  2024-12-11  0:08 ` [PATCH v4 02/11] slimbus: core: Constify slim_eaddr_equal() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:26   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages Zijun Hu
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

fsl_mc_device_match() does not modify caller's inputs.

Constify it by simply changing its parameter types to const pointer.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/bus/fsl-mc/dprc-driver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c
index 4b68c84ef485055c9b300b4f7912a20f959b8ac1..11c8fadcf85148b4e4ea6b97b7efb6d4ddf22d3c 100644
--- a/drivers/bus/fsl-mc/dprc-driver.c
+++ b/drivers/bus/fsl-mc/dprc-driver.c
@@ -22,8 +22,8 @@ struct fsl_mc_child_objs {
 	struct fsl_mc_obj_desc *child_array;
 };
 
-static bool fsl_mc_device_match(struct fsl_mc_device *mc_dev,
-				struct fsl_mc_obj_desc *obj_desc)
+static bool fsl_mc_device_match(const struct fsl_mc_device *mc_dev,
+				const struct fsl_mc_obj_desc *obj_desc)
 {
 	return mc_dev->obj_desc.id == obj_desc->id &&
 	       strcmp(mc_dev->obj_desc.type, obj_desc->type) == 0;

-- 
2.34.1


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

* [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (2 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 03/11] bus: fsl-mc: Constify fsl_mc_device_match() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23  7:30   ` Uwe Kleine-König
                     ` (2 more replies)
  2024-12-11  0:08 ` [PATCH v4 05/11] driver core: Simplify API device_find_child_by_name() implementation Zijun Hu
                   ` (6 subsequent siblings)
  10 siblings, 3 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield, Takashi Sakamoto

From: Zijun Hu <quic_zijuhu@quicinc.com>

Constify the following API:
struct device *device_find_child(struct device *dev, void *data,
		int (*match)(struct device *dev, void *data));
To :
struct device *device_find_child(struct device *dev, const void *data,
                                 device_match_t match);
typedef int (*device_match_t)(struct device *dev, const void *data);
with the following reasons:

- Protect caller's match data @*data which is for comparison and lookup
  and the API does not actually need to modify @*data.

- Make the API's parameters (@match)() and @data have the same type as
  all of other device finding APIs (bus|class|driver)_find_device().

- All kinds of existing device match functions can be directly taken
  as the API's argument, they were exported by driver core.

Constify the API and adapt for various existing usages by simply making
various match functions take 'const void *' as type of match data @data.

Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 arch/sparc/kernel/vio.c                |  6 +++---
 drivers/base/core.c                    |  6 +++---
 drivers/block/sunvdc.c                 |  6 +++---
 drivers/bus/fsl-mc/dprc-driver.c       |  4 ++--
 drivers/cxl/core/pci.c                 |  4 ++--
 drivers/cxl/core/pmem.c                |  2 +-
 drivers/cxl/core/region.c              | 21 ++++++++++++---------
 drivers/firewire/core-device.c         |  4 ++--
 drivers/firmware/arm_scmi/bus.c        |  4 ++--
 drivers/firmware/efi/dev-path-parser.c |  4 ++--
 drivers/gpio/gpio-sim.c                |  2 +-
 drivers/gpu/drm/mediatek/mtk_drm_drv.c |  2 +-
 drivers/hwmon/hwmon.c                  |  2 +-
 drivers/media/pci/mgb4/mgb4_core.c     |  4 ++--
 drivers/nvdimm/bus.c                   |  2 +-
 drivers/pwm/core.c                     |  2 +-
 drivers/rpmsg/rpmsg_core.c             |  4 ++--
 drivers/scsi/qla4xxx/ql4_os.c          |  3 ++-
 drivers/scsi/scsi_transport_iscsi.c    | 10 +++++-----
 drivers/slimbus/core.c                 |  8 ++++----
 drivers/thunderbolt/retimer.c          |  2 +-
 drivers/thunderbolt/xdomain.c          |  2 +-
 drivers/tty/serial/serial_core.c       |  4 ++--
 drivers/usb/typec/class.c              |  8 ++++----
 include/linux/device.h                 |  4 ++--
 include/scsi/scsi_transport_iscsi.h    |  4 ++--
 net/dsa/dsa.c                          |  2 +-
 tools/testing/cxl/test/cxl.c           |  2 +-
 28 files changed, 66 insertions(+), 62 deletions(-)

diff --git a/arch/sparc/kernel/vio.c b/arch/sparc/kernel/vio.c
index 07933d75ac815160a2580dce39fde7653a9502e1..1a1a9d6b8f2e8dfedefafde846315a06a167fbfb 100644
--- a/arch/sparc/kernel/vio.c
+++ b/arch/sparc/kernel/vio.c
@@ -419,13 +419,13 @@ struct vio_remove_node_data {
 	u64 node;
 };
 
-static int vio_md_node_match(struct device *dev, void *arg)
+static int vio_md_node_match(struct device *dev, const void *arg)
 {
 	struct vio_dev *vdev = to_vio_dev(dev);
-	struct vio_remove_node_data *node_data;
+	const struct vio_remove_node_data *node_data;
 	u64 node;
 
-	node_data = (struct vio_remove_node_data *)arg;
+	node_data = (const struct vio_remove_node_data *)arg;
 
 	node = vio_vdev_node(node_data->hp, vdev);
 
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 94865c9d8adcf5f2ce5002ffd7bf0ef4fc85e4d7..bc3b523a4a6366080c3c9fd190e54c7fd13c8ded 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4079,8 +4079,8 @@ EXPORT_SYMBOL_GPL(device_for_each_child_reverse_from);
  *
  * NOTE: you will need to drop the reference with put_device() after use.
  */
-struct device *device_find_child(struct device *parent, void *data,
-				 int (*match)(struct device *dev, void *data))
+struct device *device_find_child(struct device *parent, const void *data,
+				 device_match_t match)
 {
 	struct klist_iter i;
 	struct device *child;
@@ -4125,7 +4125,7 @@ struct device *device_find_child_by_name(struct device *parent,
 }
 EXPORT_SYMBOL_GPL(device_find_child_by_name);
 
-static int match_any(struct device *dev, void *unused)
+static int match_any(struct device *dev, const void *unused)
 {
 	return 1;
 }
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index 2d38331ee66793402e803ec0cc82e9e71c991c84..386643ceed59921203828844aa070833c44c67fb 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -918,12 +918,12 @@ struct vdc_check_port_data {
 	char	*type;
 };
 
-static int vdc_device_probed(struct device *dev, void *arg)
+static int vdc_device_probed(struct device *dev, const void *arg)
 {
 	struct vio_dev *vdev = to_vio_dev(dev);
-	struct vdc_check_port_data *port_data;
+	const struct vdc_check_port_data *port_data;
 
-	port_data = (struct vdc_check_port_data *)arg;
+	port_data = (const struct vdc_check_port_data *)arg;
 
 	if ((vdev->dev_no == port_data->dev_no) &&
 	    (!(strcmp((char *)&vdev->type, port_data->type))) &&
diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c
index 11c8fadcf85148b4e4ea6b97b7efb6d4ddf22d3c..52053f7c6d9a654ba46c6579c6a3c5c3faaa75c1 100644
--- a/drivers/bus/fsl-mc/dprc-driver.c
+++ b/drivers/bus/fsl-mc/dprc-driver.c
@@ -112,9 +112,9 @@ void dprc_remove_devices(struct fsl_mc_device *mc_bus_dev,
 }
 EXPORT_SYMBOL_GPL(dprc_remove_devices);
 
-static int __fsl_mc_device_match(struct device *dev, void *data)
+static int __fsl_mc_device_match(struct device *dev, const void *data)
 {
-	struct fsl_mc_obj_desc *obj_desc = data;
+	const struct fsl_mc_obj_desc *obj_desc = data;
 	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
 
 	return fsl_mc_device_match(mc_dev, obj_desc);
diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
index 9d58ab9d33c554e05ddfa2610269e6d08bfaa8e9..a3c57f96138a28c9f30562d554c42cb5224bcf4b 100644
--- a/drivers/cxl/core/pci.c
+++ b/drivers/cxl/core/pci.c
@@ -252,9 +252,9 @@ static int devm_cxl_enable_mem(struct device *host, struct cxl_dev_state *cxlds)
 }
 
 /* require dvsec ranges to be covered by a locked platform window */
-static int dvsec_range_allowed(struct device *dev, void *arg)
+static int dvsec_range_allowed(struct device *dev, const void *arg)
 {
-	struct range *dev_range = arg;
+	const struct range *dev_range = arg;
 	struct cxl_decoder *cxld;
 
 	if (!is_root_decoder(dev))
diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
index b3378d3f6acb4c9e3601683119754e3cd6329df2..a8473de24ebfd92f12f47e0556e28b81a29cff7c 100644
--- a/drivers/cxl/core/pmem.c
+++ b/drivers/cxl/core/pmem.c
@@ -57,7 +57,7 @@ bool is_cxl_nvdimm_bridge(struct device *dev)
 }
 EXPORT_SYMBOL_NS_GPL(is_cxl_nvdimm_bridge, "CXL");
 
-static int match_nvdimm_bridge(struct device *dev, void *data)
+static int match_nvdimm_bridge(struct device *dev, const void *data)
 {
 	return is_cxl_nvdimm_bridge(dev);
 }
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index d778996507984a759bbe84e7acac3774e0c7af98..bfecd71040c2f4373645380b4c31327d8b42d095 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -792,7 +792,7 @@ static int check_commit_order(struct device *dev, const void *data)
 	return 0;
 }
 
-static int match_free_decoder(struct device *dev, void *data)
+static int match_free_decoder(struct device *dev, const void *data)
 {
 	struct cxl_port *port = to_cxl_port(dev->parent);
 	struct cxl_decoder *cxld;
@@ -824,9 +824,9 @@ static int match_free_decoder(struct device *dev, void *data)
 	return 1;
 }
 
-static int match_auto_decoder(struct device *dev, void *data)
+static int match_auto_decoder(struct device *dev, const void *data)
 {
-	struct cxl_region_params *p = data;
+	const struct cxl_region_params *p = data;
 	struct cxl_decoder *cxld;
 	struct range *r;
 
@@ -1722,10 +1722,12 @@ static struct cxl_port *next_port(struct cxl_port *port)
 	return port->parent_dport->port;
 }
 
-static int match_switch_decoder_by_range(struct device *dev, void *data)
+static int match_switch_decoder_by_range(struct device *dev,
+					 const void *data)
 {
 	struct cxl_switch_decoder *cxlsd;
-	struct range *r1, *r2 = data;
+	const struct range *r1, *r2 = data;
+
 
 	if (!is_switch_decoder(dev))
 		return 0;
@@ -3176,9 +3178,10 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
 	return rc;
 }
 
-static int match_root_decoder_by_range(struct device *dev, void *data)
+static int match_root_decoder_by_range(struct device *dev,
+				       const void *data)
 {
-	struct range *r1, *r2 = data;
+	const struct range *r1, *r2 = data;
 	struct cxl_root_decoder *cxlrd;
 
 	if (!is_root_decoder(dev))
@@ -3189,11 +3192,11 @@ static int match_root_decoder_by_range(struct device *dev, void *data)
 	return range_contains(r1, r2);
 }
 
-static int match_region_by_range(struct device *dev, void *data)
+static int match_region_by_range(struct device *dev, const void *data)
 {
 	struct cxl_region_params *p;
 	struct cxl_region *cxlr;
-	struct range *r = data;
+	const struct range *r = data;
 	int rc = 0;
 
 	if (!is_cxl_region(dev))
diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
index a99fe35f1f0d1a2e585ac49b86cc6fd0807cffb6..ec3e21ad202520dda745064b954c853a26d03e3d 100644
--- a/drivers/firewire/core-device.c
+++ b/drivers/firewire/core-device.c
@@ -988,7 +988,7 @@ int fw_device_set_broadcast_channel(struct device *dev, void *gen)
 	return 0;
 }
 
-static int compare_configuration_rom(struct device *dev, void *data)
+static int compare_configuration_rom(struct device *dev, const void *data)
 {
 	const struct fw_device *old = fw_device(dev);
 	const u32 *config_rom = data;
@@ -1039,7 +1039,7 @@ static void fw_device_init(struct work_struct *work)
 	//
 	// serialize config_rom access.
 	scoped_guard(rwsem_read, &fw_device_rwsem) {
-		found = device_find_child(card->device, (void *)device->config_rom,
+		found = device_find_child(card->device, device->config_rom,
 					  compare_configuration_rom);
 	}
 	if (found) {
diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
index 157172a5f2b577ce4f04425f967f548230c1ebed..a3386bf36de508d312e2c4fa2e27ba62ba3776a0 100644
--- a/drivers/firmware/arm_scmi/bus.c
+++ b/drivers/firmware/arm_scmi/bus.c
@@ -238,10 +238,10 @@ static int scmi_dev_match(struct device *dev, const struct device_driver *drv)
 	return 0;
 }
 
-static int scmi_match_by_id_table(struct device *dev, void *data)
+static int scmi_match_by_id_table(struct device *dev, const void *data)
 {
 	struct scmi_device *sdev = to_scmi_dev(dev);
-	struct scmi_device_id *id_table = data;
+	const struct scmi_device_id *id_table = data;
 
 	return sdev->protocol_id == id_table->protocol_id &&
 		(id_table->name && !strcmp(sdev->name, id_table->name));
diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c
index 937be269fee86d5d71256758aed94741e794431c..13ea141c0defb5e80d5af43cca73cf527444a238 100644
--- a/drivers/firmware/efi/dev-path-parser.c
+++ b/drivers/firmware/efi/dev-path-parser.c
@@ -47,9 +47,9 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
 	return 0;
 }
 
-static int __init match_pci_dev(struct device *dev, void *data)
+static int __init match_pci_dev(struct device *dev, const void *data)
 {
-	unsigned int devfn = *(unsigned int *)data;
+	unsigned int devfn = *(const unsigned int *)data;
 
 	return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn;
 }
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index f387dad81f2960b5ec3c1b5fd04081ee501cc75b..370b71513bdb529112e157fa22a5451e02502a17 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -413,7 +413,7 @@ static int gpio_sim_setup_sysfs(struct gpio_sim_chip *chip)
 	return devm_add_action_or_reset(dev, gpio_sim_sysfs_remove, chip);
 }
 
-static int gpio_sim_dev_match_fwnode(struct device *dev, void *data)
+static int gpio_sim_dev_match_fwnode(struct device *dev, const void *data)
 {
 	return device_match_fwnode(dev, data);
 }
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 0829ceb9967ca5d03509c52a559494d58776077b..4aeb393b58e636225ba3b529e4529f3028219e62 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -359,7 +359,7 @@ static const struct of_device_id mtk_drm_of_ids[] = {
 };
 MODULE_DEVICE_TABLE(of, mtk_drm_of_ids);
 
-static int mtk_drm_match(struct device *dev, void *data)
+static int mtk_drm_match(struct device *dev, const void *data)
 {
 	if (!strncmp(dev_name(dev), "mediatek-drm", sizeof("mediatek-drm") - 1))
 		return true;
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index bbb9cc44e29fbc635706db5bed21f3b8a1cd4987..6552ee5186896e9290658a26d8f230849aacafa6 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -341,7 +341,7 @@ static int hwmon_attr_base(enum hwmon_sensor_types type)
 
 static DEFINE_MUTEX(hwmon_pec_mutex);
 
-static int hwmon_match_device(struct device *dev, void *data)
+static int hwmon_match_device(struct device *dev, const void *data)
 {
 	return dev->class == &hwmon_class;
 }
diff --git a/drivers/media/pci/mgb4/mgb4_core.c b/drivers/media/pci/mgb4/mgb4_core.c
index bc63dc81bcae0d20924174be74b93a2139d5879f..697d50bedfe285d74c702efde61e510df87c1229 100644
--- a/drivers/media/pci/mgb4/mgb4_core.c
+++ b/drivers/media/pci/mgb4/mgb4_core.c
@@ -123,7 +123,7 @@ static const struct hwmon_chip_info temp_chip_info = {
 };
 #endif
 
-static int match_i2c_adap(struct device *dev, void *data)
+static int match_i2c_adap(struct device *dev, const void *data)
 {
 	return i2c_verify_adapter(dev) ? 1 : 0;
 }
@@ -139,7 +139,7 @@ static struct i2c_adapter *get_i2c_adap(struct platform_device *pdev)
 	return dev ? to_i2c_adapter(dev) : NULL;
 }
 
-static int match_spi_adap(struct device *dev, void *data)
+static int match_spi_adap(struct device *dev, const void *data)
 {
 	return to_spi_device(dev) ? 1 : 0;
 }
diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
index 2237715e42eb32a14a4134746739a0df5ca27414..0ccf4a9e523a52ef52a96a339ecff0bcb51b214b 100644
--- a/drivers/nvdimm/bus.c
+++ b/drivers/nvdimm/bus.c
@@ -1212,7 +1212,7 @@ enum nd_ioctl_mode {
 	DIMM_IOCTL,
 };
 
-static int match_dimm(struct device *dev, void *data)
+static int match_dimm(struct device *dev, const void *data)
 {
 	long id = (long) data;
 
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index 675b252d9c8ce74705ef245faae42e2c1330ed15..14144d0fa38e0c4e0bc34b9c929e127f1b2e96b6 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -1276,7 +1276,7 @@ static int pwm_export_child(struct device *pwmchip_dev, struct pwm_device *pwm)
 	return 0;
 }
 
-static int pwm_unexport_match(struct device *pwm_dev, void *data)
+static int pwm_unexport_match(struct device *pwm_dev, const void *data)
 {
 	return pwm_from_dev(pwm_dev) == data;
 }
diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
index 712c06c02696663821c8c884bcbd83036098899b..207b64c0a2fe9ccdb03b4ed66d1cee81e6f4c1ae 100644
--- a/drivers/rpmsg/rpmsg_core.c
+++ b/drivers/rpmsg/rpmsg_core.c
@@ -377,9 +377,9 @@ EXPORT_SYMBOL(rpmsg_get_mtu);
  * this is used to make sure we're not creating rpmsg devices for channels
  * that already exist.
  */
-static int rpmsg_device_match(struct device *dev, void *data)
+static int rpmsg_device_match(struct device *dev, const void *data)
 {
-	struct rpmsg_channel_info *chinfo = data;
+	const struct rpmsg_channel_info *chinfo = data;
 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
 
 	if (chinfo->src != RPMSG_ADDR_ANY && chinfo->src != rpdev->src)
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index d91f54a6e752f2feb68da69f474375f1415f33a2..133f36457b283a53b4dca29adf081f385a371368 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -7189,7 +7189,8 @@ static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
  *	1: if flashnode entry is non-persistent
  *	0: if flashnode entry is persistent
  **/
-static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
+static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev,
+					       const void *data)
 {
 	struct iscsi_bus_flash_session *fnode_sess;
 
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index fde7de3b1e55381f7cd468ad308a3e4ee9417c8c..0d474de2d960a865c52c9e7253f173d70ddd8f16 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -1324,7 +1324,7 @@ EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
  *  1 on success
  *  0 on failure
  */
-static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)
+static int iscsi_is_flashnode_conn_dev(struct device *dev, const void *data)
 {
 	return dev->bus == &iscsi_flashnode_bus;
 }
@@ -1335,7 +1335,7 @@ static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn)
 	return 0;
 }
 
-static int flashnode_match_index(struct device *dev, void *data)
+static int flashnode_match_index(struct device *dev, const void *data)
 {
 	struct iscsi_bus_flash_session *fnode_sess = NULL;
 	int ret = 0;
@@ -1344,7 +1344,7 @@ static int flashnode_match_index(struct device *dev, void *data)
 		goto exit_match_index;
 
 	fnode_sess = iscsi_dev_to_flash_session(dev);
-	ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0;
+	ret = (fnode_sess->target_id == *((const int *)data)) ? 1 : 0;
 
 exit_match_index:
 	return ret;
@@ -1389,8 +1389,8 @@ iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
  *  %NULL on failure
  */
 struct device *
-iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
-			  int (*fn)(struct device *dev, void *data))
+iscsi_find_flashnode_sess(struct Scsi_Host *shost, const void *data,
+			  device_match_t fn)
 {
 	return device_find_child(&shost->shost_gendev, data, fn);
 }
diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index b5d5bbb9fdb6614ffd578f5754226b50e394f0df..ab927fd077cb4fe1e29c004269fe52b2896c302f 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -337,9 +337,9 @@ static bool slim_eaddr_equal(const struct slim_eaddr *a,
 		a->instance == b->instance);
 }
 
-static int slim_match_dev(struct device *dev, void *data)
+static int slim_match_dev(struct device *dev, const void *data)
 {
-	struct slim_eaddr *e_addr = data;
+	const struct slim_eaddr *e_addr = data;
 	struct slim_device *sbdev = to_slim_device(dev);
 
 	return slim_eaddr_equal(&sbdev->e_addr, e_addr);
@@ -385,9 +385,9 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl,
 }
 EXPORT_SYMBOL_GPL(slim_get_device);
 
-static int of_slim_match_dev(struct device *dev, void *data)
+static int of_slim_match_dev(struct device *dev, const void *data)
 {
-	struct device_node *np = data;
+	const struct device_node *np = data;
 	struct slim_device *sbdev = to_slim_device(dev);
 
 	return (sbdev->dev.of_node == np);
diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c
index 89d2919d0193e8f5c68e669d054f3efc7abf78c8..21d2902c6102f0f593fb0c6d645acaff31ebb274 100644
--- a/drivers/thunderbolt/retimer.c
+++ b/drivers/thunderbolt/retimer.c
@@ -461,7 +461,7 @@ struct tb_retimer_lookup {
 	u8 index;
 };
 
-static int retimer_match(struct device *dev, void *data)
+static int retimer_match(struct device *dev, const void *data)
 {
 	const struct tb_retimer_lookup *lookup = data;
 	struct tb_retimer *rt = tb_to_retimer(dev);
diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
index 11a50c86a1e4302968f44dafeab47977bac01dd5..b0630e6d94726f9069c20017876ec7e212071686 100644
--- a/drivers/thunderbolt/xdomain.c
+++ b/drivers/thunderbolt/xdomain.c
@@ -1026,7 +1026,7 @@ static int remove_missing_service(struct device *dev, void *data)
 	return 0;
 }
 
-static int find_service(struct device *dev, void *data)
+static int find_service(struct device *dev, const void *data)
 {
 	const struct tb_property *p = data;
 	struct tb_service *svc;
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 74fa02b237729931928b2ae4902c699ec017af94..8e0aa2c76d4037047a16f6c631eccaa066d8f230 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -2365,9 +2365,9 @@ struct uart_match {
 	struct uart_driver *driver;
 };
 
-static int serial_match_port(struct device *dev, void *data)
+static int serial_match_port(struct device *dev, const void *data)
 {
-	struct uart_match *match = data;
+	const struct uart_match *match = data;
 	struct tty_driver *tty_drv = match->driver->tty_driver;
 	dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
 		match->port->line;
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 4b3047e055a3737d3eb841e00fc976a70f8c9c3e..601a81aa1e1024265f2359393dee531a7779c6ea 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -229,10 +229,10 @@ static const char * const usb_modes[] = {
 /* ------------------------------------------------------------------------- */
 /* Alternate Modes */
 
-static int altmode_match(struct device *dev, void *data)
+static int altmode_match(struct device *dev, const void *data)
 {
 	struct typec_altmode *adev = to_typec_altmode(dev);
-	struct typec_device_id *id = data;
+	const struct typec_device_id *id = data;
 
 	if (!is_typec_altmode(dev))
 		return 0;
@@ -1282,7 +1282,7 @@ const struct device_type typec_cable_dev_type = {
 	.release = typec_cable_release,
 };
 
-static int cable_match(struct device *dev, void *data)
+static int cable_match(struct device *dev, const void *data)
 {
 	return is_typec_cable(dev);
 }
@@ -2028,7 +2028,7 @@ const struct device_type typec_port_dev_type = {
 /* --------------------------------------- */
 /* Driver callbacks to report role updates */
 
-static int partner_match(struct device *dev, void *data)
+static int partner_match(struct device *dev, const void *data)
 {
 	return is_typec_partner(dev);
 }
diff --git a/include/linux/device.h b/include/linux/device.h
index 667cb6db9019349c9db0233acf9e78ff6a6d9625..0e0bc9bfe0d15a8734bf3d34106300f4df6b5364 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1081,8 +1081,8 @@ int device_for_each_child_reverse(struct device *dev, void *data,
 int device_for_each_child_reverse_from(struct device *parent,
 				       struct device *from, const void *data,
 				       int (*fn)(struct device *, const void *));
-struct device *device_find_child(struct device *dev, void *data,
-				 int (*match)(struct device *dev, void *data));
+struct device *device_find_child(struct device *dev, const void *data,
+				 device_match_t match);
 struct device *device_find_child_by_name(struct device *parent,
 					 const char *name);
 struct device *device_find_any_child(struct device *parent);
diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
index bd1243657c019962853849b07fc2ae190ec3b557..4d3baf324900f4b2b1ff3a5724b7ca7d122dc468 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -497,8 +497,8 @@ extern void iscsi_destroy_all_flashnode(struct Scsi_Host *shost);
 extern int iscsi_flashnode_bus_match(struct device *dev,
 				     const struct device_driver *drv);
 extern struct device *
-iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
-			  int (*fn)(struct device *dev, void *data));
+iscsi_find_flashnode_sess(struct Scsi_Host *shost, const void *data,
+			  device_match_t fn);
 extern struct device *
 iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess);
 
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 5a7c0e565a894545ee14f0e0186ed3c46b809b16..e827775baf2ee1d0e1c0ce5807c2cca5c372fc75 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -1367,7 +1367,7 @@ static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn)
 	return dsa_switch_parse_ports_of(ds, dn);
 }
 
-static int dev_is_class(struct device *dev, void *class)
+static int dev_is_class(struct device *dev, const void *class)
 {
 	if (dev->class != NULL && !strcmp(dev->class->name, class))
 		return 1;
diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
index d0337c11f9ee675b0c461c8ae28e50957dc644ce..cc8948f49117a98086b3ef2ea7a8de0ce1ec36a5 100644
--- a/tools/testing/cxl/test/cxl.c
+++ b/tools/testing/cxl/test/cxl.c
@@ -725,7 +725,7 @@ static void default_mock_decoder(struct cxl_decoder *cxld)
 	cxld->reset = mock_decoder_reset;
 }
 
-static int first_decoder(struct device *dev, void *data)
+static int first_decoder(struct device *dev, const void *data)
 {
 	struct cxl_decoder *cxld;
 

-- 
2.34.1


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

* [PATCH v4 05/11] driver core: Simplify API device_find_child_by_name() implementation
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (3 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:39   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 06/11] driver core: Remove match_any() Zijun Hu
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

Simplify device_find_child_by_name() implementation by both existing
API device_find_child() and device_match_name().

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/core.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index bc3b523a4a6366080c3c9fd190e54c7fd13c8ded..8116bc8dd6e9eba0653ca686a90c7008de9e2840 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4110,18 +4110,7 @@ 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;
+	return device_find_child(parent, name, device_match_name);
 }
 EXPORT_SYMBOL_GPL(device_find_child_by_name);
 

-- 
2.34.1


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

* [PATCH v4 06/11] driver core: Remove match_any()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (4 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 05/11] driver core: Simplify API device_find_child_by_name() implementation Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:40   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 07/11] slimbus: core: Remove of_slim_match_dev() Zijun Hu
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

Static match_any() is exactly same as API device_match_any().
Remove the former and use the later instead.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 8116bc8dd6e9eba0653ca686a90c7008de9e2840..289f2dafa8f3831931d0f316d66ee12c2cb8a2e1 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -4114,11 +4114,6 @@ struct device *device_find_child_by_name(struct device *parent,
 }
 EXPORT_SYMBOL_GPL(device_find_child_by_name);
 
-static int match_any(struct device *dev, const void *unused)
-{
-	return 1;
-}
-
 /**
  * device_find_any_child - device iterator for locating a child device, if any.
  * @parent: parent struct device
@@ -4130,7 +4125,7 @@ static int match_any(struct device *dev, const void *unused)
  */
 struct device *device_find_any_child(struct device *parent)
 {
-	return device_find_child(parent, NULL, match_any);
+	return device_find_child(parent, NULL, device_match_any);
 }
 EXPORT_SYMBOL_GPL(device_find_any_child);
 

-- 
2.34.1


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

* [PATCH v4 07/11] slimbus: core: Remove of_slim_match_dev()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (5 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 06/11] driver core: Remove match_any() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:44   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode() Zijun Hu
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

static of_slim_match_dev() has same function as API device_match_of_node().

Remove the former and use the later instead.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/slimbus/core.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
index ab927fd077cb4fe1e29c004269fe52b2896c302f..005fa2ef100f526df5603d212b6334c06a366c94 100644
--- a/drivers/slimbus/core.c
+++ b/drivers/slimbus/core.c
@@ -385,21 +385,13 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl,
 }
 EXPORT_SYMBOL_GPL(slim_get_device);
 
-static int of_slim_match_dev(struct device *dev, const void *data)
-{
-	const struct device_node *np = data;
-	struct slim_device *sbdev = to_slim_device(dev);
-
-	return (sbdev->dev.of_node == np);
-}
-
 static struct slim_device *of_find_slim_device(struct slim_controller *ctrl,
 					       struct device_node *np)
 {
 	struct slim_device *sbdev;
 	struct device *dev;
 
-	dev = device_find_child(ctrl->dev, np, of_slim_match_dev);
+	dev = device_find_child(ctrl->dev, np, device_match_of_node);
 	if (dev) {
 		sbdev = to_slim_device(dev);
 		return sbdev;

-- 
2.34.1


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

* [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (6 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 07/11] slimbus: core: Remove of_slim_match_dev() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-11  8:18   ` Bartosz Golaszewski
  2024-12-23 20:45   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 09/11] driver core: Introduce an device matching API device_match_type() Zijun Hu
                   ` (2 subsequent siblings)
  10 siblings, 2 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

gpio_sim_dev_match_fwnode() is a simple wrapper of API
device_match_fwnode().

Remove the needless wrapper and use the API instead.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/gpio/gpio-sim.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 370b71513bdb529112e157fa22a5451e02502a17..b1f33cbaaaa78aca324f99c45a868e7e79a9d672 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -413,11 +413,6 @@ static int gpio_sim_setup_sysfs(struct gpio_sim_chip *chip)
 	return devm_add_action_or_reset(dev, gpio_sim_sysfs_remove, chip);
 }
 
-static int gpio_sim_dev_match_fwnode(struct device *dev, const void *data)
-{
-	return device_match_fwnode(dev, data);
-}
-
 static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
 {
 	struct gpio_sim_chip *chip;
@@ -503,7 +498,7 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
 	if (ret)
 		return ret;
 
-	chip->dev = device_find_child(dev, swnode, gpio_sim_dev_match_fwnode);
+	chip->dev = device_find_child(dev, swnode, device_match_fwnode);
 	if (!chip->dev)
 		return -ENODEV;
 

-- 
2.34.1


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

* [PATCH v4 09/11] driver core: Introduce an device matching API device_match_type()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (7 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:46   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 10/11] cxl/pmem: Replace match_nvdimm_bridge() with " Zijun Hu
  2024-12-11  0:08 ` [PATCH v4 11/11] usb: typec: class: Remove both cable_match() and partner_match() Zijun Hu
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

Introduce device_match_type() for purposes below:

- Test if a device matches with a specified device type.
- As argument of various device finding APIs to find a device with
  specified type.

device_find_child() will use it to simplify operations later.

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

diff --git a/drivers/base/core.c b/drivers/base/core.c
index 289f2dafa8f3831931d0f316d66ee12c2cb8a2e1..8bdbc9e657e832a063542391426f570ccb5c18b9 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -5228,6 +5228,12 @@ int device_match_name(struct device *dev, const void *name)
 }
 EXPORT_SYMBOL_GPL(device_match_name);
 
+int device_match_type(struct device *dev, const void *type)
+{
+	return dev->type == type;
+}
+EXPORT_SYMBOL_GPL(device_match_type);
+
 int device_match_of_node(struct device *dev, const void *np)
 {
 	return dev->of_node == np;
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
index cdc4757217f9bb4b36b5c3b8a48bab45737e44c5..bc3fd74bb763e6d2d862859bd2ec3f0d443f2d7a 100644
--- a/include/linux/device/bus.h
+++ b/include/linux/device/bus.h
@@ -131,6 +131,7 @@ typedef int (*device_match_t)(struct device *dev, const void *data);
 
 /* Generic device matching functions that all busses can use to match with */
 int device_match_name(struct device *dev, const void *name);
+int device_match_type(struct device *dev, const void *type);
 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);

-- 
2.34.1


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

* [PATCH v4 10/11] cxl/pmem: Replace match_nvdimm_bridge() with API device_match_type()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (8 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 09/11] driver core: Introduce an device matching API device_match_type() Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:48   ` Jonathan Cameron
  2024-12-11  0:08 ` [PATCH v4 11/11] usb: typec: class: Remove both cable_match() and partner_match() Zijun Hu
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield

From: Zijun Hu <quic_zijuhu@quicinc.com>

Static match_nvdimm_bridge(), as matching function of device_find_child()
matches a device with device type @cxl_nvdimm_bridge_type, and its task
can be simplified by the recently introduced API device_match_type().

Replace match_nvdimm_bridge() usage with device_match_type().

Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/cxl/core/pmem.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
index a8473de24ebfd92f12f47e0556e28b81a29cff7c..0f8166e793e14fc0b1c04ffda79e756a743d9e6b 100644
--- a/drivers/cxl/core/pmem.c
+++ b/drivers/cxl/core/pmem.c
@@ -57,11 +57,6 @@ bool is_cxl_nvdimm_bridge(struct device *dev)
 }
 EXPORT_SYMBOL_NS_GPL(is_cxl_nvdimm_bridge, "CXL");
 
-static int match_nvdimm_bridge(struct device *dev, const void *data)
-{
-	return is_cxl_nvdimm_bridge(dev);
-}
-
 /**
  * cxl_find_nvdimm_bridge() - find a bridge device relative to a port
  * @port: any descendant port of an nvdimm-bridge associated
@@ -75,7 +70,9 @@ struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port)
 	if (!cxl_root)
 		return NULL;
 
-	dev = device_find_child(&cxl_root->port.dev, NULL, match_nvdimm_bridge);
+	dev = device_find_child(&cxl_root->port.dev,
+				&cxl_nvdimm_bridge_type,
+				device_match_type);
 
 	if (!dev)
 		return NULL;

-- 
2.34.1


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

* [PATCH v4 11/11] usb: typec: class: Remove both cable_match() and partner_match()
  2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
                   ` (9 preceding siblings ...)
  2024-12-11  0:08 ` [PATCH v4 10/11] cxl/pmem: Replace match_nvdimm_bridge() with " Zijun Hu
@ 2024-12-11  0:08 ` Zijun Hu
  2024-12-23 20:52   ` Jonathan Cameron
  10 siblings, 1 reply; 32+ messages in thread
From: Zijun Hu @ 2024-12-11  0:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Linus Walleij, Bartosz Golaszewski, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, Zijun Hu, linux-kernel,
	nvdimm, linux-sound, sparclinux, linux-block, linux-cxl,
	linux1394-devel, arm-scmi, linux-efi, linux-gpio, dri-devel,
	linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

cable_match(), as matching function of device_find_child(), matches
a device with device type @typec_cable_dev_type, and its task can be
simplified by the recently introduced API device_match_type().

partner_match() is similar with cable_match() but with a different
device type @typec_partner_dev_type.

Remove both functions and use the API plus respective device type instead.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/usb/typec/class.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 601a81aa1e1024265f2359393dee531a7779c6ea..3a4e0bd0131774afd0d746d2f0a306190219feec 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1282,11 +1282,6 @@ const struct device_type typec_cable_dev_type = {
 	.release = typec_cable_release,
 };
 
-static int cable_match(struct device *dev, const void *data)
-{
-	return is_typec_cable(dev);
-}
-
 /**
  * typec_cable_get - Get a reference to the USB Type-C cable
  * @port: The USB Type-C Port the cable is connected to
@@ -1298,7 +1293,8 @@ struct typec_cable *typec_cable_get(struct typec_port *port)
 {
 	struct device *dev;
 
-	dev = device_find_child(&port->dev, NULL, cable_match);
+	dev = device_find_child(&port->dev, &typec_cable_dev_type,
+				device_match_type);
 	if (!dev)
 		return NULL;
 
@@ -2028,16 +2024,12 @@ const struct device_type typec_port_dev_type = {
 /* --------------------------------------- */
 /* Driver callbacks to report role updates */
 
-static int partner_match(struct device *dev, const void *data)
-{
-	return is_typec_partner(dev);
-}
-
 static struct typec_partner *typec_get_partner(struct typec_port *port)
 {
 	struct device *dev;
 
-	dev = device_find_child(&port->dev, NULL, partner_match);
+	dev = device_find_child(&port->dev, &typec_partner_dev_type,
+				device_match_type);
 	if (!dev)
 		return NULL;
 
@@ -2170,7 +2162,9 @@ void typec_set_pwr_opmode(struct typec_port *port,
 	sysfs_notify(&port->dev.kobj, NULL, "power_operation_mode");
 	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
 
-	partner_dev = device_find_child(&port->dev, NULL, partner_match);
+	partner_dev = device_find_child(&port->dev,
+					&typec_partner_dev_type,
+					device_match_type);
 	if (partner_dev) {
 		struct typec_partner *partner = to_typec_partner(partner_dev);
 
@@ -2334,7 +2328,9 @@ int typec_get_negotiated_svdm_version(struct typec_port *port)
 	enum usb_pd_svdm_ver svdm_version;
 	struct device *partner_dev;
 
-	partner_dev = device_find_child(&port->dev, NULL, partner_match);
+	partner_dev = device_find_child(&port->dev,
+					&typec_partner_dev_type,
+					device_match_type);
 	if (!partner_dev)
 		return -ENODEV;
 
@@ -2361,7 +2357,8 @@ int typec_get_cable_svdm_version(struct typec_port *port)
 	enum usb_pd_svdm_ver svdm_version;
 	struct device *cable_dev;
 
-	cable_dev = device_find_child(&port->dev, NULL, cable_match);
+	cable_dev = device_find_child(&port->dev, &typec_cable_dev_type,
+				      device_match_type);
 	if (!cable_dev)
 		return -ENODEV;
 

-- 
2.34.1


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

* Re: [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode()
  2024-12-11  0:08 ` [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode() Zijun Hu
@ 2024-12-11  8:18   ` Bartosz Golaszewski
  2024-12-23 20:45   ` Jonathan Cameron
  1 sibling, 0 replies; 32+ messages in thread
From: Bartosz Golaszewski @ 2024-12-11  8:18 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Uwe Kleine-König,
	James Bottomley, Thomas Weißschuh, linux-kernel, nvdimm,
	linux-sound, sparclinux, linux-block, linux-cxl, linux1394-devel,
	arm-scmi, linux-efi, linux-gpio, dri-devel, linux-mediatek,
	linux-hwmon, linux-media, linux-pwm, linux-remoteproc, linux-scsi,
	linux-usb, linux-serial, netdev, Zijun Hu

On Wed, Dec 11, 2024 at 1:10 AM Zijun Hu <zijun_hu@icloud.com> wrote:
>
> From: Zijun Hu <quic_zijuhu@quicinc.com>
>
> gpio_sim_dev_match_fwnode() is a simple wrapper of API
> device_match_fwnode().
>
> Remove the needless wrapper and use the API instead.
>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---

Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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

* Re: [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages
  2024-12-11  0:08 ` [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages Zijun Hu
@ 2024-12-23  7:30   ` Uwe Kleine-König
  2024-12-23 20:33   ` Jonathan Cameron
  2025-01-02 17:07   ` Mathieu Poirier
  2 siblings, 0 replies; 32+ messages in thread
From: Uwe Kleine-König @ 2024-12-23  7:30 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	James Bottomley, Thomas Weißschuh, linux-kernel, nvdimm,
	linux-sound, sparclinux, linux-block, linux-cxl, linux1394-devel,
	arm-scmi, linux-efi, linux-gpio, dri-devel, linux-mediatek,
	linux-hwmon, linux-media, linux-pwm, linux-remoteproc, linux-scsi,
	linux-usb, linux-serial, netdev, Zijun Hu, Alison Schofield,
	Takashi Sakamoto

[-- Attachment #1: Type: text/plain, Size: 211 bytes --]

Hello,

On Wed, Dec 11, 2024 at 08:08:06AM +0800, Zijun Hu wrote:
>  drivers/pwm/core.c                     |  2 +-

Acked-by: Uwe Kleine-König <ukleinek@kernel.org> # for drivers/pwm

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name()
  2024-12-11  0:08 ` [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name() Zijun Hu
@ 2024-12-23 20:23   ` Jonathan Cameron
  2025-01-02 18:17   ` Fan Ni
  1 sibling, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:23 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield

On Wed, 11 Dec 2024 08:08:03 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Simplify nd_namespace_store() implementation by
> using device_find_child_by_name().
> 
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/nvdimm/claim.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c
> index 030dbde6b0882050c90fb8db106ec15b1baef7ca..9e84ab411564f9d5e7ceb687c6491562564552e3 100644
> --- a/drivers/nvdimm/claim.c
> +++ b/drivers/nvdimm/claim.c
> @@ -67,13 +67,6 @@ bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
>  	return claimed;
>  }
>  
> -static int namespace_match(struct device *dev, void *data)
> -{
> -	char *name = data;
> -
> -	return strcmp(name, dev_name(dev)) == 0;
> -}
> -
>  static bool is_idle(struct device *dev, struct nd_namespace_common *ndns)
>  {
>  	struct nd_region *nd_region = to_nd_region(dev->parent);
> @@ -168,7 +161,7 @@ ssize_t nd_namespace_store(struct device *dev,
>  		goto out;
>  	}
>  
> -	found = device_find_child(dev->parent, name, namespace_match);
> +	found = device_find_child_by_name(dev->parent, name);
>  	if (!found) {
>  		dev_dbg(dev, "'%s' not found under %s\n", name,
>  				dev_name(dev->parent));
> 


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

* Re: [PATCH v4 02/11] slimbus: core: Constify slim_eaddr_equal()
  2024-12-11  0:08 ` [PATCH v4 02/11] slimbus: core: Constify slim_eaddr_equal() Zijun Hu
@ 2024-12-23 20:25   ` Jonathan Cameron
  0 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:25 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:04 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> bool slim_eaddr_equal(struct slim_eaddr *a, struct slim_eaddr *b)
> does not modify @*a or @*b.
> 
> Constify it by simply changing its parameter type to
> 'const struct slim_eaddr *'.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

Absolutely makes sense given later patches mean one of the inputs
is of type constant pointer, but maybe worth calling that out as
the reason for the change here.

Other than that looks good.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/slimbus/core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
> index 65e5515f7555e2eb840fedaf2dc4cc5d76dbc089..b5d5bbb9fdb6614ffd578f5754226b50e394f0df 100644
> --- a/drivers/slimbus/core.c
> +++ b/drivers/slimbus/core.c
> @@ -328,7 +328,8 @@ void slim_report_absent(struct slim_device *sbdev)
>  }
>  EXPORT_SYMBOL_GPL(slim_report_absent);
>  
> -static bool slim_eaddr_equal(struct slim_eaddr *a, struct slim_eaddr *b)
> +static bool slim_eaddr_equal(const struct slim_eaddr *a,
> +			     const struct slim_eaddr *b)
>  {
>  	return (a->manf_id == b->manf_id &&
>  		a->prod_code == b->prod_code &&
> 


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

* Re: [PATCH v4 03/11] bus: fsl-mc: Constify fsl_mc_device_match()
  2024-12-11  0:08 ` [PATCH v4 03/11] bus: fsl-mc: Constify fsl_mc_device_match() Zijun Hu
@ 2024-12-23 20:26   ` Jonathan Cameron
  2024-12-24 12:36     ` Zijun Hu
  0 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:26 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:05 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> fsl_mc_device_match() does not modify caller's inputs.
> 
> Constify it by simply changing its parameter types to const pointer.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Similar to previous patch, I'd say why you are making this change.
There are may places in the kernel where pointers are constant but
not marked so. Why does this one matter?  

With that info added
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/bus/fsl-mc/dprc-driver.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c
> index 4b68c84ef485055c9b300b4f7912a20f959b8ac1..11c8fadcf85148b4e4ea6b97b7efb6d4ddf22d3c 100644
> --- a/drivers/bus/fsl-mc/dprc-driver.c
> +++ b/drivers/bus/fsl-mc/dprc-driver.c
> @@ -22,8 +22,8 @@ struct fsl_mc_child_objs {
>  	struct fsl_mc_obj_desc *child_array;
>  };
>  
> -static bool fsl_mc_device_match(struct fsl_mc_device *mc_dev,
> -				struct fsl_mc_obj_desc *obj_desc)
> +static bool fsl_mc_device_match(const struct fsl_mc_device *mc_dev,
> +				const struct fsl_mc_obj_desc *obj_desc)
>  {
>  	return mc_dev->obj_desc.id == obj_desc->id &&
>  	       strcmp(mc_dev->obj_desc.type, obj_desc->type) == 0;
> 


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

* Re: [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages
  2024-12-11  0:08 ` [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages Zijun Hu
  2024-12-23  7:30   ` Uwe Kleine-König
@ 2024-12-23 20:33   ` Jonathan Cameron
  2024-12-24 12:47     ` Zijun Hu
  2025-01-02 17:07   ` Mathieu Poirier
  2 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:33 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield, Takashi Sakamoto

On Wed, 11 Dec 2024 08:08:06 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Constify the following API:
> struct device *device_find_child(struct device *dev, void *data,
> 		int (*match)(struct device *dev, void *data));
> To :
> struct device *device_find_child(struct device *dev, const void *data,
>                                  device_match_t match);
> typedef int (*device_match_t)(struct device *dev, const void *data);
> with the following reasons:
> 
> - Protect caller's match data @*data which is for comparison and lookup
>   and the API does not actually need to modify @*data.
> 
> - Make the API's parameters (@match)() and @data have the same type as
>   all of other device finding APIs (bus|class|driver)_find_device().
> 
> - All kinds of existing device match functions can be directly taken
>   as the API's argument, they were exported by driver core.
> 
> Constify the API and adapt for various existing usages by simply making
> various match functions take 'const void *' as type of match data @data.

There are a couple of places I noticed where you changed types
that aren't related to the specific change this is making.
They are almost certainly fine but I'd either like a specific note
on that in this patch description or just change the elements
that are directly affected by this change.

> 
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>


> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index d778996507984a759bbe84e7acac3774e0c7af98..bfecd71040c2f4373645380b4c31327d8b42d095 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c

> @@ -1722,10 +1722,12 @@ static struct cxl_port *next_port(struct cxl_port *port)
>  	return port->parent_dport->port;
>  }
>  
> -static int match_switch_decoder_by_range(struct device *dev, void *data)
> +static int match_switch_decoder_by_range(struct device *dev,
> +					 const void *data)
>  {
>  	struct cxl_switch_decoder *cxlsd;
> -	struct range *r1, *r2 = data;
> +	const struct range *r1, *r2 = data;

As below. I'd not touch type of things you don't need to touch.

> +
>  
>  	if (!is_switch_decoder(dev))
>  		return 0;
> @@ -3176,9 +3178,10 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
>  	return rc;
>  }
>  
> -static int match_root_decoder_by_range(struct device *dev, void *data)
> +static int match_root_decoder_by_range(struct device *dev,
> +				       const void *data)
>  {
> -	struct range *r1, *r2 = data;
> +	const struct range *r1, *r2 = data;

From the point of view of keeping the patch to what it 'needs'
to touch, should leave type of r1 alone.
I've not looked at whether this causes any problems, just whether
it is relevant to this change.

>  	struct cxl_root_decoder *cxlrd;
>  
>  	if (!is_root_decoder(dev))
> @@ -3189,11 +3192,11 @@ static int match_root_decoder_by_range(struct device *dev, void *data)
>  	return range_contains(r1, r2);
>  }
>  
> -static int match_region_by_range(struct device *dev, void *data)
> +static int match_region_by_range(struct device *dev, const void *data)
>  {
>  	struct cxl_region_params *p;
>  	struct cxl_region *cxlr;
> -	struct range *r = data;
> +	const struct range *r = data;
>  	int rc = 0;
>  


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

* Re: [PATCH v4 05/11] driver core: Simplify API device_find_child_by_name() implementation
  2024-12-11  0:08 ` [PATCH v4 05/11] driver core: Simplify API device_find_child_by_name() implementation Zijun Hu
@ 2024-12-23 20:39   ` Jonathan Cameron
  2024-12-24 12:55     ` Zijun Hu
  0 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:39 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:07 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Simplify device_find_child_by_name() implementation by both existing
> API device_find_child() and device_match_name().
There is a subtle difference.  In theory old code could dereference a NULL
if parent->p == NULL, now it can't.  Sounds at most like a harmless change but
maybe you should mention it.

Otherwise LGTM
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/base/core.c | 13 +------------
>  1 file changed, 1 insertion(+), 12 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index bc3b523a4a6366080c3c9fd190e54c7fd13c8ded..8116bc8dd6e9eba0653ca686a90c7008de9e2840 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4110,18 +4110,7 @@ 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;
> +	return device_find_child(parent, name, device_match_name);
>  }
>  EXPORT_SYMBOL_GPL(device_find_child_by_name);
>  
> 


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

* Re: [PATCH v4 06/11] driver core: Remove match_any()
  2024-12-11  0:08 ` [PATCH v4 06/11] driver core: Remove match_any() Zijun Hu
@ 2024-12-23 20:40   ` Jonathan Cameron
  0 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:40 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:08 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Static match_any() is exactly same as API device_match_any().
is now exactly...

perhaps to call out that it wasn't prior to this set!

> Remove the former and use the later instead.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/base/core.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 8116bc8dd6e9eba0653ca686a90c7008de9e2840..289f2dafa8f3831931d0f316d66ee12c2cb8a2e1 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4114,11 +4114,6 @@ struct device *device_find_child_by_name(struct device *parent,
>  }
>  EXPORT_SYMBOL_GPL(device_find_child_by_name);
>  
> -static int match_any(struct device *dev, const void *unused)
> -{
> -	return 1;
> -}
> -
>  /**
>   * device_find_any_child - device iterator for locating a child device, if any.
>   * @parent: parent struct device
> @@ -4130,7 +4125,7 @@ static int match_any(struct device *dev, const void *unused)
>   */
>  struct device *device_find_any_child(struct device *parent)
>  {
> -	return device_find_child(parent, NULL, match_any);
> +	return device_find_child(parent, NULL, device_match_any);
>  }
>  EXPORT_SYMBOL_GPL(device_find_any_child);
>  
> 


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

* Re: [PATCH v4 07/11] slimbus: core: Remove of_slim_match_dev()
  2024-12-11  0:08 ` [PATCH v4 07/11] slimbus: core: Remove of_slim_match_dev() Zijun Hu
@ 2024-12-23 20:44   ` Jonathan Cameron
  0 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:44 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:09 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> static of_slim_match_dev() has same function as API device_match_of_node().
> 
> Remove the former and use the later instead.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Nice tidy up given the current code is dance up and down containing structure to exactly
the same device it started with.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/slimbus/core.c | 10 +---------
>  1 file changed, 1 insertion(+), 9 deletions(-)
> 
> diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
> index ab927fd077cb4fe1e29c004269fe52b2896c302f..005fa2ef100f526df5603d212b6334c06a366c94 100644
> --- a/drivers/slimbus/core.c
> +++ b/drivers/slimbus/core.c
> @@ -385,21 +385,13 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl,
>  }
>  EXPORT_SYMBOL_GPL(slim_get_device);
>  
> -static int of_slim_match_dev(struct device *dev, const void *data)
> -{
> -	const struct device_node *np = data;
> -	struct slim_device *sbdev = to_slim_device(dev);
> -
> -	return (sbdev->dev.of_node == np);
> -}
> -
>  static struct slim_device *of_find_slim_device(struct slim_controller *ctrl,
>  					       struct device_node *np)
>  {
>  	struct slim_device *sbdev;
>  	struct device *dev;
>  
> -	dev = device_find_child(ctrl->dev, np, of_slim_match_dev);
> +	dev = device_find_child(ctrl->dev, np, device_match_of_node);
>  	if (dev) {
>  		sbdev = to_slim_device(dev);
>  		return sbdev;
> 


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

* Re: [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode()
  2024-12-11  0:08 ` [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode() Zijun Hu
  2024-12-11  8:18   ` Bartosz Golaszewski
@ 2024-12-23 20:45   ` Jonathan Cameron
  1 sibling, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:45 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:10 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> gpio_sim_dev_match_fwnode() is a simple wrapper of API
> device_match_fwnode().
> 
> Remove the needless wrapper and use the API instead.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

> ---
>  drivers/gpio/gpio-sim.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index 370b71513bdb529112e157fa22a5451e02502a17..b1f33cbaaaa78aca324f99c45a868e7e79a9d672 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -413,11 +413,6 @@ static int gpio_sim_setup_sysfs(struct gpio_sim_chip *chip)
>  	return devm_add_action_or_reset(dev, gpio_sim_sysfs_remove, chip);
>  }
>  
> -static int gpio_sim_dev_match_fwnode(struct device *dev, const void *data)
> -{
> -	return device_match_fwnode(dev, data);
> -}
> -
>  static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
>  {
>  	struct gpio_sim_chip *chip;
> @@ -503,7 +498,7 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
>  	if (ret)
>  		return ret;
>  
> -	chip->dev = device_find_child(dev, swnode, gpio_sim_dev_match_fwnode);
> +	chip->dev = device_find_child(dev, swnode, device_match_fwnode);
>  	if (!chip->dev)
>  		return -ENODEV;
>  
> 


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

* Re: [PATCH v4 09/11] driver core: Introduce an device matching API device_match_type()
  2024-12-11  0:08 ` [PATCH v4 09/11] driver core: Introduce an device matching API device_match_type() Zijun Hu
@ 2024-12-23 20:46   ` Jonathan Cameron
  0 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:46 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:11 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Introduce device_match_type() for purposes below:
> 
> - Test if a device matches with a specified device type.
> - As argument of various device finding APIs to find a device with
>   specified type.
> 
> device_find_child() will use it to simplify operations later.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Seems useful enough to have a generic helper.

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  drivers/base/core.c        | 6 ++++++
>  include/linux/device/bus.h | 1 +
>  2 files changed, 7 insertions(+)
> 
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 289f2dafa8f3831931d0f316d66ee12c2cb8a2e1..8bdbc9e657e832a063542391426f570ccb5c18b9 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -5228,6 +5228,12 @@ int device_match_name(struct device *dev, const void *name)
>  }
>  EXPORT_SYMBOL_GPL(device_match_name);
>  
> +int device_match_type(struct device *dev, const void *type)
> +{
> +	return dev->type == type;
> +}
> +EXPORT_SYMBOL_GPL(device_match_type);
> +
>  int device_match_of_node(struct device *dev, const void *np)
>  {
>  	return dev->of_node == np;
> diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
> index cdc4757217f9bb4b36b5c3b8a48bab45737e44c5..bc3fd74bb763e6d2d862859bd2ec3f0d443f2d7a 100644
> --- a/include/linux/device/bus.h
> +++ b/include/linux/device/bus.h
> @@ -131,6 +131,7 @@ typedef int (*device_match_t)(struct device *dev, const void *data);
>  
>  /* Generic device matching functions that all busses can use to match with */
>  int device_match_name(struct device *dev, const void *name);
> +int device_match_type(struct device *dev, const void *type);
>  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);
> 


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

* Re: [PATCH v4 10/11] cxl/pmem: Replace match_nvdimm_bridge() with API device_match_type()
  2024-12-11  0:08 ` [PATCH v4 10/11] cxl/pmem: Replace match_nvdimm_bridge() with " Zijun Hu
@ 2024-12-23 20:48   ` Jonathan Cameron
  2024-12-24 12:58     ` Zijun Hu
  0 siblings, 1 reply; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:48 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield

On Wed, 11 Dec 2024 08:08:12 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Static match_nvdimm_bridge(), as matching function of device_find_child()
> matches a device with device type @cxl_nvdimm_bridge_type, and its task
> can be simplified by the recently introduced API device_match_type().
> 
> Replace match_nvdimm_bridge() usage with device_match_type().
> 
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

I don't see any uses of is_cxl_nvdimm_bridge() other than this one
Drop that as well?

This one is a bit of a trade off because the way is_cxl_nvdimm_bridge()
is identified is kind of an internal detail, but it's been true for a long
time so I'm fine with this change.

Jonathan


> ---
>  drivers/cxl/core/pmem.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
> index a8473de24ebfd92f12f47e0556e28b81a29cff7c..0f8166e793e14fc0b1c04ffda79e756a743d9e6b 100644
> --- a/drivers/cxl/core/pmem.c
> +++ b/drivers/cxl/core/pmem.c
> @@ -57,11 +57,6 @@ bool is_cxl_nvdimm_bridge(struct device *dev)
>  }
>  EXPORT_SYMBOL_NS_GPL(is_cxl_nvdimm_bridge, "CXL");
>  
> -static int match_nvdimm_bridge(struct device *dev, const void *data)
> -{
> -	return is_cxl_nvdimm_bridge(dev);
> -}
> -
>  /**
>   * cxl_find_nvdimm_bridge() - find a bridge device relative to a port
>   * @port: any descendant port of an nvdimm-bridge associated
> @@ -75,7 +70,9 @@ struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port)
>  	if (!cxl_root)
>  		return NULL;
>  
> -	dev = device_find_child(&cxl_root->port.dev, NULL, match_nvdimm_bridge);
> +	dev = device_find_child(&cxl_root->port.dev,
> +				&cxl_nvdimm_bridge_type,
> +				device_match_type);
>  
>  	if (!dev)
>  		return NULL;
> 


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

* Re: [PATCH v4 11/11] usb: typec: class: Remove both cable_match() and partner_match()
  2024-12-11  0:08 ` [PATCH v4 11/11] usb: typec: class: Remove both cable_match() and partner_match() Zijun Hu
@ 2024-12-23 20:52   ` Jonathan Cameron
  0 siblings, 0 replies; 32+ messages in thread
From: Jonathan Cameron @ 2024-12-23 20:52 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On Wed, 11 Dec 2024 08:08:13 +0800
Zijun Hu <zijun_hu@icloud.com> wrote:

> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> cable_match(), as matching function of device_find_child(), matches
> a device with device type @typec_cable_dev_type, and its task can be
> simplified by the recently introduced API device_match_type().
> 
> partner_match() is similar with cable_match() but with a different
> device type @typec_partner_dev_type.
> 
> Remove both functions and use the API plus respective device type instead.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Looks good, but there is the same trade off here between internal
detail of type identification and reducing the use of helpers
where the generic ones are fine.  Here is less obvious even than
the CXL one as the helper macros do have other uses in these
files.

So, it's on for USB folk to decide on and I won't be giving a tag
as a result.

Jonathan

> ---
>  drivers/usb/typec/class.c | 27 ++++++++++++---------------
>  1 file changed, 12 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 601a81aa1e1024265f2359393dee531a7779c6ea..3a4e0bd0131774afd0d746d2f0a306190219feec 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -1282,11 +1282,6 @@ const struct device_type typec_cable_dev_type = {
>  	.release = typec_cable_release,
>  };
>  
> -static int cable_match(struct device *dev, const void *data)
> -{
> -	return is_typec_cable(dev);
> -}
> -
>  /**
>   * typec_cable_get - Get a reference to the USB Type-C cable
>   * @port: The USB Type-C Port the cable is connected to
> @@ -1298,7 +1293,8 @@ struct typec_cable *typec_cable_get(struct typec_port *port)
>  {
>  	struct device *dev;
>  
> -	dev = device_find_child(&port->dev, NULL, cable_match);
> +	dev = device_find_child(&port->dev, &typec_cable_dev_type,
> +				device_match_type);
>  	if (!dev)
>  		return NULL;
>  
> @@ -2028,16 +2024,12 @@ const struct device_type typec_port_dev_type = {
>  /* --------------------------------------- */
>  /* Driver callbacks to report role updates */
>  
> -static int partner_match(struct device *dev, const void *data)
> -{
> -	return is_typec_partner(dev);
> -}
> -
>  static struct typec_partner *typec_get_partner(struct typec_port *port)
>  {
>  	struct device *dev;
>  
> -	dev = device_find_child(&port->dev, NULL, partner_match);
> +	dev = device_find_child(&port->dev, &typec_partner_dev_type,
> +				device_match_type);
>  	if (!dev)
>  		return NULL;
>  
> @@ -2170,7 +2162,9 @@ void typec_set_pwr_opmode(struct typec_port *port,
>  	sysfs_notify(&port->dev.kobj, NULL, "power_operation_mode");
>  	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
>  
> -	partner_dev = device_find_child(&port->dev, NULL, partner_match);
> +	partner_dev = device_find_child(&port->dev,
> +					&typec_partner_dev_type,
> +					device_match_type);
>  	if (partner_dev) {
>  		struct typec_partner *partner = to_typec_partner(partner_dev);
>  
> @@ -2334,7 +2328,9 @@ int typec_get_negotiated_svdm_version(struct typec_port *port)
>  	enum usb_pd_svdm_ver svdm_version;
>  	struct device *partner_dev;
>  
> -	partner_dev = device_find_child(&port->dev, NULL, partner_match);
> +	partner_dev = device_find_child(&port->dev,
> +					&typec_partner_dev_type,
> +					device_match_type);
>  	if (!partner_dev)
>  		return -ENODEV;
>  
> @@ -2361,7 +2357,8 @@ int typec_get_cable_svdm_version(struct typec_port *port)
>  	enum usb_pd_svdm_ver svdm_version;
>  	struct device *cable_dev;
>  
> -	cable_dev = device_find_child(&port->dev, NULL, cable_match);
> +	cable_dev = device_find_child(&port->dev, &typec_cable_dev_type,
> +				      device_match_type);
>  	if (!cable_dev)
>  		return -ENODEV;
>  
> 


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

* Re: [PATCH v4 03/11] bus: fsl-mc: Constify fsl_mc_device_match()
  2024-12-23 20:26   ` Jonathan Cameron
@ 2024-12-24 12:36     ` Zijun Hu
  0 siblings, 0 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-24 12:36 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On 2024/12/24 04:26, Jonathan Cameron wrote:
> On Wed, 11 Dec 2024 08:08:05 +0800
> Zijun Hu <zijun_hu@icloud.com> wrote:
> 
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> fsl_mc_device_match() does not modify caller's inputs.
>>
>> Constify it by simply changing its parameter types to const pointer.
>>
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> Similar to previous patch, I'd say why you are making this change.
> There are may places in the kernel where pointers are constant but
> not marked so. Why does this one matter?  
> 

thank you for code review.
make sense.
will correct comment message for this and previous patch in v5.

> With that info added
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


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

* Re: [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages
  2024-12-23 20:33   ` Jonathan Cameron
@ 2024-12-24 12:47     ` Zijun Hu
  0 siblings, 0 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-24 12:47 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield, Takashi Sakamoto

On 2024/12/24 04:33, Jonathan Cameron wrote:
> On Wed, 11 Dec 2024 08:08:06 +0800
> Zijun Hu <zijun_hu@icloud.com> wrote:
> 
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> Constify the following API:
>> struct device *device_find_child(struct device *dev, void *data,
>> 		int (*match)(struct device *dev, void *data));
>> To :
>> struct device *device_find_child(struct device *dev, const void *data,
>>                                  device_match_t match);
>> typedef int (*device_match_t)(struct device *dev, const void *data);
>> with the following reasons:
>>
>> - Protect caller's match data @*data which is for comparison and lookup
>>   and the API does not actually need to modify @*data.
>>
>> - Make the API's parameters (@match)() and @data have the same type as
>>   all of other device finding APIs (bus|class|driver)_find_device().
>>
>> - All kinds of existing device match functions can be directly taken
>>   as the API's argument, they were exported by driver core.
>>
>> Constify the API and adapt for various existing usages by simply making
>> various match functions take 'const void *' as type of match data @data.
> 
> There are a couple of places I noticed where you changed types
> that aren't related to the specific change this is making.
> They are almost certainly fine but I'd either like a specific note
> on that in this patch description or just change the elements
> that are directly affected by this change.
> 

okay, will correct commit message in v5.

v5 will mention these changes will bring extra code improvement as side
effects during achieving main purpose.

>>
>> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
>> Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> 
>> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
>> index d778996507984a759bbe84e7acac3774e0c7af98..bfecd71040c2f4373645380b4c31327d8b42d095 100644
>> --- a/drivers/cxl/core/region.c
>> +++ b/drivers/cxl/core/region.c
> 
>> @@ -1722,10 +1722,12 @@ static struct cxl_port *next_port(struct cxl_port *port)
>>  	return port->parent_dport->port;
>>  }
>>  
>> -static int match_switch_decoder_by_range(struct device *dev, void *data)
>> +static int match_switch_decoder_by_range(struct device *dev,
>> +					 const void *data)
>>  {
>>  	struct cxl_switch_decoder *cxlsd;
>> -	struct range *r1, *r2 = data;
>> +	const struct range *r1, *r2 = data;
> 
> As below. I'd not touch type of things you don't need to touch.
> 
explained below.

>> +
>>  
>>  	if (!is_switch_decoder(dev))
>>  		return 0;
>> @@ -3176,9 +3178,10 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
>>  	return rc;
>>  }
>>  
>> -static int match_root_decoder_by_range(struct device *dev, void *data)
>> +static int match_root_decoder_by_range(struct device *dev,
>> +				       const void *data)
>>  {
>> -	struct range *r1, *r2 = data;
>> +	const struct range *r1, *r2 = data;
> 
> From the point of view of keeping the patch to what it 'needs'
> to touch, should leave type of r1 alone.
> I've not looked at whether this causes any problems, just whether
> it is relevant to this change.
> 

1) i have checked that will not cause problem, may have code improvement

2) this change (2 lines) is simpler than below(3 lines)
   -	struct range *r1, *r2 = data;
   +    struct range *r1;
   +    const struct range *r2 = data;

3) r1 and r2 are used for range_contains() whose prototype was changed
to takes 2 const pointers recently.

4) make r1 & r2 keep the same type as original.

>>  	struct cxl_root_decoder *cxlrd;
>>  
>>  	if (!is_root_decoder(dev))
>> @@ -3189,11 +3192,11 @@ static int match_root_decoder_by_range(struct device *dev, void *data)
>>  	return range_contains(r1, r2);
>>  }
>>  
>> -static int match_region_by_range(struct device *dev, void *data)
>> +static int match_region_by_range(struct device *dev, const void *data)
>>  {
>>  	struct cxl_region_params *p;
>>  	struct cxl_region *cxlr;
>> -	struct range *r = data;
>> +	const struct range *r = data;
>>  	int rc = 0;
>>  
> 



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

* Re: [PATCH v4 05/11] driver core: Simplify API device_find_child_by_name() implementation
  2024-12-23 20:39   ` Jonathan Cameron
@ 2024-12-24 12:55     ` Zijun Hu
  0 siblings, 0 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-24 12:55 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu

On 2024/12/24 04:39, Jonathan Cameron wrote:
> There is a subtle difference.  In theory old code could dereference a NULL
> if parent->p == NULL, now it can't.  Sounds at most like a harmless change but
> maybe you should mention it.
> 

i did not correct parameter checking for device_find_child_by_name() in
below commit

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/drivers/base/core.c?id=903c44939abc02e2f3d6f2ad65fa090f7e5df5b6

since this commit will come finally, actually, this commit is the
original motivation of this whole patch series.

> Otherwise LGTM
> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>


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

* Re: [PATCH v4 10/11] cxl/pmem: Replace match_nvdimm_bridge() with API device_match_type()
  2024-12-23 20:48   ` Jonathan Cameron
@ 2024-12-24 12:58     ` Zijun Hu
  0 siblings, 0 replies; 32+ messages in thread
From: Zijun Hu @ 2024-12-24 12:58 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield

On 2024/12/24 04:48, Jonathan Cameron wrote:
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> Static match_nvdimm_bridge(), as matching function of device_find_child()
>> matches a device with device type @cxl_nvdimm_bridge_type, and its task
>> can be simplified by the recently introduced API device_match_type().
>>
>> Replace match_nvdimm_bridge() usage with device_match_type().
>>
>> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
>> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> I don't see any uses of is_cxl_nvdimm_bridge() other than this one
> Drop that as well?
> 
will add a optional patch to drop is_cxl_nvdimm_bridge() in next revision.

> This one is a bit of a trade off because the way is_cxl_nvdimm_bridge()
> is identified is kind of an internal detail, but it's been true for a long
> time so I'm fine with this change.
> 
> Jonathan


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

* Re: [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages
  2024-12-11  0:08 ` [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages Zijun Hu
  2024-12-23  7:30   ` Uwe Kleine-König
  2024-12-23 20:33   ` Jonathan Cameron
@ 2025-01-02 17:07   ` Mathieu Poirier
  2 siblings, 0 replies; 32+ messages in thread
From: Mathieu Poirier @ 2025-01-02 17:07 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield, Takashi Sakamoto

On Wed, Dec 11, 2024 at 08:08:06AM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Constify the following API:
> struct device *device_find_child(struct device *dev, void *data,
> 		int (*match)(struct device *dev, void *data));
> To :
> struct device *device_find_child(struct device *dev, const void *data,
>                                  device_match_t match);
> typedef int (*device_match_t)(struct device *dev, const void *data);
> with the following reasons:
> 
> - Protect caller's match data @*data which is for comparison and lookup
>   and the API does not actually need to modify @*data.
> 
> - Make the API's parameters (@match)() and @data have the same type as
>   all of other device finding APIs (bus|class|driver)_find_device().
> 
> - All kinds of existing device match functions can be directly taken
>   as the API's argument, they were exported by driver core.
> 
> Constify the API and adapt for various existing usages by simply making
> various match functions take 'const void *' as type of match data @data.
> 
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  arch/sparc/kernel/vio.c                |  6 +++---
>  drivers/base/core.c                    |  6 +++---
>  drivers/block/sunvdc.c                 |  6 +++---
>  drivers/bus/fsl-mc/dprc-driver.c       |  4 ++--
>  drivers/cxl/core/pci.c                 |  4 ++--
>  drivers/cxl/core/pmem.c                |  2 +-
>  drivers/cxl/core/region.c              | 21 ++++++++++++---------
>  drivers/firewire/core-device.c         |  4 ++--
>  drivers/firmware/arm_scmi/bus.c        |  4 ++--
>  drivers/firmware/efi/dev-path-parser.c |  4 ++--
>  drivers/gpio/gpio-sim.c                |  2 +-
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c |  2 +-
>  drivers/hwmon/hwmon.c                  |  2 +-
>  drivers/media/pci/mgb4/mgb4_core.c     |  4 ++--
>  drivers/nvdimm/bus.c                   |  2 +-
>  drivers/pwm/core.c                     |  2 +-
>  drivers/rpmsg/rpmsg_core.c             |  4 ++--

Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org>

>  drivers/scsi/qla4xxx/ql4_os.c          |  3 ++-
>  drivers/scsi/scsi_transport_iscsi.c    | 10 +++++-----
>  drivers/slimbus/core.c                 |  8 ++++----
>  drivers/thunderbolt/retimer.c          |  2 +-
>  drivers/thunderbolt/xdomain.c          |  2 +-
>  drivers/tty/serial/serial_core.c       |  4 ++--
>  drivers/usb/typec/class.c              |  8 ++++----
>  include/linux/device.h                 |  4 ++--
>  include/scsi/scsi_transport_iscsi.h    |  4 ++--
>  net/dsa/dsa.c                          |  2 +-
>  tools/testing/cxl/test/cxl.c           |  2 +-
>  28 files changed, 66 insertions(+), 62 deletions(-)
> 
> diff --git a/arch/sparc/kernel/vio.c b/arch/sparc/kernel/vio.c
> index 07933d75ac815160a2580dce39fde7653a9502e1..1a1a9d6b8f2e8dfedefafde846315a06a167fbfb 100644
> --- a/arch/sparc/kernel/vio.c
> +++ b/arch/sparc/kernel/vio.c
> @@ -419,13 +419,13 @@ struct vio_remove_node_data {
>  	u64 node;
>  };
>  
> -static int vio_md_node_match(struct device *dev, void *arg)
> +static int vio_md_node_match(struct device *dev, const void *arg)
>  {
>  	struct vio_dev *vdev = to_vio_dev(dev);
> -	struct vio_remove_node_data *node_data;
> +	const struct vio_remove_node_data *node_data;
>  	u64 node;
>  
> -	node_data = (struct vio_remove_node_data *)arg;
> +	node_data = (const struct vio_remove_node_data *)arg;
>  
>  	node = vio_vdev_node(node_data->hp, vdev);
>  
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index 94865c9d8adcf5f2ce5002ffd7bf0ef4fc85e4d7..bc3b523a4a6366080c3c9fd190e54c7fd13c8ded 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -4079,8 +4079,8 @@ EXPORT_SYMBOL_GPL(device_for_each_child_reverse_from);
>   *
>   * NOTE: you will need to drop the reference with put_device() after use.
>   */
> -struct device *device_find_child(struct device *parent, void *data,
> -				 int (*match)(struct device *dev, void *data))
> +struct device *device_find_child(struct device *parent, const void *data,
> +				 device_match_t match)
>  {
>  	struct klist_iter i;
>  	struct device *child;
> @@ -4125,7 +4125,7 @@ struct device *device_find_child_by_name(struct device *parent,
>  }
>  EXPORT_SYMBOL_GPL(device_find_child_by_name);
>  
> -static int match_any(struct device *dev, void *unused)
> +static int match_any(struct device *dev, const void *unused)
>  {
>  	return 1;
>  }
> diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
> index 2d38331ee66793402e803ec0cc82e9e71c991c84..386643ceed59921203828844aa070833c44c67fb 100644
> --- a/drivers/block/sunvdc.c
> +++ b/drivers/block/sunvdc.c
> @@ -918,12 +918,12 @@ struct vdc_check_port_data {
>  	char	*type;
>  };
>  
> -static int vdc_device_probed(struct device *dev, void *arg)
> +static int vdc_device_probed(struct device *dev, const void *arg)
>  {
>  	struct vio_dev *vdev = to_vio_dev(dev);
> -	struct vdc_check_port_data *port_data;
> +	const struct vdc_check_port_data *port_data;
>  
> -	port_data = (struct vdc_check_port_data *)arg;
> +	port_data = (const struct vdc_check_port_data *)arg;
>  
>  	if ((vdev->dev_no == port_data->dev_no) &&
>  	    (!(strcmp((char *)&vdev->type, port_data->type))) &&
> diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c
> index 11c8fadcf85148b4e4ea6b97b7efb6d4ddf22d3c..52053f7c6d9a654ba46c6579c6a3c5c3faaa75c1 100644
> --- a/drivers/bus/fsl-mc/dprc-driver.c
> +++ b/drivers/bus/fsl-mc/dprc-driver.c
> @@ -112,9 +112,9 @@ void dprc_remove_devices(struct fsl_mc_device *mc_bus_dev,
>  }
>  EXPORT_SYMBOL_GPL(dprc_remove_devices);
>  
> -static int __fsl_mc_device_match(struct device *dev, void *data)
> +static int __fsl_mc_device_match(struct device *dev, const void *data)
>  {
> -	struct fsl_mc_obj_desc *obj_desc = data;
> +	const struct fsl_mc_obj_desc *obj_desc = data;
>  	struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
>  
>  	return fsl_mc_device_match(mc_dev, obj_desc);
> diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
> index 9d58ab9d33c554e05ddfa2610269e6d08bfaa8e9..a3c57f96138a28c9f30562d554c42cb5224bcf4b 100644
> --- a/drivers/cxl/core/pci.c
> +++ b/drivers/cxl/core/pci.c
> @@ -252,9 +252,9 @@ static int devm_cxl_enable_mem(struct device *host, struct cxl_dev_state *cxlds)
>  }
>  
>  /* require dvsec ranges to be covered by a locked platform window */
> -static int dvsec_range_allowed(struct device *dev, void *arg)
> +static int dvsec_range_allowed(struct device *dev, const void *arg)
>  {
> -	struct range *dev_range = arg;
> +	const struct range *dev_range = arg;
>  	struct cxl_decoder *cxld;
>  
>  	if (!is_root_decoder(dev))
> diff --git a/drivers/cxl/core/pmem.c b/drivers/cxl/core/pmem.c
> index b3378d3f6acb4c9e3601683119754e3cd6329df2..a8473de24ebfd92f12f47e0556e28b81a29cff7c 100644
> --- a/drivers/cxl/core/pmem.c
> +++ b/drivers/cxl/core/pmem.c
> @@ -57,7 +57,7 @@ bool is_cxl_nvdimm_bridge(struct device *dev)
>  }
>  EXPORT_SYMBOL_NS_GPL(is_cxl_nvdimm_bridge, "CXL");
>  
> -static int match_nvdimm_bridge(struct device *dev, void *data)
> +static int match_nvdimm_bridge(struct device *dev, const void *data)
>  {
>  	return is_cxl_nvdimm_bridge(dev);
>  }
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index d778996507984a759bbe84e7acac3774e0c7af98..bfecd71040c2f4373645380b4c31327d8b42d095 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -792,7 +792,7 @@ static int check_commit_order(struct device *dev, const void *data)
>  	return 0;
>  }
>  
> -static int match_free_decoder(struct device *dev, void *data)
> +static int match_free_decoder(struct device *dev, const void *data)
>  {
>  	struct cxl_port *port = to_cxl_port(dev->parent);
>  	struct cxl_decoder *cxld;
> @@ -824,9 +824,9 @@ static int match_free_decoder(struct device *dev, void *data)
>  	return 1;
>  }
>  
> -static int match_auto_decoder(struct device *dev, void *data)
> +static int match_auto_decoder(struct device *dev, const void *data)
>  {
> -	struct cxl_region_params *p = data;
> +	const struct cxl_region_params *p = data;
>  	struct cxl_decoder *cxld;
>  	struct range *r;
>  
> @@ -1722,10 +1722,12 @@ static struct cxl_port *next_port(struct cxl_port *port)
>  	return port->parent_dport->port;
>  }
>  
> -static int match_switch_decoder_by_range(struct device *dev, void *data)
> +static int match_switch_decoder_by_range(struct device *dev,
> +					 const void *data)
>  {
>  	struct cxl_switch_decoder *cxlsd;
> -	struct range *r1, *r2 = data;
> +	const struct range *r1, *r2 = data;
> +
>  
>  	if (!is_switch_decoder(dev))
>  		return 0;
> @@ -3176,9 +3178,10 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr)
>  	return rc;
>  }
>  
> -static int match_root_decoder_by_range(struct device *dev, void *data)
> +static int match_root_decoder_by_range(struct device *dev,
> +				       const void *data)
>  {
> -	struct range *r1, *r2 = data;
> +	const struct range *r1, *r2 = data;
>  	struct cxl_root_decoder *cxlrd;
>  
>  	if (!is_root_decoder(dev))
> @@ -3189,11 +3192,11 @@ static int match_root_decoder_by_range(struct device *dev, void *data)
>  	return range_contains(r1, r2);
>  }
>  
> -static int match_region_by_range(struct device *dev, void *data)
> +static int match_region_by_range(struct device *dev, const void *data)
>  {
>  	struct cxl_region_params *p;
>  	struct cxl_region *cxlr;
> -	struct range *r = data;
> +	const struct range *r = data;
>  	int rc = 0;
>  
>  	if (!is_cxl_region(dev))
> diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
> index a99fe35f1f0d1a2e585ac49b86cc6fd0807cffb6..ec3e21ad202520dda745064b954c853a26d03e3d 100644
> --- a/drivers/firewire/core-device.c
> +++ b/drivers/firewire/core-device.c
> @@ -988,7 +988,7 @@ int fw_device_set_broadcast_channel(struct device *dev, void *gen)
>  	return 0;
>  }
>  
> -static int compare_configuration_rom(struct device *dev, void *data)
> +static int compare_configuration_rom(struct device *dev, const void *data)
>  {
>  	const struct fw_device *old = fw_device(dev);
>  	const u32 *config_rom = data;
> @@ -1039,7 +1039,7 @@ static void fw_device_init(struct work_struct *work)
>  	//
>  	// serialize config_rom access.
>  	scoped_guard(rwsem_read, &fw_device_rwsem) {
> -		found = device_find_child(card->device, (void *)device->config_rom,
> +		found = device_find_child(card->device, device->config_rom,
>  					  compare_configuration_rom);
>  	}
>  	if (found) {
> diff --git a/drivers/firmware/arm_scmi/bus.c b/drivers/firmware/arm_scmi/bus.c
> index 157172a5f2b577ce4f04425f967f548230c1ebed..a3386bf36de508d312e2c4fa2e27ba62ba3776a0 100644
> --- a/drivers/firmware/arm_scmi/bus.c
> +++ b/drivers/firmware/arm_scmi/bus.c
> @@ -238,10 +238,10 @@ static int scmi_dev_match(struct device *dev, const struct device_driver *drv)
>  	return 0;
>  }
>  
> -static int scmi_match_by_id_table(struct device *dev, void *data)
> +static int scmi_match_by_id_table(struct device *dev, const void *data)
>  {
>  	struct scmi_device *sdev = to_scmi_dev(dev);
> -	struct scmi_device_id *id_table = data;
> +	const struct scmi_device_id *id_table = data;
>  
>  	return sdev->protocol_id == id_table->protocol_id &&
>  		(id_table->name && !strcmp(sdev->name, id_table->name));
> diff --git a/drivers/firmware/efi/dev-path-parser.c b/drivers/firmware/efi/dev-path-parser.c
> index 937be269fee86d5d71256758aed94741e794431c..13ea141c0defb5e80d5af43cca73cf527444a238 100644
> --- a/drivers/firmware/efi/dev-path-parser.c
> +++ b/drivers/firmware/efi/dev-path-parser.c
> @@ -47,9 +47,9 @@ static long __init parse_acpi_path(const struct efi_dev_path *node,
>  	return 0;
>  }
>  
> -static int __init match_pci_dev(struct device *dev, void *data)
> +static int __init match_pci_dev(struct device *dev, const void *data)
>  {
> -	unsigned int devfn = *(unsigned int *)data;
> +	unsigned int devfn = *(const unsigned int *)data;
>  
>  	return dev_is_pci(dev) && to_pci_dev(dev)->devfn == devfn;
>  }
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index f387dad81f2960b5ec3c1b5fd04081ee501cc75b..370b71513bdb529112e157fa22a5451e02502a17 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -413,7 +413,7 @@ static int gpio_sim_setup_sysfs(struct gpio_sim_chip *chip)
>  	return devm_add_action_or_reset(dev, gpio_sim_sysfs_remove, chip);
>  }
>  
> -static int gpio_sim_dev_match_fwnode(struct device *dev, void *data)
> +static int gpio_sim_dev_match_fwnode(struct device *dev, const void *data)
>  {
>  	return device_match_fwnode(dev, data);
>  }
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index 0829ceb9967ca5d03509c52a559494d58776077b..4aeb393b58e636225ba3b529e4529f3028219e62 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -359,7 +359,7 @@ static const struct of_device_id mtk_drm_of_ids[] = {
>  };
>  MODULE_DEVICE_TABLE(of, mtk_drm_of_ids);
>  
> -static int mtk_drm_match(struct device *dev, void *data)
> +static int mtk_drm_match(struct device *dev, const void *data)
>  {
>  	if (!strncmp(dev_name(dev), "mediatek-drm", sizeof("mediatek-drm") - 1))
>  		return true;
> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index bbb9cc44e29fbc635706db5bed21f3b8a1cd4987..6552ee5186896e9290658a26d8f230849aacafa6 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -341,7 +341,7 @@ static int hwmon_attr_base(enum hwmon_sensor_types type)
>  
>  static DEFINE_MUTEX(hwmon_pec_mutex);
>  
> -static int hwmon_match_device(struct device *dev, void *data)
> +static int hwmon_match_device(struct device *dev, const void *data)
>  {
>  	return dev->class == &hwmon_class;
>  }
> diff --git a/drivers/media/pci/mgb4/mgb4_core.c b/drivers/media/pci/mgb4/mgb4_core.c
> index bc63dc81bcae0d20924174be74b93a2139d5879f..697d50bedfe285d74c702efde61e510df87c1229 100644
> --- a/drivers/media/pci/mgb4/mgb4_core.c
> +++ b/drivers/media/pci/mgb4/mgb4_core.c
> @@ -123,7 +123,7 @@ static const struct hwmon_chip_info temp_chip_info = {
>  };
>  #endif
>  
> -static int match_i2c_adap(struct device *dev, void *data)
> +static int match_i2c_adap(struct device *dev, const void *data)
>  {
>  	return i2c_verify_adapter(dev) ? 1 : 0;
>  }
> @@ -139,7 +139,7 @@ static struct i2c_adapter *get_i2c_adap(struct platform_device *pdev)
>  	return dev ? to_i2c_adapter(dev) : NULL;
>  }
>  
> -static int match_spi_adap(struct device *dev, void *data)
> +static int match_spi_adap(struct device *dev, const void *data)
>  {
>  	return to_spi_device(dev) ? 1 : 0;
>  }
> diff --git a/drivers/nvdimm/bus.c b/drivers/nvdimm/bus.c
> index 2237715e42eb32a14a4134746739a0df5ca27414..0ccf4a9e523a52ef52a96a339ecff0bcb51b214b 100644
> --- a/drivers/nvdimm/bus.c
> +++ b/drivers/nvdimm/bus.c
> @@ -1212,7 +1212,7 @@ enum nd_ioctl_mode {
>  	DIMM_IOCTL,
>  };
>  
> -static int match_dimm(struct device *dev, void *data)
> +static int match_dimm(struct device *dev, const void *data)
>  {
>  	long id = (long) data;
>  
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index 675b252d9c8ce74705ef245faae42e2c1330ed15..14144d0fa38e0c4e0bc34b9c929e127f1b2e96b6 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -1276,7 +1276,7 @@ static int pwm_export_child(struct device *pwmchip_dev, struct pwm_device *pwm)
>  	return 0;
>  }
>  
> -static int pwm_unexport_match(struct device *pwm_dev, void *data)
> +static int pwm_unexport_match(struct device *pwm_dev, const void *data)
>  {
>  	return pwm_from_dev(pwm_dev) == data;
>  }
> diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
> index 712c06c02696663821c8c884bcbd83036098899b..207b64c0a2fe9ccdb03b4ed66d1cee81e6f4c1ae 100644
> --- a/drivers/rpmsg/rpmsg_core.c
> +++ b/drivers/rpmsg/rpmsg_core.c
> @@ -377,9 +377,9 @@ EXPORT_SYMBOL(rpmsg_get_mtu);
>   * this is used to make sure we're not creating rpmsg devices for channels
>   * that already exist.
>   */
> -static int rpmsg_device_match(struct device *dev, void *data)
> +static int rpmsg_device_match(struct device *dev, const void *data)
>  {
> -	struct rpmsg_channel_info *chinfo = data;
> +	const struct rpmsg_channel_info *chinfo = data;
>  	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
>  
>  	if (chinfo->src != RPMSG_ADDR_ANY && chinfo->src != rpdev->src)
> diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
> index d91f54a6e752f2feb68da69f474375f1415f33a2..133f36457b283a53b4dca29adf081f385a371368 100644
> --- a/drivers/scsi/qla4xxx/ql4_os.c
> +++ b/drivers/scsi/qla4xxx/ql4_os.c
> @@ -7189,7 +7189,8 @@ static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,
>   *	1: if flashnode entry is non-persistent
>   *	0: if flashnode entry is persistent
>   **/
> -static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data)
> +static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev,
> +					       const void *data)
>  {
>  	struct iscsi_bus_flash_session *fnode_sess;
>  
> diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
> index fde7de3b1e55381f7cd468ad308a3e4ee9417c8c..0d474de2d960a865c52c9e7253f173d70ddd8f16 100644
> --- a/drivers/scsi/scsi_transport_iscsi.c
> +++ b/drivers/scsi/scsi_transport_iscsi.c
> @@ -1324,7 +1324,7 @@ EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);
>   *  1 on success
>   *  0 on failure
>   */
> -static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)
> +static int iscsi_is_flashnode_conn_dev(struct device *dev, const void *data)
>  {
>  	return dev->bus == &iscsi_flashnode_bus;
>  }
> @@ -1335,7 +1335,7 @@ static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn)
>  	return 0;
>  }
>  
> -static int flashnode_match_index(struct device *dev, void *data)
> +static int flashnode_match_index(struct device *dev, const void *data)
>  {
>  	struct iscsi_bus_flash_session *fnode_sess = NULL;
>  	int ret = 0;
> @@ -1344,7 +1344,7 @@ static int flashnode_match_index(struct device *dev, void *data)
>  		goto exit_match_index;
>  
>  	fnode_sess = iscsi_dev_to_flash_session(dev);
> -	ret = (fnode_sess->target_id == *((int *)data)) ? 1 : 0;
> +	ret = (fnode_sess->target_id == *((const int *)data)) ? 1 : 0;
>  
>  exit_match_index:
>  	return ret;
> @@ -1389,8 +1389,8 @@ iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx)
>   *  %NULL on failure
>   */
>  struct device *
> -iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
> -			  int (*fn)(struct device *dev, void *data))
> +iscsi_find_flashnode_sess(struct Scsi_Host *shost, const void *data,
> +			  device_match_t fn)
>  {
>  	return device_find_child(&shost->shost_gendev, data, fn);
>  }
> diff --git a/drivers/slimbus/core.c b/drivers/slimbus/core.c
> index b5d5bbb9fdb6614ffd578f5754226b50e394f0df..ab927fd077cb4fe1e29c004269fe52b2896c302f 100644
> --- a/drivers/slimbus/core.c
> +++ b/drivers/slimbus/core.c
> @@ -337,9 +337,9 @@ static bool slim_eaddr_equal(const struct slim_eaddr *a,
>  		a->instance == b->instance);
>  }
>  
> -static int slim_match_dev(struct device *dev, void *data)
> +static int slim_match_dev(struct device *dev, const void *data)
>  {
> -	struct slim_eaddr *e_addr = data;
> +	const struct slim_eaddr *e_addr = data;
>  	struct slim_device *sbdev = to_slim_device(dev);
>  
>  	return slim_eaddr_equal(&sbdev->e_addr, e_addr);
> @@ -385,9 +385,9 @@ struct slim_device *slim_get_device(struct slim_controller *ctrl,
>  }
>  EXPORT_SYMBOL_GPL(slim_get_device);
>  
> -static int of_slim_match_dev(struct device *dev, void *data)
> +static int of_slim_match_dev(struct device *dev, const void *data)
>  {
> -	struct device_node *np = data;
> +	const struct device_node *np = data;
>  	struct slim_device *sbdev = to_slim_device(dev);
>  
>  	return (sbdev->dev.of_node == np);
> diff --git a/drivers/thunderbolt/retimer.c b/drivers/thunderbolt/retimer.c
> index 89d2919d0193e8f5c68e669d054f3efc7abf78c8..21d2902c6102f0f593fb0c6d645acaff31ebb274 100644
> --- a/drivers/thunderbolt/retimer.c
> +++ b/drivers/thunderbolt/retimer.c
> @@ -461,7 +461,7 @@ struct tb_retimer_lookup {
>  	u8 index;
>  };
>  
> -static int retimer_match(struct device *dev, void *data)
> +static int retimer_match(struct device *dev, const void *data)
>  {
>  	const struct tb_retimer_lookup *lookup = data;
>  	struct tb_retimer *rt = tb_to_retimer(dev);
> diff --git a/drivers/thunderbolt/xdomain.c b/drivers/thunderbolt/xdomain.c
> index 11a50c86a1e4302968f44dafeab47977bac01dd5..b0630e6d94726f9069c20017876ec7e212071686 100644
> --- a/drivers/thunderbolt/xdomain.c
> +++ b/drivers/thunderbolt/xdomain.c
> @@ -1026,7 +1026,7 @@ static int remove_missing_service(struct device *dev, void *data)
>  	return 0;
>  }
>  
> -static int find_service(struct device *dev, void *data)
> +static int find_service(struct device *dev, const void *data)
>  {
>  	const struct tb_property *p = data;
>  	struct tb_service *svc;
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 74fa02b237729931928b2ae4902c699ec017af94..8e0aa2c76d4037047a16f6c631eccaa066d8f230 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -2365,9 +2365,9 @@ struct uart_match {
>  	struct uart_driver *driver;
>  };
>  
> -static int serial_match_port(struct device *dev, void *data)
> +static int serial_match_port(struct device *dev, const void *data)
>  {
> -	struct uart_match *match = data;
> +	const struct uart_match *match = data;
>  	struct tty_driver *tty_drv = match->driver->tty_driver;
>  	dev_t devt = MKDEV(tty_drv->major, tty_drv->minor_start) +
>  		match->port->line;
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 4b3047e055a3737d3eb841e00fc976a70f8c9c3e..601a81aa1e1024265f2359393dee531a7779c6ea 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -229,10 +229,10 @@ static const char * const usb_modes[] = {
>  /* ------------------------------------------------------------------------- */
>  /* Alternate Modes */
>  
> -static int altmode_match(struct device *dev, void *data)
> +static int altmode_match(struct device *dev, const void *data)
>  {
>  	struct typec_altmode *adev = to_typec_altmode(dev);
> -	struct typec_device_id *id = data;
> +	const struct typec_device_id *id = data;
>  
>  	if (!is_typec_altmode(dev))
>  		return 0;
> @@ -1282,7 +1282,7 @@ const struct device_type typec_cable_dev_type = {
>  	.release = typec_cable_release,
>  };
>  
> -static int cable_match(struct device *dev, void *data)
> +static int cable_match(struct device *dev, const void *data)
>  {
>  	return is_typec_cable(dev);
>  }
> @@ -2028,7 +2028,7 @@ const struct device_type typec_port_dev_type = {
>  /* --------------------------------------- */
>  /* Driver callbacks to report role updates */
>  
> -static int partner_match(struct device *dev, void *data)
> +static int partner_match(struct device *dev, const void *data)
>  {
>  	return is_typec_partner(dev);
>  }
> diff --git a/include/linux/device.h b/include/linux/device.h
> index 667cb6db9019349c9db0233acf9e78ff6a6d9625..0e0bc9bfe0d15a8734bf3d34106300f4df6b5364 100644
> --- a/include/linux/device.h
> +++ b/include/linux/device.h
> @@ -1081,8 +1081,8 @@ int device_for_each_child_reverse(struct device *dev, void *data,
>  int device_for_each_child_reverse_from(struct device *parent,
>  				       struct device *from, const void *data,
>  				       int (*fn)(struct device *, const void *));
> -struct device *device_find_child(struct device *dev, void *data,
> -				 int (*match)(struct device *dev, void *data));
> +struct device *device_find_child(struct device *dev, const void *data,
> +				 device_match_t match);
>  struct device *device_find_child_by_name(struct device *parent,
>  					 const char *name);
>  struct device *device_find_any_child(struct device *parent);
> diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
> index bd1243657c019962853849b07fc2ae190ec3b557..4d3baf324900f4b2b1ff3a5724b7ca7d122dc468 100644
> --- a/include/scsi/scsi_transport_iscsi.h
> +++ b/include/scsi/scsi_transport_iscsi.h
> @@ -497,8 +497,8 @@ extern void iscsi_destroy_all_flashnode(struct Scsi_Host *shost);
>  extern int iscsi_flashnode_bus_match(struct device *dev,
>  				     const struct device_driver *drv);
>  extern struct device *
> -iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,
> -			  int (*fn)(struct device *dev, void *data));
> +iscsi_find_flashnode_sess(struct Scsi_Host *shost, const void *data,
> +			  device_match_t fn);
>  extern struct device *
>  iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess);
>  
> diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
> index 5a7c0e565a894545ee14f0e0186ed3c46b809b16..e827775baf2ee1d0e1c0ce5807c2cca5c372fc75 100644
> --- a/net/dsa/dsa.c
> +++ b/net/dsa/dsa.c
> @@ -1367,7 +1367,7 @@ static int dsa_switch_parse_of(struct dsa_switch *ds, struct device_node *dn)
>  	return dsa_switch_parse_ports_of(ds, dn);
>  }
>  
> -static int dev_is_class(struct device *dev, void *class)
> +static int dev_is_class(struct device *dev, const void *class)
>  {
>  	if (dev->class != NULL && !strcmp(dev->class->name, class))
>  		return 1;
> diff --git a/tools/testing/cxl/test/cxl.c b/tools/testing/cxl/test/cxl.c
> index d0337c11f9ee675b0c461c8ae28e50957dc644ce..cc8948f49117a98086b3ef2ea7a8de0ce1ec36a5 100644
> --- a/tools/testing/cxl/test/cxl.c
> +++ b/tools/testing/cxl/test/cxl.c
> @@ -725,7 +725,7 @@ static void default_mock_decoder(struct cxl_decoder *cxld)
>  	cxld->reset = mock_decoder_reset;
>  }
>  
> -static int first_decoder(struct device *dev, void *data)
> +static int first_decoder(struct device *dev, const void *data)
>  {
>  	struct cxl_decoder *cxld;
>  
> 
> -- 
> 2.34.1
> 
> 

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

* Re: [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name()
  2024-12-11  0:08 ` [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name() Zijun Hu
  2024-12-23 20:23   ` Jonathan Cameron
@ 2025-01-02 18:17   ` Fan Ni
  2025-01-03  0:29     ` Zijun Hu
  1 sibling, 1 reply; 32+ messages in thread
From: Fan Ni @ 2025-01-02 18:17 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield

On Wed, Dec 11, 2024 at 08:08:03AM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> Simplify nd_namespace_store() implementation by
> using device_find_child_by_name().
> 
> Reviewed-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/nvdimm/claim.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
> 
> diff --git a/drivers/nvdimm/claim.c b/drivers/nvdimm/claim.c
> index 030dbde6b0882050c90fb8db106ec15b1baef7ca..9e84ab411564f9d5e7ceb687c6491562564552e3 100644
> --- a/drivers/nvdimm/claim.c
> +++ b/drivers/nvdimm/claim.c
> @@ -67,13 +67,6 @@ bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
>  	return claimed;
>  }
>  
> -static int namespace_match(struct device *dev, void *data)
> -{
> -	char *name = data;
> -
> -	return strcmp(name, dev_name(dev)) == 0;
> -}
> -
>  static bool is_idle(struct device *dev, struct nd_namespace_common *ndns)
>  {
>  	struct nd_region *nd_region = to_nd_region(dev->parent);
> @@ -168,7 +161,7 @@ ssize_t nd_namespace_store(struct device *dev,
>  		goto out;
>  	}
>  
> -	found = device_find_child(dev->parent, name, namespace_match);
> +	found = device_find_child_by_name(dev->parent, name);

Looks good to me.
Just one general question.
The function device_find_child checks parent and parent->p, but
device_find_child_by_name only checks parent although they share the
code except the match function. Why that?

Fan
>  	if (!found) {
>  		dev_dbg(dev, "'%s' not found under %s\n", name,
>  				dev_name(dev->parent));
> 
> -- 
> 2.34.1
> 

-- 
Fan Ni (From gmail)

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

* Re: [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name()
  2025-01-02 18:17   ` Fan Ni
@ 2025-01-03  0:29     ` Zijun Hu
  0 siblings, 0 replies; 32+ messages in thread
From: Zijun Hu @ 2025-01-03  0:29 UTC (permalink / raw)
  To: Fan Ni
  Cc: Greg Kroah-Hartman, Linus Walleij, Bartosz Golaszewski,
	Uwe Kleine-König, James Bottomley, Thomas Weißschuh,
	linux-kernel, nvdimm, linux-sound, sparclinux, linux-block,
	linux-cxl, linux1394-devel, arm-scmi, linux-efi, linux-gpio,
	dri-devel, linux-mediatek, linux-hwmon, linux-media, linux-pwm,
	linux-remoteproc, linux-scsi, linux-usb, linux-serial, netdev,
	Zijun Hu, Alison Schofield

On 2025/1/3 02:17, Fan Ni wrote:
>> -
>>  static bool is_idle(struct device *dev, struct nd_namespace_common *ndns)
>>  {
>>  	struct nd_region *nd_region = to_nd_region(dev->parent);
>> @@ -168,7 +161,7 @@ ssize_t nd_namespace_store(struct device *dev,
>>  		goto out;
>>  	}
>>  
>> -	found = device_find_child(dev->parent, name, namespace_match);
>> +	found = device_find_child_by_name(dev->parent, name);
> Looks good to me.
> Just one general question.
> The function device_find_child checks parent and parent->p, but
> device_find_child_by_name only checks parent although they share the
> code except the match function. Why that?
> 

Thank you Fan for code review.

I did not touch device_find_child_by_name() parameter checking at
that time.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=903c44939abc02e2f3d6f2ad65fa090f7e5df5b6

since
[PATCH v5 05/12] will come finally.
https://lore.kernel.org/all/20241224-const_dfc_done-v5-5-6623037414d4@quicinc.com/


> Fan


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

end of thread, other threads:[~2025-01-03  0:29 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-11  0:08 [PATCH v4 00/11] driver core: Constify API device_find_child() Zijun Hu
2024-12-11  0:08 ` [PATCH v4 01/11] libnvdimm: Replace namespace_match() with device_find_child_by_name() Zijun Hu
2024-12-23 20:23   ` Jonathan Cameron
2025-01-02 18:17   ` Fan Ni
2025-01-03  0:29     ` Zijun Hu
2024-12-11  0:08 ` [PATCH v4 02/11] slimbus: core: Constify slim_eaddr_equal() Zijun Hu
2024-12-23 20:25   ` Jonathan Cameron
2024-12-11  0:08 ` [PATCH v4 03/11] bus: fsl-mc: Constify fsl_mc_device_match() Zijun Hu
2024-12-23 20:26   ` Jonathan Cameron
2024-12-24 12:36     ` Zijun Hu
2024-12-11  0:08 ` [PATCH v4 04/11] driver core: Constify API device_find_child() then adapt for various usages Zijun Hu
2024-12-23  7:30   ` Uwe Kleine-König
2024-12-23 20:33   ` Jonathan Cameron
2024-12-24 12:47     ` Zijun Hu
2025-01-02 17:07   ` Mathieu Poirier
2024-12-11  0:08 ` [PATCH v4 05/11] driver core: Simplify API device_find_child_by_name() implementation Zijun Hu
2024-12-23 20:39   ` Jonathan Cameron
2024-12-24 12:55     ` Zijun Hu
2024-12-11  0:08 ` [PATCH v4 06/11] driver core: Remove match_any() Zijun Hu
2024-12-23 20:40   ` Jonathan Cameron
2024-12-11  0:08 ` [PATCH v4 07/11] slimbus: core: Remove of_slim_match_dev() Zijun Hu
2024-12-23 20:44   ` Jonathan Cameron
2024-12-11  0:08 ` [PATCH v4 08/11] gpio: sim: Remove gpio_sim_dev_match_fwnode() Zijun Hu
2024-12-11  8:18   ` Bartosz Golaszewski
2024-12-23 20:45   ` Jonathan Cameron
2024-12-11  0:08 ` [PATCH v4 09/11] driver core: Introduce an device matching API device_match_type() Zijun Hu
2024-12-23 20:46   ` Jonathan Cameron
2024-12-11  0:08 ` [PATCH v4 10/11] cxl/pmem: Replace match_nvdimm_bridge() with " Zijun Hu
2024-12-23 20:48   ` Jonathan Cameron
2024-12-24 12:58     ` Zijun Hu
2024-12-11  0:08 ` [PATCH v4 11/11] usb: typec: class: Remove both cable_match() and partner_match() Zijun Hu
2024-12-23 20:52   ` Jonathan Cameron

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).