* [PATCH v2 1/3] coresight: cti: use device_* to iterate over device child nodes
2024-08-08 15:12 [PATCH v2 0/3] use device_for_each_child_node_scoped to access device child nodes Javier Carrasco
@ 2024-08-08 15:12 ` Javier Carrasco
2024-08-19 10:34 ` Mike Leach
2024-08-08 15:12 ` [PATCH v2 2/3] iio: adc: xilinx-ams: " Javier Carrasco
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Javier Carrasco @ 2024-08-08 15:12 UTC (permalink / raw)
To: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
Anand Ashok Dumbre, Michal Simek, Sakari Ailus, Pavel Machek,
Lee Jones
Cc: coresight, linux-arm-kernel, linux-kernel, linux-iio, linux-leds,
Javier Carrasco
Drop the manual access to the fwnode of the device to iterate over its
child nodes. `device_for_each_child_node` macro provides direct access
to the child nodes, and given that they are only required within the
loop, the scoped variant of the macro can be used.
Use the `device_for_each_child_node_scoped` macro to iterate over the
direct child nodes of the device.
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/hwtracing/coresight/coresight-cti-platform.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c
index ccef04f27f12..d0ae10bf6128 100644
--- a/drivers/hwtracing/coresight/coresight-cti-platform.c
+++ b/drivers/hwtracing/coresight/coresight-cti-platform.c
@@ -416,20 +416,16 @@ static int cti_plat_create_impdef_connections(struct device *dev,
struct cti_drvdata *drvdata)
{
int rc = 0;
- struct fwnode_handle *fwnode = dev_fwnode(dev);
- struct fwnode_handle *child = NULL;
- if (IS_ERR_OR_NULL(fwnode))
+ if (IS_ERR_OR_NULL(dev_fwnode(dev)))
return -EINVAL;
- fwnode_for_each_child_node(fwnode, child) {
+ device_for_each_child_node_scoped(dev, child) {
if (cti_plat_node_name_eq(child, CTI_DT_CONNS))
- rc = cti_plat_create_connection(dev, drvdata,
- child);
+ rc = cti_plat_create_connection(dev, drvdata, child);
if (rc != 0)
break;
}
- fwnode_handle_put(child);
return rc;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 1/3] coresight: cti: use device_* to iterate over device child nodes
2024-08-08 15:12 ` [PATCH v2 1/3] coresight: cti: use device_* to iterate over " Javier Carrasco
@ 2024-08-19 10:34 ` Mike Leach
0 siblings, 0 replies; 8+ messages in thread
From: Mike Leach @ 2024-08-19 10:34 UTC (permalink / raw)
To: Javier Carrasco
Cc: Suzuki K Poulose, James Clark, Alexander Shishkin,
Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
Anand Ashok Dumbre, Michal Simek, Sakari Ailus, Pavel Machek,
Lee Jones, coresight, linux-arm-kernel, linux-kernel, linux-iio,
linux-leds
On Thu, 8 Aug 2024 at 16:12, Javier Carrasco
<javier.carrasco.cruz@gmail.com> wrote:
>
> Drop the manual access to the fwnode of the device to iterate over its
> child nodes. `device_for_each_child_node` macro provides direct access
> to the child nodes, and given that they are only required within the
> loop, the scoped variant of the macro can be used.
>
> Use the `device_for_each_child_node_scoped` macro to iterate over the
> direct child nodes of the device.
>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> drivers/hwtracing/coresight/coresight-cti-platform.c | 10 +++-------
> 1 file changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers/hwtracing/coresight/coresight-cti-platform.c
> index ccef04f27f12..d0ae10bf6128 100644
> --- a/drivers/hwtracing/coresight/coresight-cti-platform.c
> +++ b/drivers/hwtracing/coresight/coresight-cti-platform.c
> @@ -416,20 +416,16 @@ static int cti_plat_create_impdef_connections(struct device *dev,
> struct cti_drvdata *drvdata)
> {
> int rc = 0;
> - struct fwnode_handle *fwnode = dev_fwnode(dev);
> - struct fwnode_handle *child = NULL;
>
> - if (IS_ERR_OR_NULL(fwnode))
> + if (IS_ERR_OR_NULL(dev_fwnode(dev)))
> return -EINVAL;
>
> - fwnode_for_each_child_node(fwnode, child) {
> + device_for_each_child_node_scoped(dev, child) {
> if (cti_plat_node_name_eq(child, CTI_DT_CONNS))
> - rc = cti_plat_create_connection(dev, drvdata,
> - child);
> + rc = cti_plat_create_connection(dev, drvdata, child);
> if (rc != 0)
> break;
> }
> - fwnode_handle_put(child);
>
> return rc;
> }
>
> --
> 2.43.0
>
Reviewed-by: Mike Leach <mike.leach@linaro.org>
--
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 2/3] iio: adc: xilinx-ams: use device_* to iterate over device child nodes
2024-08-08 15:12 [PATCH v2 0/3] use device_for_each_child_node_scoped to access device child nodes Javier Carrasco
2024-08-08 15:12 ` [PATCH v2 1/3] coresight: cti: use device_* to iterate over " Javier Carrasco
@ 2024-08-08 15:12 ` Javier Carrasco
2024-08-10 10:38 ` Jonathan Cameron
2024-08-08 15:12 ` [PATCH v2 3/3] leds: as3645a: " Javier Carrasco
2024-08-19 14:33 ` [PATCH v2 0/3] use device_for_each_child_node_scoped to access " Suzuki K Poulose
3 siblings, 1 reply; 8+ messages in thread
From: Javier Carrasco @ 2024-08-08 15:12 UTC (permalink / raw)
To: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
Anand Ashok Dumbre, Michal Simek, Sakari Ailus, Pavel Machek,
Lee Jones
Cc: coresight, linux-arm-kernel, linux-kernel, linux-iio, linux-leds,
Javier Carrasco
Use `device_for_each_child_node_scoped()` in `ams_parse_firmware()`
to explicitly state device child node access, and simplify the child
node handling as it is not required outside the loop.
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/iio/adc/xilinx-ams.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c
index f051358d6b50..ebc583b07e0c 100644
--- a/drivers/iio/adc/xilinx-ams.c
+++ b/drivers/iio/adc/xilinx-ams.c
@@ -1275,7 +1275,6 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
struct ams *ams = iio_priv(indio_dev);
struct iio_chan_spec *ams_channels, *dev_channels;
struct device *dev = indio_dev->dev.parent;
- struct fwnode_handle *child = NULL;
struct fwnode_handle *fwnode = dev_fwnode(dev);
size_t ams_size;
int ret, ch_cnt = 0, i, rising_off, falling_off;
@@ -1297,16 +1296,12 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
num_channels += ret;
}
- fwnode_for_each_child_node(fwnode, child) {
- if (fwnode_device_is_available(child)) {
- ret = ams_init_module(indio_dev, child, ams_channels + num_channels);
- if (ret < 0) {
- fwnode_handle_put(child);
- return ret;
- }
+ device_for_each_child_node_scoped(dev, child) {
+ ret = ams_init_module(indio_dev, child, ams_channels + num_channels);
+ if (ret < 0)
+ return ret;
- num_channels += ret;
- }
+ num_channels += ret;
}
for (i = 0; i < num_channels; i++) {
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 2/3] iio: adc: xilinx-ams: use device_* to iterate over device child nodes
2024-08-08 15:12 ` [PATCH v2 2/3] iio: adc: xilinx-ams: " Javier Carrasco
@ 2024-08-10 10:38 ` Jonathan Cameron
0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Cameron @ 2024-08-10 10:38 UTC (permalink / raw)
To: Javier Carrasco
Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
Michael Hennerich, Lars-Peter Clausen, Anand Ashok Dumbre,
Michal Simek, Sakari Ailus, Pavel Machek, Lee Jones, coresight,
linux-arm-kernel, linux-kernel, linux-iio, linux-leds
On Thu, 08 Aug 2024 17:12:38 +0200
Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote:
> Use `device_for_each_child_node_scoped()` in `ams_parse_firmware()`
> to explicitly state device child node access, and simplify the child
> node handling as it is not required outside the loop.
>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
One follow up question for those familiar with the driver.
Why do we check if the main device is available?
if (fwnode_device_is_available(fwnode)) {
ret = ams_init_module(indio_dev, fwnode, ams_channels);
if (ret < 0)
return ret;
num_channels += ret;
}
How is the platform device driver probed if it's not available?
Jonathan
> ---
> drivers/iio/adc/xilinx-ams.c | 15 +++++----------
> 1 file changed, 5 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/adc/xilinx-ams.c b/drivers/iio/adc/xilinx-ams.c
> index f051358d6b50..ebc583b07e0c 100644
> --- a/drivers/iio/adc/xilinx-ams.c
> +++ b/drivers/iio/adc/xilinx-ams.c
> @@ -1275,7 +1275,6 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
> struct ams *ams = iio_priv(indio_dev);
> struct iio_chan_spec *ams_channels, *dev_channels;
> struct device *dev = indio_dev->dev.parent;
> - struct fwnode_handle *child = NULL;
> struct fwnode_handle *fwnode = dev_fwnode(dev);
> size_t ams_size;
> int ret, ch_cnt = 0, i, rising_off, falling_off;
> @@ -1297,16 +1296,12 @@ static int ams_parse_firmware(struct iio_dev *indio_dev)
> num_channels += ret;
> }
>
> - fwnode_for_each_child_node(fwnode, child) {
> - if (fwnode_device_is_available(child)) {
> - ret = ams_init_module(indio_dev, child, ams_channels + num_channels);
> - if (ret < 0) {
> - fwnode_handle_put(child);
> - return ret;
> - }
> + device_for_each_child_node_scoped(dev, child) {
> + ret = ams_init_module(indio_dev, child, ams_channels + num_channels);
> + if (ret < 0)
> + return ret;
>
> - num_channels += ret;
> - }
> + num_channels += ret;
> }
>
> for (i = 0; i < num_channels; i++) {
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v2 3/3] leds: as3645a: use device_* to iterate over device child nodes
2024-08-08 15:12 [PATCH v2 0/3] use device_for_each_child_node_scoped to access device child nodes Javier Carrasco
2024-08-08 15:12 ` [PATCH v2 1/3] coresight: cti: use device_* to iterate over " Javier Carrasco
2024-08-08 15:12 ` [PATCH v2 2/3] iio: adc: xilinx-ams: " Javier Carrasco
@ 2024-08-08 15:12 ` Javier Carrasco
2024-08-16 16:08 ` Lee Jones
2024-08-19 14:33 ` [PATCH v2 0/3] use device_for_each_child_node_scoped to access " Suzuki K Poulose
3 siblings, 1 reply; 8+ messages in thread
From: Javier Carrasco @ 2024-08-08 15:12 UTC (permalink / raw)
To: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
Anand Ashok Dumbre, Michal Simek, Sakari Ailus, Pavel Machek,
Lee Jones
Cc: coresight, linux-arm-kernel, linux-kernel, linux-iio, linux-leds,
Javier Carrasco
Drop the manual access to the fwnode of the device to iterate over its
child nodes. `device_for_each_child_node` macro provides direct access
to the child nodes, and given that the `child` variable is only required
within the loop, the scoped variant of the macro can be used.
Use the `device_for_each_child_node_scoped` macro to iterate over the
direct child nodes of the device.
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
drivers/leds/flash/leds-as3645a.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/leds/flash/leds-as3645a.c b/drivers/leds/flash/leds-as3645a.c
index 2c6ef321b7c8..8e6abedf6e00 100644
--- a/drivers/leds/flash/leds-as3645a.c
+++ b/drivers/leds/flash/leds-as3645a.c
@@ -478,14 +478,12 @@ static int as3645a_detect(struct as3645a *flash)
return as3645a_write(flash, AS_BOOST_REG, AS_BOOST_CURRENT_DISABLE);
}
-static int as3645a_parse_node(struct as3645a *flash,
- struct fwnode_handle *fwnode)
+static int as3645a_parse_node(struct as3645a *flash, struct device *dev)
{
struct as3645a_config *cfg = &flash->cfg;
- struct fwnode_handle *child;
int rval;
- fwnode_for_each_child_node(fwnode, child) {
+ device_for_each_child_node_scoped(dev, child) {
u32 id = 0;
fwnode_property_read_u32(child, "reg", &id);
@@ -686,7 +684,7 @@ static int as3645a_probe(struct i2c_client *client)
flash->client = client;
- rval = as3645a_parse_node(flash, dev_fwnode(&client->dev));
+ rval = as3645a_parse_node(flash, &client->dev);
if (rval < 0)
return rval;
--
2.43.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH v2 3/3] leds: as3645a: use device_* to iterate over device child nodes
2024-08-08 15:12 ` [PATCH v2 3/3] leds: as3645a: " Javier Carrasco
@ 2024-08-16 16:08 ` Lee Jones
0 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2024-08-16 16:08 UTC (permalink / raw)
To: Javier Carrasco
Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
Michael Hennerich, Lars-Peter Clausen, Jonathan Cameron,
Anand Ashok Dumbre, Michal Simek, Sakari Ailus, Pavel Machek,
coresight, linux-arm-kernel, linux-kernel, linux-iio, linux-leds
On Thu, 08 Aug 2024, Javier Carrasco wrote:
> Drop the manual access to the fwnode of the device to iterate over its
> child nodes. `device_for_each_child_node` macro provides direct access
> to the child nodes, and given that the `child` variable is only required
> within the loop, the scoped variant of the macro can be used.
>
> Use the `device_for_each_child_node_scoped` macro to iterate over the
> direct child nodes of the device.
>
> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
> ---
> drivers/leds/flash/leds-as3645a.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/leds/flash/leds-as3645a.c b/drivers/leds/flash/leds-as3645a.c
> index 2c6ef321b7c8..8e6abedf6e00 100644
> --- a/drivers/leds/flash/leds-as3645a.c
> +++ b/drivers/leds/flash/leds-as3645a.c
> @@ -478,14 +478,12 @@ static int as3645a_detect(struct as3645a *flash)
> return as3645a_write(flash, AS_BOOST_REG, AS_BOOST_CURRENT_DISABLE);
> }
>
> -static int as3645a_parse_node(struct as3645a *flash,
> - struct fwnode_handle *fwnode)
> +static int as3645a_parse_node(struct as3645a *flash, struct device *dev)
Please swap the parameters to have the more senior one (dev) at the start.
> {
> struct as3645a_config *cfg = &flash->cfg;
> - struct fwnode_handle *child;
> int rval;
>
> - fwnode_for_each_child_node(fwnode, child) {
> + device_for_each_child_node_scoped(dev, child) {
> u32 id = 0;
>
> fwnode_property_read_u32(child, "reg", &id);
> @@ -686,7 +684,7 @@ static int as3645a_probe(struct i2c_client *client)
>
> flash->client = client;
>
> - rval = as3645a_parse_node(flash, dev_fwnode(&client->dev));
> + rval = as3645a_parse_node(flash, &client->dev);
> if (rval < 0)
> return rval;
>
>
> --
> 2.43.0
>
>
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v2 0/3] use device_for_each_child_node_scoped to access device child nodes
2024-08-08 15:12 [PATCH v2 0/3] use device_for_each_child_node_scoped to access device child nodes Javier Carrasco
` (2 preceding siblings ...)
2024-08-08 15:12 ` [PATCH v2 3/3] leds: as3645a: " Javier Carrasco
@ 2024-08-19 14:33 ` Suzuki K Poulose
3 siblings, 0 replies; 8+ messages in thread
From: Suzuki K Poulose @ 2024-08-19 14:33 UTC (permalink / raw)
To: Michal Simek, Michael Hennerich, James Clark, Javier Carrasco,
Lars-Peter Clausen, Pavel Machek, Mike Leach, Sakari Ailus,
Anand Ashok Dumbre, Alexander Shishkin, Lee Jones,
Jonathan Cameron
Cc: Suzuki K Poulose, linux-kernel, coresight, linux-iio,
linux-arm-kernel, linux-leds
On Thu, 08 Aug 2024 17:12:36 +0200, Javier Carrasco wrote:
> This series removes accesses to the device `fwnode` to iterate over its
> own child nodes. Using the `device_for_each_child_node` macro provides
> direct access to the device child nodes, and given that in all cases
> they are only required within the loop, the scoped variant of the macro
> can be used.
>
> It has been stated in previous discussions [1] that `device_for_each_*`
> should be used to access device child nodes, removing the need to access
> its internal fwnode, and restricting `fwnode_for_each_*` to traversing
> subnodes when required.
>
> [...]
Applied, to coresight next tree. Thanks!
[1/3] coresight: cti: use device_* to iterate over device child nodes
https://git.kernel.org/coresight/c/daca644d0c9e0
Best regards,
--
Suzuki K Poulose <suzuki.poulose@arm.com>
^ permalink raw reply [flat|nested] 8+ messages in thread