Patch "gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data()" has been added to the 5.4-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

    gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data()

to the 5.4-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:
     gpio-gpiolib-of-fix-refcount-bugs-in-of_mm_gpiochip_.patch
and it can be found in the queue-5.4 subdirectory.

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



commit f994b259e7ea9ab3fef589a92772267b3721f864
Author: Liang He <windhl@xxxxxxx>
Date:   Mon Jul 11 20:52:38 2022 +0800

    gpio: gpiolib-of: Fix refcount bugs in of_mm_gpiochip_add_data()
    
    [ Upstream commit 5d07a692f9562f9c06e62cce369e9dd108173a0f ]
    
    We should use of_node_get() when a new reference of device_node
    is created. It is noted that the old reference stored in
    'mm_gc->gc.of_node' should also be decreased.
    
    This patch is based on the fact that there is a call site in function
    'qe_add_gpiochips()' of src file 'drivers\soc\fsl\qe\gpio.c'. In this
    function, of_mm_gpiochip_add_data() is contained in an iteration of
    for_each_compatible_node() which will automatically increase and
    decrease the refcount. So we need additional of_node_get() for the
    reference escape in of_mm_gpiochip_add_data().
    
    Fixes: a19e3da5bc5f ("of/gpio: Kill of_gpio_chip and add members directly to gpio_chip")
    Signed-off-by: Liang He <windhl@xxxxxxx>
    Signed-off-by: Bartosz Golaszewski <brgl@xxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index b1dcd2dd52e6..73807c897391 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -734,7 +734,8 @@ int of_mm_gpiochip_add_data(struct device_node *np,
 	if (mm_gc->save_regs)
 		mm_gc->save_regs(mm_gc);
 
-	mm_gc->gc.of_node = np;
+	of_node_put(mm_gc->gc.of_node);
+	mm_gc->gc.of_node = of_node_get(np);
 
 	ret = gpiochip_add_data(gc, data);
 	if (ret)
@@ -742,6 +743,7 @@ int of_mm_gpiochip_add_data(struct device_node *np,
 
 	return 0;
 err2:
+	of_node_put(np);
 	iounmap(mm_gc->regs);
 err1:
 	kfree(gc->label);



[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