memory: of: Fix refcount leak bug in of_get_ddr_timings()
authorLiang He <windhl@126.com>
Tue, 19 Jul 2022 08:56:39 +0000 (16:56 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 10:34:58 +0000 (12:34 +0200)
[ Upstream commit 05215fb32010d4afb68fbdbb4d237df6e2d4567b ]

We should add the of_node_put() when breaking out of
for_each_child_of_node() as it will automatically increase
and decrease the refcount.

Fixes: e6b42eb6a66c ("memory: emif: add device tree support to emif driver")
Signed-off-by: Liang He <windhl@126.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20220719085640.1210583-1-windhl@126.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/memory/of_memory.c

index d9f5437..d0a80ae 100644 (file)
@@ -134,6 +134,7 @@ const struct lpddr2_timings *of_get_ddr_timings(struct device_node *np_ddr,
        for_each_child_of_node(np_ddr, np_tim) {
                if (of_device_is_compatible(np_tim, tim_compat)) {
                        if (of_do_get_timings(np_tim, &timings[i])) {
        for_each_child_of_node(np_ddr, np_tim) {
                if (of_device_is_compatible(np_tim, tim_compat)) {
                        if (of_do_get_timings(np_tim, &timings[i])) {
+                               of_node_put(np_tim);
                                devm_kfree(dev, timings);
                                goto default_timings;
                        }
                                devm_kfree(dev, timings);
                                goto default_timings;
                        }