提交 a77b124a 编写于 作者: L Liang He 提交者: Zheng Zengkai

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

stable inclusion
from stable-v5.10.137
commit 26975d8ea96b478897f8cb91a9bc2395d7f3393c
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60PLB

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=26975d8ea96b478897f8cb91a9bc2395d7f3393c

--------------------------------

[ Upstream commit 5d07a692 ]

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: a19e3da5 ("of/gpio: Kill of_gpio_chip and add members directly to gpio_chip")
Signed-off-by: NLiang He <windhl@126.com>
Signed-off-by: NBartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 a79db264
...@@ -863,7 +863,8 @@ int of_mm_gpiochip_add_data(struct device_node *np, ...@@ -863,7 +863,8 @@ int of_mm_gpiochip_add_data(struct device_node *np,
if (mm_gc->save_regs) if (mm_gc->save_regs)
mm_gc->save_regs(mm_gc); 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); ret = gpiochip_add_data(gc, data);
if (ret) if (ret)
...@@ -871,6 +872,7 @@ int of_mm_gpiochip_add_data(struct device_node *np, ...@@ -871,6 +872,7 @@ int of_mm_gpiochip_add_data(struct device_node *np,
return 0; return 0;
err2: err2:
of_node_put(np);
iounmap(mm_gc->regs); iounmap(mm_gc->regs);
err1: err1:
kfree(gc->label); kfree(gc->label);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册