Message ID | 20240928-gpio_device_for_each_child_node_scoped-v1-1-c20eff315f4f@gmail.com (mailing list archive) |
---|---|
State | Handled Elsewhere, archived |
Headers | show |
Series | gpio: switch to device_for_each_chilld_node_scoped() | expand |
On Sat, Sep 28, 2024 at 09:47:35PM +0200, Javier Carrasco wrote: > 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(). Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
On Sat, Sep 28, 2024 at 09:47:35PM GMT, Javier Carrasco wrote: > 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> Acked-by: Serge Semin <fancer.lancer@gmail.com> -Serge(y) > --- > drivers/gpio/gpio-dwapb.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c > index 798235791f70..bd374fc27174 100644 > --- a/drivers/gpio/gpio-dwapb.c > +++ b/drivers/gpio/gpio-dwapb.c > @@ -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) > { > - struct fwnode_handle *fwnode; > struct dwapb_platform_data *pdata; > struct dwapb_port_property *pp; > int nports; > @@ -592,7 +591,7 @@ static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev) > pdata->nports = nports; > > i = 0; > - device_for_each_child_node(dev, fwnode) { > + device_for_each_child_node_scoped(dev, fwnode) { > pp = &pdata->properties[i++]; > pp->fwnode = fwnode; > > @@ -600,7 +599,6 @@ static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev) > pp->idx >= DWAPB_MAX_PORTS) { > dev_err(dev, > "missing/invalid port index for port%d\n", i); > - fwnode_handle_put(fwnode); > return ERR_PTR(-EINVAL); > } > > > -- > 2.43.0 >
On Sat, Sep 28, 2024 at 9:47 PM Javier Carrasco <javier.carrasco.cruz@gmail.com> wrote: > 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> Neat. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij
diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 798235791f70..bd374fc27174 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c @@ -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) { - struct fwnode_handle *fwnode; struct dwapb_platform_data *pdata; struct dwapb_port_property *pp; int nports; @@ -592,7 +591,7 @@ static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev) pdata->nports = nports; i = 0; - device_for_each_child_node(dev, fwnode) { + device_for_each_child_node_scoped(dev, fwnode) { pp = &pdata->properties[i++]; pp->fwnode = fwnode; @@ -600,7 +599,6 @@ static struct dwapb_platform_data *dwapb_gpio_get_pdata(struct device *dev) pp->idx >= DWAPB_MAX_PORTS) { dev_err(dev, "missing/invalid port index for port%d\n", i); - fwnode_handle_put(fwnode); return ERR_PTR(-EINVAL); }
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> --- drivers/gpio/gpio-dwapb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)