[PATCH v5 06/12] gpio: regmap: fix memory leak of gpio_regmap structure

Ioana Ciornei posted 12 patches 1 week, 2 days ago
[PATCH v5 06/12] gpio: regmap: fix memory leak of gpio_regmap structure
Posted by Ioana Ciornei 1 week, 2 days ago
The gpio_regmap structure is leaked on the error path. Fix this by
jumping to the appropriate kfree instead of returning directly.

Fixes: db305161880a ("gpio: regmap: Allow ngpio to be read from the property")
Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
Suggested-by: Michael Walle <mwalle@kernel.org>
---
Changes in v5:
- new patch

 drivers/gpio/gpio-regmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index d9d23853e032..ab9e4077fa60 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -281,7 +281,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
 	if (!chip->ngpio) {
 		ret = gpiochip_get_ngpios(chip, chip->parent);
 		if (ret)
-			return ERR_PTR(ret);
+			goto err_free_gpio;
 	}
 
 	/* if not set, assume there is only one register */
-- 
2.25.1
Re: [PATCH v5 06/12] gpio: regmap: fix memory leak of gpio_regmap structure
Posted by Michael Walle 1 week, 2 days ago
> The gpio_regmap structure is leaked on the error path. Fix this by
> jumping to the appropriate kfree instead of returning directly.
>
> Fixes: db305161880a ("gpio: regmap: Allow ngpio to be read from the property")
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> Suggested-by: Michael Walle <mwalle@kernel.org>

Reviewed-by: Michael Walle <mwalle@kernel.org>