[PATCH] pinctrl: single: Fix memleak in pcs_dt_node_to_map
Linus Walleij
linus.walleij at linaro.org
Tue Jul 4 02:18:55 PDT 2023
On Mon, Jul 3, 2023 at 10:24 AM Guo Mengqi <guomengqi3 at huawei.com> wrote:
> In a reliability test which repeatedly load and remove a module,
> I found some kmalloc-256 memory leaks in pinctrl-single.
>
> pcs_dt_node_to_map() will recognize a dt_node and
> make a mapping for it. Along the way some pinctrl functions and groups
> are registered in pinctrl-single controller. These functions/groups are
> registered once and not removed during the system lifetime.
>
> When the client module loads again, pcs_dt_node_to_map() fail to consider
> this situation, create the same set of resources, and does not release or
> use them.
>
> To fix this, add a check at the start of pcs_parse_one_pinctrl_entry/
> pcs_parse_bits_in_pinctrl_entry. If the target is found,
> then all the resource allocation and parsing work can be skipped,
> just set the mapping with existing function/group information.
>
> Fixes: 8b8b091bf07f ("pinctrl: Add one-register-per-pin type device tree
> based pinctrl driver")
>
> Signed-off-by: Guo Mengqi <guomengqi3 at huawei.com>
Good catch!
I expect Tony to review the patch in-depth.
> -static int pinmux_func_name_to_selector(struct pinctrl_dev *pctldev,
> +int pinmux_func_name_to_selector(struct pinctrl_dev *pctldev,
> const char *function)
> {
> const struct pinmux_ops *ops = pctldev->desc->pmxops;
It appears you need to add EXPORT_SYMBOL_GPL() for this function
so the module can build. (This is why the build robot complains.)
Yours,
Linus Walleij
More information about the linux-arm-kernel
mailing list