Patch "pinctrl: core: fix possible memory leak when pinctrl_enable() fails" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    pinctrl: core: fix possible memory leak when pinctrl_enable() fails

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     pinctrl-core-fix-possible-memory-leak-when-pinctrl_e.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit df50956b4d6ae20f89f1966a05244ce21001ea06
Author: Yang Yingliang <yangyingliang@xxxxxxxxxx>
Date:   Thu Jun 6 10:37:02 2024 +0800

    pinctrl: core: fix possible memory leak when pinctrl_enable() fails
    
    [ Upstream commit ae1cf4759972c5fe665ee4c5e0c29de66fe3cf4a ]
    
    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.
    
    Introduce pinctrl_uninit_controller(), call it in the error path to free memory.
    
    Fixes: 5038a66dad01 ("pinctrl: core: delete incorrect free in pinctrl_enable()")
    Signed-off-by: Yang Yingliang <yangyingliang@xxxxxxxxxx>
    Reviewed-by: Dan Carpenter <dan.carpenter@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20240606023704.3931561-2-yangyingliang@xxxxxxxxxx
    Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index f567805cbde8e..8f4cc52b2a066 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -2062,6 +2062,14 @@ pinctrl_init_controller(struct pinctrl_desc *pctldesc, struct device *dev,
 	return ERR_PTR(ret);
 }
 
+static void pinctrl_uninit_controller(struct pinctrl_dev *pctldev, struct pinctrl_desc *pctldesc)
+{
+	pinctrl_free_pindescs(pctldev, pctldesc->pins,
+			      pctldesc->npins);
+	mutex_destroy(&pctldev->mutex);
+	kfree(pctldev);
+}
+
 static int pinctrl_claim_hogs(struct pinctrl_dev *pctldev)
 {
 	pctldev->p = create_pinctrl(pctldev->dev, pctldev);
@@ -2142,8 +2150,10 @@ struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
 		return pctldev;
 
 	error = pinctrl_enable(pctldev);
-	if (error)
+	if (error) {
+		pinctrl_uninit_controller(pctldev, pctldesc);
 		return ERR_PTR(error);
+	}
 
 	return pctldev;
 }




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux