]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
pinctrl: keembay: release allocated memory in detach path
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 2 Sep 2025 11:59:17 +0000 (13:59 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Nov 2025 20:34:04 +0000 (15:34 -0500)
[ Upstream commit aae7a2876c3b39d07aa7655ea082af8e7862f3a5 ]

Unlike all the other allocations in this driver, the memory for storing
the pin function descriptions allocated with kcalloc() and later resized
with krealloc() is never freed. Use devres like elsewhere to handle
that. While at it - replace krealloc() with more suitable
devm_krealloc_array().

Note: the logic in this module is pretty convoluted and could probably
use some revisiting, we should probably be able to calculate the exact
amount of memory needed in advance or even skip the allocation
altogether and just add each function to the radix tree separately.

Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/pinctrl/pinctrl-keembay.c

index b693f4787044cef7afd355248dcaa64e98612e29..b1124d3e50bff77161187b929d55b8a7295db423 100644 (file)
@@ -1606,7 +1606,8 @@ static int keembay_build_functions(struct keembay_pinctrl *kpc)
         * being part of 8 (hw maximum) globally unique muxes.
         */
        kpc->nfuncs = 0;
-       keembay_funcs = kcalloc(kpc->npins * 8, sizeof(*keembay_funcs), GFP_KERNEL);
+       keembay_funcs = devm_kcalloc(kpc->dev, kpc->npins * 8,
+                                    sizeof(*keembay_funcs), GFP_KERNEL);
        if (!keembay_funcs)
                return -ENOMEM;
 
@@ -1637,7 +1638,9 @@ static int keembay_build_functions(struct keembay_pinctrl *kpc)
        }
 
        /* Reallocate memory based on actual number of functions */
-       new_funcs = krealloc(keembay_funcs, kpc->nfuncs * sizeof(*new_funcs), GFP_KERNEL);
+       new_funcs = devm_krealloc_array(kpc->dev, keembay_funcs,
+                                       kpc->nfuncs, sizeof(*new_funcs),
+                                       GFP_KERNEL);
        if (!new_funcs) {
                kfree(keembay_funcs);
                return -ENOMEM;