gpio: dwapb: switch to device_for_each_child_node_scoped()

Switch to device_for_each_child_node_scoped() to simplify the code by
removing the need for a  call to fwnode_handle_put() in the error path.

This also prevents possible memory leaks if new error paths are added
without the required call to fwnode_handle_put().

Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Serge Semin <fancer.lancer@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240928-gpio_device_for_each_child_node_scoped-v1-1-c20eff315f4f@gmail.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
Javier Carrasco 2024-09-28 21:47:35 +02:00 committed by Bartosz Golaszewski
parent f53ab43553
commit 0a53be8e08

View File

@ -571,7 +571,6 @@ static void dwapb_get_irq(struct device *dev, struct fwnode_handle *fwnode,
static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev) static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev)
{ {
struct fwnode_handle *fwnode;
struct dwapb_platform_data *pdata; struct dwapb_platform_data *pdata;
struct dwapb_port_property *pp; struct dwapb_port_property *pp;
int nports; int nports;
@ -592,7 +591,7 @@ static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev)
pdata->nports = nports; pdata->nports = nports;
i = 0; i = 0;
device_for_each_child_node(dev, fwnode) { device_for_each_child_node_scoped(dev, fwnode) {
pp = &pdata->properties[i++]; pp = &pdata->properties[i++];
pp->fwnode = fwnode; pp->fwnode = fwnode;
@ -600,7 +599,6 @@ static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev)
pp->idx >= DWAPB_MAX_PORTS) { pp->idx >= DWAPB_MAX_PORTS) {
dev_err(dev, dev_err(dev,
"missing/invalid port index for port%d\n", i); "missing/invalid port index for port%d\n", i);
fwnode_handle_put(fwnode);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }