Re: [PATCH] pinctrl: pinctrl-generic-mux: Fix provider resource leak on re-parse
From: Chancel Liu
Date: Tue Sep 22 2026 - 06:31:09 EST
On 9/18/2026 5:02 AM, Frank Li wrote:
> On Wed, Sep 16, 2026 at 12:04:35PM +0900, Chancel Liu wrote:
>> From: Chancel Liu <chancel.liu@xxxxxxx>
>>
> ...
>>
>> +static int mux_pinctrl_probe_dt(struct pinctrl_dev *pctldev,
>> + struct device_node *np)
>> +{
>> + struct device *dev = pctldev->dev;
>> +
>> + for_each_available_child_of_node_scoped(np, grp) {
>> + struct mux_pin_function *function;
>> + const char **group_names;
>> + int ret;
>> +
>> + function = devm_kzalloc(dev, sizeof(*function), GFP_KERNEL);
>> + if (!function)
>> + return -ENOMEM;
>> +
>> + group_names = devm_kcalloc(dev, 1, sizeof(*group_names), GFP_KERNEL);
>> + if (!group_names)
>> + return -ENOMEM;
>> +
>> + group_names[0] = grp->name;
>> +
>> + function->mux_state = devm_mux_state_get_from_np(dev, NULL, grp);
>> + if (IS_ERR(function->mux_state))
>> + return dev_err_probe(dev, PTR_ERR(function->mux_state),
>> + "failed to get mux-state for %pOFn\n",
>> + grp);
>> +
>> + ret = pinctrl_generic_add_group(pctldev, grp->name, NULL, 0, NULL);
>> + if (ret < 0)
>> + return dev_err_probe(dev, ret,
>> + "failed to add group %pOFn\n", grp);
>> +
>> + ret = pinmux_generic_add_function(pctldev, grp->name, group_names,
>> + 1, function);
>> + if (ret < 0)
>> + return dev_err_probe(dev, ret,
>> + "failed to add function %pOFn\n", grp);
>> + }
>> +
>> + return 0;
>> +}
>
> This method also works, slice difference, if some pin have not used by
> consumer, old method may save some memory.
>
> leave to linus to decide which is better way, this one or add free() at
> .dt_free_map()
>
> Frank
IMHO, the groups and functions of a board-level mux are static and fully
described by the devicetree, so probe time is the natural place to build
them, and dt_node_to_map() can then focus on mapping. Happy to go with
whichever Linus prefers.
Regards,
Chancel Liu