mbox series

[0/3] pinctrl: fix possible memory leak when pinctrl_enable() fails

Message ID 20240605073827.3380584-1-yangyingliang@huawei.com
Headers show
Series pinctrl: fix possible memory leak when pinctrl_enable() fails | expand

Message

Yang Yingliang June 5, 2024, 7:38 a.m. UTC
In devm_pinctrl_register(), if pinctrl_enable() fails in pinctrl_register(),
the "pctldev" has not been added to dev resources, so devm_pinctrl_dev_release()
can not be called, it leads memory leak.

And some driver calls pinctrl_register_and_init() which is not devm_ managed,
it also leads memory leak if pinctrl_enable() fails.

To fix this, introduce pinctrl_uninit_controller(), call it in the error path to
free memory and replace pinctrl_register_and_init with devm_pinctrl_register_and_init.


Yang Yingliang (3):
  pinctrl: core: fix possible memory leak when pinctrl_enable() fails
  pinctrl: single: fix possible memory leak when pinctrl_enable() fails
  pinctrl: ti: ti-iodelay: fix possible memory leak when
    pinctrl_enable() fails

 drivers/pinctrl/core.c                  | 12 +++++++++++-
 drivers/pinctrl/pinctrl-single.c        |  3 +--
 drivers/pinctrl/ti/pinctrl-ti-iodelay.c | 11 ++++++-----
 3 files changed, 18 insertions(+), 8 deletions(-)

Comments

Dan Carpenter June 5, 2024, 8:40 a.m. UTC | #1
On Wed, Jun 05, 2024 at 03:38:26PM +0800, Yang Yingliang wrote:
> @@ -1879,7 +1878,7 @@ static int pcs_probe(struct platform_device *pdev)
>  	if (ret < 0)
>  		goto free;
>  
> -	ret = pinctrl_register_and_init(&pcs->desc, pcs->dev, pcs, &pcs->pctl);
> +	ret = devm_pinctrl_register_and_init(pcs->dev, &pcs->desc, pcs, &pcs->pctl);
>  	if (ret) {
>  		dev_err(pcs->dev, "could not register single pinctrl driver\n");
>  		goto free;

Could you add a check in this function for if pinctrl_enable() fails?

regards,
dan carpenter