Skip to content

Commit 83e1bca

Browse files
gscuilinusw
authored andcommitted
pinctrl: thunderbay: fix possible memory leak in thunderbay_build_functions()
The thunderbay_add_functions() will free memory of thunderbay_funcs when everything is ok, but thunderbay_funcs will not be freed when thunderbay_add_functions() fails, then there will be a memory leak, so we need to add kfree() when thunderbay_add_functions() fails to fix it. In addition, doing some cleaner works, moving kfree(funcs) from thunderbay_add_functions() to thunderbay_build_functions(). Fixes: 12422af ("pinctrl: Add Intel Thunder Bay pinctrl driver") Signed-off-by: Gaosheng Cui <[email protected]> Reviewed-by: Rafał Miłecki <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 80b99ed commit 83e1bca

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

drivers/pinctrl/pinctrl-thunderbay.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ static int thunderbay_add_functions(struct thunderbay_pinctrl *tpc, struct funct
808808
funcs[i].num_group_names,
809809
funcs[i].data);
810810
}
811-
kfree(funcs);
811+
812812
return 0;
813813
}
814814

@@ -817,6 +817,7 @@ static int thunderbay_build_functions(struct thunderbay_pinctrl *tpc)
817817
struct function_desc *thunderbay_funcs;
818818
void *ptr;
819819
int pin;
820+
int ret;
820821

821822
/*
822823
* Allocate maximum possible number of functions. Assume every pin
@@ -860,7 +861,10 @@ static int thunderbay_build_functions(struct thunderbay_pinctrl *tpc)
860861
return -ENOMEM;
861862

862863
thunderbay_funcs = ptr;
863-
return thunderbay_add_functions(tpc, thunderbay_funcs);
864+
ret = thunderbay_add_functions(tpc, thunderbay_funcs);
865+
866+
kfree(thunderbay_funcs);
867+
return ret;
864868
}
865869

866870
static int thunderbay_pinconf_set_tristate(struct thunderbay_pinctrl *tpc,

0 commit comments

Comments
 (0)