public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] use device_for_each_child_node_scoped to access device child nodes
@ 2024-08-20 19:02 Javier Carrasco
  2024-08-20 19:02 ` [PATCH v3 1/2] iio: adc: xilinx-ams: use device_* to iterate over " Javier Carrasco
  2024-08-20 19:02 ` [PATCH v3 2/2] leds: as3645a: " Javier Carrasco
  0 siblings, 2 replies; 6+ messages in thread
From: Javier Carrasco @ 2024-08-20 19:02 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

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.

Note that `device_for_each_*` implies availability, which means that
after this conversion, unavailable nodes will not be accessible within
the loop. The affected drivers does not seem to have any reason to
iterate over unavailable nodes, though. But if someone has a case where
the affected drivers might require accessing unavailable nodes, please
let me know.

Link: https://lore.kernel.org/linux-hwmon/cffb5885-3cbc-480c-ab6d-4a442d1afb8a@gmail.com/ [1]
Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
---
Changes in v3:
- leds-as3645a: swap the parameters in as3645a_parse_node() to have dev
  at the beginning.
- Rebase onto next-20240820, drop upstreamed patches (changes for
  coresight-cti-platform).
- Link to v2: https://lore.kernel.org/r/20240808-device_child_node_access-v2-0-fc757cc76650@gmail.com

Changes in v2:
- Rebase onto next-20240808, drop upstreamed patches (changes for ad7768-1)
- xilinx-ams.c: drop fwnode_device_is_available(child) (implicit in the
  loop).
- Link to v1: https://lore.kernel.org/r/20240801-device_child_node_access-v1-0-ddfa21bef6f2@gmail.com

---
Javier Carrasco (2):
      iio: adc: xilinx-ams: use device_* to iterate over device child nodes
      leds: as3645a: use device_* to iterate over device child nodes

 drivers/iio/adc/xilinx-ams.c      | 15 +++++----------
 drivers/leds/flash/leds-as3645a.c |  8 +++-----
 2 files changed, 8 insertions(+), 15 deletions(-)
---
base-commit: bb1b0acdcd66e0d8eedee3570d249e076b89ab32
change-id: 20240725-device_child_node_access-442533910a6f

Best regards,
-- 
Javier Carrasco <javier.carrasco.cruz@gmail.com>


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

* [PATCH v3 1/2] iio: adc: xilinx-ams: use device_* to iterate over device child nodes
  2024-08-20 19:02 [PATCH v3 0/2] use device_for_each_child_node_scoped to access device child nodes Javier Carrasco
@ 2024-08-20 19:02 ` Javier Carrasco
  2024-08-26 10:52   ` Jonathan Cameron
  2024-08-20 19:02 ` [PATCH v3 2/2] leds: as3645a: " Javier Carrasco
  1 sibling, 1 reply; 6+ messages in thread
From: Javier Carrasco @ 2024-08-20 19:02 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] 6+ messages in thread

* [PATCH v3 2/2] leds: as3645a: use device_* to iterate over device child nodes
  2024-08-20 19:02 [PATCH v3 0/2] use device_for_each_child_node_scoped to access device child nodes Javier Carrasco
  2024-08-20 19:02 ` [PATCH v3 1/2] iio: adc: xilinx-ams: use device_* to iterate over " Javier Carrasco
@ 2024-08-20 19:02 ` Javier Carrasco
  2024-08-22 13:36   ` (subset) " Lee Jones
  1 sibling, 1 reply; 6+ messages in thread
From: Javier Carrasco @ 2024-08-20 19:02 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..2f2d783c62c3 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 device *dev, struct as3645a *flash)
 {
 	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(&client->dev, flash);
 	if (rval < 0)
 		return rval;
 

-- 
2.43.0


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

* Re: (subset) [PATCH v3 2/2] leds: as3645a: use device_* to iterate over device child nodes
  2024-08-20 19:02 ` [PATCH v3 2/2] leds: as3645a: " Javier Carrasco
@ 2024-08-22 13:36   ` Lee Jones
  0 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2024-08-22 13:36 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, Javier Carrasco
  Cc: coresight, linux-arm-kernel, linux-kernel, linux-iio, linux-leds

On Tue, 20 Aug 2024 21:02:27 +0200, 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.
> 
> [...]

Applied, thanks!

[2/2] leds: as3645a: use device_* to iterate over device child nodes
      commit: 1041e1d4f061e65a3c47cff34709864293f07284

--
Lee Jones [李琼斯]


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

* Re: [PATCH v3 1/2] iio: adc: xilinx-ams: use device_* to iterate over device child nodes
  2024-08-20 19:02 ` [PATCH v3 1/2] iio: adc: xilinx-ams: use device_* to iterate over " Javier Carrasco
@ 2024-08-26 10:52   ` Jonathan Cameron
  2024-08-26 11:15     ` Michal Simek
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Cameron @ 2024-08-26 10:52 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 Tue, 20 Aug 2024 21:02:26 +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>
Applied, but I would ideally still like one of the xilinx folk
others familiar with this driver to take a look.  It'll be a
few days before this ends up in next anyway as I need to rebase
after Greg (hopefully) takes the pull request from last week.

It would be lovely to get rid of the direct fwnode usage
in here but I'm not 100% sure if there is a path that will land
on a disabled fwnode.

Thanks,

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] 6+ messages in thread

* Re: [PATCH v3 1/2] iio: adc: xilinx-ams: use device_* to iterate over device child nodes
  2024-08-26 10:52   ` Jonathan Cameron
@ 2024-08-26 11:15     ` Michal Simek
  0 siblings, 0 replies; 6+ messages in thread
From: Michal Simek @ 2024-08-26 11:15 UTC (permalink / raw)
  To: Jonathan Cameron, Javier Carrasco, O'Griofa, Conall
  Cc: Suzuki K Poulose, Mike Leach, James Clark, Alexander Shishkin,
	Michael Hennerich, Lars-Peter Clausen, Anand Ashok Dumbre,
	Sakari Ailus, Pavel Machek, Lee Jones, coresight,
	linux-arm-kernel, linux-kernel, linux-iio, linux-leds

Hi Jonathan,

On 8/26/24 12:52, Jonathan Cameron wrote:
> On Tue, 20 Aug 2024 21:02:26 +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>
> Applied, but I would ideally still like one of the xilinx folk
> others familiar with this driver to take a look.  It'll be a
> few days before this ends up in next anyway as I need to rebase
> after Greg (hopefully) takes the pull request from last week.

I just get back from vacation.

> 
> It would be lovely to get rid of the direct fwnode usage
> in here but I'm not 100% sure if there is a path that will land
> on a disabled fwnode.

Conall: Please take a look at this and test it.

Thanks,
Michal


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

end of thread, other threads:[~2024-08-26 11:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-20 19:02 [PATCH v3 0/2] use device_for_each_child_node_scoped to access device child nodes Javier Carrasco
2024-08-20 19:02 ` [PATCH v3 1/2] iio: adc: xilinx-ams: use device_* to iterate over " Javier Carrasco
2024-08-26 10:52   ` Jonathan Cameron
2024-08-26 11:15     ` Michal Simek
2024-08-20 19:02 ` [PATCH v3 2/2] leds: as3645a: " Javier Carrasco
2024-08-22 13:36   ` (subset) " Lee Jones

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