Re: [PATCH] pinctrl: thunderbay: fix possible memory leak in thunderbay_add_functions()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 29.11.2022 11:58, Gaosheng Cui wrote:
The memory of funcs is allocated by thunderbay_build_functions(),
thunderbay_add_functions() will free funcs when everything is ok,
but it will not be freed when thunderbay_add_functions() fails,
then there will be a memory leak, so add kfree() when
thunderbay_add_functions() fails to fix it.

Fixes: 25d2e41cf59b ("pinctrl: thunderbay: rework loops looking for groups names")
Signed-off-by: Gaosheng Cui <cuigaosheng1@xxxxxxxxxx>
---
  drivers/pinctrl/pinctrl-thunderbay.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/pinctrl/pinctrl-thunderbay.c b/drivers/pinctrl/pinctrl-thunderbay.c
index 9328b17485cf..10a7380af8e6 100644
--- a/drivers/pinctrl/pinctrl-thunderbay.c
+++ b/drivers/pinctrl/pinctrl-thunderbay.c
@@ -784,8 +784,10 @@ static int thunderbay_add_functions(struct thunderbay_pinctrl *tpc, struct funct
group_names = devm_kcalloc(tpc->dev, func->num_group_names,
  					   sizeof(*group_names), GFP_KERNEL);
-		if (!group_names)
+		if (!group_names) {
+			kfree(funcs);
  			return -ENOMEM;
+		}
for (j = 0; j < tpc->soc->npins; j++) {
  			const struct pinctrl_pin_desc *pin_info = &thunderbay_pins[j];

I'm wondering if moving that kfree(funcs) to the caller
(thunderbay_build_functions()) would make code a bit cleaner.

If you take a look at thunderbay_build_functions() it takes care of
allocating and reallocating so maybe kfree() should belong there too?



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux