Message ID | 20240928-gpio_device_for_each_child_node_scoped-v1-2-c20eff315f4f@gmail.com |
---|---|
State | New |
Headers | show |
Series | gpio: switch to device_for_each_chilld_node_scoped() | expand |
On Sat, Sep 28, 2024 at 09:47:36PM +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>
diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index dcca1d7f173e..f387dad81f29 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -520,15 +520,12 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev) static int gpio_sim_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct fwnode_handle *swnode; int ret; - device_for_each_child_node(dev, swnode) { + device_for_each_child_node_scoped(dev, swnode) { ret = gpio_sim_add_bank(swnode, dev); - if (ret) { - fwnode_handle_put(swnode); + if (ret) return ret; - } } return 0;
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-sim.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)