Switch to the _scoped() version introduced in commit 365130fd47af
("device property: Introduce device_for_each_child_node_scoped()")
to remove the need for manual calling of fwnode_handle_put() in the
paths where the code exits the loop early.
There are only two users of the non scoped version in the hwmon
subsystem:
- ltc2991
- gsc-hwmon
All calls of fwnode_handle_put() were in error paths.
This series is based on the master branch of linux-next (next-20240404)
to profif from the scoped version of device_for_each_child_node().
Signed-off-by: Javier Carrasco <[email protected]>
---
Javier Carrasco (2):
hwmon: (ltc2991) use device_for_each_child_node_scoped()
hwmon: (gsc-hwmon) use device_for_each_child_node_scoped()
drivers/hwmon/gsc-hwmon.c | 7 +------
drivers/hwmon/ltc2991.c | 11 +++--------
2 files changed, 4 insertions(+), 14 deletions(-)
---
base-commit: 2b3d5988ae2cb5cd945ddbc653f0a71706231fdd
change-id: 20240404-hwmon_device_for_each_child_node_scoped-6e581c1d8a31
Best regards,
--
Javier Carrasco <[email protected]>
Switch to the _scoped() version introduced in commit 365130fd47af
("device property: Introduce device_for_each_child_node_scoped()")
to remove the need for manual calling of fwnode_handle_put() in the
paths where the code exits the loop early.
Signed-off-by: Javier Carrasco <[email protected]>
---
drivers/hwmon/ltc2991.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)
diff --git a/drivers/hwmon/ltc2991.c b/drivers/hwmon/ltc2991.c
index 80a6e391f266..3286775de6e8 100644
--- a/drivers/hwmon/ltc2991.c
+++ b/drivers/hwmon/ltc2991.c
@@ -284,7 +284,6 @@ static const struct regmap_config ltc2991_regmap_config = {
static int ltc2991_init(struct ltc2991_state *st, struct device *dev)
{
- struct fwnode_handle *child;
int ret;
u32 val, addr;
u8 v5_v8_reg_data = 0, v1_v4_reg_data = 0;
@@ -294,17 +293,13 @@ static int ltc2991_init(struct ltc2991_state *st, struct device *dev)
return dev_err_probe(dev, ret,
"failed to enable regulator\n");
- device_for_each_child_node(dev, child) {
+ device_for_each_child_node_scoped(dev, child) {
ret = fwnode_property_read_u32(child, "reg", &addr);
- if (ret < 0) {
- fwnode_handle_put(child);
+ if (ret < 0)
return ret;
- }
- if (addr > 3) {
- fwnode_handle_put(child);
+ if (addr > 3)
return -EINVAL;
- }
ret = fwnode_property_read_u32(child,
"shunt-resistor-micro-ohms",
--
2.40.1
Switch to the _scoped() version introduced in commit 365130fd47af
("device property: Introduce device_for_each_child_node_scoped()")
to remove the need for manual calling of fwnode_handle_put() in the
paths where the code exits the loop early.
Signed-off-by: Javier Carrasco <[email protected]>
---
drivers/hwmon/gsc-hwmon.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/drivers/hwmon/gsc-hwmon.c b/drivers/hwmon/gsc-hwmon.c
index 1501ceb551e7..0f2147699c91 100644
--- a/drivers/hwmon/gsc-hwmon.c
+++ b/drivers/hwmon/gsc-hwmon.c
@@ -249,7 +249,6 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
{
struct gsc_hwmon_platform_data *pdata;
struct gsc_hwmon_channel *ch;
- struct fwnode_handle *child;
struct device_node *fan;
int nchannels;
@@ -276,25 +275,21 @@ gsc_hwmon_get_devtree_pdata(struct device *dev)
ch = pdata->channels;
/* allocate structures for channels and count instances of each type */
- device_for_each_child_node(dev, child) {
+ device_for_each_child_node_scoped(dev, child) {
if (fwnode_property_read_string(child, "label", &ch->name)) {
dev_err(dev, "channel without label\n");
- fwnode_handle_put(child);
return ERR_PTR(-EINVAL);
}
if (fwnode_property_read_u32(child, "reg", &ch->reg)) {
dev_err(dev, "channel without reg\n");
- fwnode_handle_put(child);
return ERR_PTR(-EINVAL);
}
if (fwnode_property_read_u32(child, "gw,mode", &ch->mode)) {
dev_err(dev, "channel without mode\n");
- fwnode_handle_put(child);
return ERR_PTR(-EINVAL);
}
if (ch->mode > mode_max) {
dev_err(dev, "invalid channel mode\n");
- fwnode_handle_put(child);
return ERR_PTR(-EINVAL);
}
--
2.40.1
On 04/04/2024 13:13, Javier Carrasco wrote:
> Switch to the _scoped() version introduced in commit 365130fd47af
> ("device property: Introduce device_for_each_child_node_scoped()")
> to remove the need for manual calling of fwnode_handle_put() in the
> paths where the code exits the loop early.
>
> There are only two users of the non scoped version in the hwmon
> subsystem:
>
> - ltc2991
> - gsc-hwmon
>
> All calls of fwnode_handle_put() were in error paths.
>
> This series is based on the master branch of linux-next (next-20240404)
> to profif from the scoped version of device_for_each_child_node().
>
> Signed-off-by: Javier Carrasco <[email protected]>
> ---
> Javier Carrasco (2):
> hwmon: (ltc2991) use device_for_each_child_node_scoped()
> hwmon: (gsc-hwmon) use device_for_each_child_node_scoped()
>
> drivers/hwmon/gsc-hwmon.c | 7 +------
> drivers/hwmon/ltc2991.c | 11 +++--------
> 2 files changed, 4 insertions(+), 14 deletions(-)
> ---
> base-commit: 2b3d5988ae2cb5cd945ddbc653f0a71706231fdd
> change-id: 20240404-hwmon_device_for_each_child_node_scoped-6e581c1d8a31
>
> Best regards,
Hi, this patch appears as "superseded" in the patchwork, but I could not
find what series actually superseded it.
I just noticed that the cleanup in ltc2991.c turns out to be a bug fix
as well because there is an error path if "shunt-resistor-micro-ohms" is
zero that misses the required fwnode_handle_put().
This is something similar like the recently applied fix for the ltc2992
[1], but in this case the _scoped() macro already exists and is in use
in the mainline kernel, and no explicit call to fwnode_handle_put() is
required unless the fix is to be ported to old kernels that don't have
the device_for_each_child_node_scoped() macro.
Link:
https://lore.kernel.org/linux-hwmon/20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@gmail.com/
[1]
Best regards,
Javier Carrasco
On Thu, Apr 04, 2024 at 01:13:27PM +0200, Javier Carrasco wrote:
> Switch to the _scoped() version introduced in commit 365130fd47af
> ("device property: Introduce device_for_each_child_node_scoped()")
> to remove the need for manual calling of fwnode_handle_put() in the
> paths where the code exits the loop early.
>
> Signed-off-by: Javier Carrasco <[email protected]>
Applied, and sorry for the confusion.
Guenter
On Thu, Apr 04, 2024 at 01:13:28PM +0200, Javier Carrasco wrote:
> Switch to the _scoped() version introduced in commit 365130fd47af
> ("device property: Introduce device_for_each_child_node_scoped()")
> to remove the need for manual calling of fwnode_handle_put() in the
> paths where the code exits the loop early.
>
> Signed-off-by: Javier Carrasco <[email protected]>
Applied.
Guenter
On 6/7/24 14:00, Javier Carrasco wrote:
> On 04/04/2024 13:13, Javier Carrasco wrote:
>> Switch to the _scoped() version introduced in commit 365130fd47af
>> ("device property: Introduce device_for_each_child_node_scoped()")
>> to remove the need for manual calling of fwnode_handle_put() in the
>> paths where the code exits the loop early.
>>
>> There are only two users of the non scoped version in the hwmon
>> subsystem:
>>
>> - ltc2991
>> - gsc-hwmon
>>
>> All calls of fwnode_handle_put() were in error paths.
>>
>> This series is based on the master branch of linux-next (next-20240404)
>> to profif from the scoped version of device_for_each_child_node().
>>
>> Signed-off-by: Javier Carrasco <[email protected]>
>> ---
>> Javier Carrasco (2):
>> hwmon: (ltc2991) use device_for_each_child_node_scoped()
>> hwmon: (gsc-hwmon) use device_for_each_child_node_scoped()
>>
>> drivers/hwmon/gsc-hwmon.c | 7 +------
>> drivers/hwmon/ltc2991.c | 11 +++--------
>> 2 files changed, 4 insertions(+), 14 deletions(-)
>> ---
>> base-commit: 2b3d5988ae2cb5cd945ddbc653f0a71706231fdd
>> change-id: 20240404-hwmon_device_for_each_child_node_scoped-6e581c1d8a31
>>
>> Best regards,
>
>
> Hi, this patch appears as "superseded" in the patchwork, but I could not
> find what series actually superseded it.
>
> I just noticed that the cleanup in ltc2991.c turns out to be a bug fix
> as well because there is an error path if "shunt-resistor-micro-ohms" is
> zero that misses the required fwnode_handle_put().
>
> This is something similar like the recently applied fix for the ltc2992
> [1], but in this case the _scoped() macro already exists and is in use
> in the mainline kernel, and no explicit call to fwnode_handle_put() is
> required unless the fix is to be ported to old kernels that don't have
> the device_for_each_child_node_scoped() macro.
>
> Link:
> https://lore.kernel.org/linux-hwmon/20240523-fwnode_for_each_available_child_node_scoped-v2-0-701f3a03f2fb@gmail.com/
> [1]
>
I strongly suspect I confused it with the other series introducing
fwnode_for_each_available_child_node_scoped(). Sorry for the confusion.
Guenter