* [PATCH] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings
@ 2022-06-02 4:17 Miaoqian Lin
2022-06-02 7:40 ` Lukasz Luba
2022-06-06 9:20 ` Krzysztof Kozlowski
0 siblings, 2 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-06-02 4:17 UTC (permalink / raw)
To: Lukasz Luba, Krzysztof Kozlowski, Alim Akhtar, linux-pm,
linux-samsung-soc, linux-kernel, linux-arm-kernel
Cc: linmq006
of_parse_phandle() returns a node pointer with refcount
incremented, we should use of_node_put() on it when not need anymore.
This function doesn't call of_node_put() in some error paths.
To unify the structure, Add put_node label and goto it on errors.
Fixes: 6e7674c3c6df ("memory: Add DMC driver for Exynos5422")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/memory/samsung/exynos5422-dmc.c | 29 +++++++++++++++----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/drivers/memory/samsung/exynos5422-dmc.c b/drivers/memory/samsung/exynos5422-dmc.c
index 4733e7898ffe..c491cd549644 100644
--- a/drivers/memory/samsung/exynos5422-dmc.c
+++ b/drivers/memory/samsung/exynos5422-dmc.c
@@ -1187,33 +1187,39 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
dmc->timing_row = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
sizeof(u32), GFP_KERNEL);
- if (!dmc->timing_row)
- return -ENOMEM;
+ if (!dmc->timing_row) {
+ ret = -ENOMEM;
+ goto put_node;
+ }
dmc->timing_data = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
sizeof(u32), GFP_KERNEL);
- if (!dmc->timing_data)
- return -ENOMEM;
+ if (!dmc->timing_data) {
+ ret = -ENOMEM;
+ goto put_node;
+ }
dmc->timing_power = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
sizeof(u32), GFP_KERNEL);
- if (!dmc->timing_power)
- return -ENOMEM;
+ if (!dmc->timing_power) {
+ ret = -ENOMEM;
+ goto put_node;
+ }
dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dmc->dev,
DDR_TYPE_LPDDR3,
&dmc->timings_arr_size);
if (!dmc->timings) {
- of_node_put(np_ddr);
dev_warn(dmc->dev, "could not get timings from DT\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto put_node;
}
dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dmc->dev);
if (!dmc->min_tck) {
- of_node_put(np_ddr);
dev_warn(dmc->dev, "could not get tck from DT\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto put_node;
}
/* Sorted array of OPPs with frequency ascending */
@@ -1227,13 +1233,14 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
clk_period_ps);
}
- of_node_put(np_ddr);
/* Take the highest frequency's timings as 'bypass' */
dmc->bypass_timing_row = dmc->timing_row[idx - 1];
dmc->bypass_timing_data = dmc->timing_data[idx - 1];
dmc->bypass_timing_power = dmc->timing_power[idx - 1];
+put_node:
+ of_node_put(np_ddr);
return ret;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings
2022-06-02 4:17 [PATCH] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings Miaoqian Lin
@ 2022-06-02 7:40 ` Lukasz Luba
2022-06-06 9:20 ` Krzysztof Kozlowski
1 sibling, 0 replies; 3+ messages in thread
From: Lukasz Luba @ 2022-06-02 7:40 UTC (permalink / raw)
To: Miaoqian Lin
Cc: Krzysztof Kozlowski, linux-pm, Alim Akhtar, linux-arm-kernel,
linux-kernel, linux-samsung-soc
On 6/2/22 05:17, Miaoqian Lin wrote:
> of_parse_phandle() returns a node pointer with refcount
> incremented, we should use of_node_put() on it when not need anymore.
> This function doesn't call of_node_put() in some error paths.
> To unify the structure, Add put_node label and goto it on errors.
>
> Fixes: 6e7674c3c6df ("memory: Add DMC driver for Exynos5422")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Thanks for the patch, LGTM.
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings
2022-06-02 4:17 [PATCH] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings Miaoqian Lin
2022-06-02 7:40 ` Lukasz Luba
@ 2022-06-06 9:20 ` Krzysztof Kozlowski
1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-06 9:20 UTC (permalink / raw)
To: Lukasz Luba, linux-samsung-soc, Miaoqian Lin, Alim Akhtar,
linux-arm-kernel, linux-pm, linux-kernel
Cc: Krzysztof Kozlowski
On Thu, 2 Jun 2022 08:17:21 +0400, Miaoqian Lin wrote:
> of_parse_phandle() returns a node pointer with refcount
> incremented, we should use of_node_put() on it when not need anymore.
> This function doesn't call of_node_put() in some error paths.
> To unify the structure, Add put_node label and goto it on errors.
>
>
Applied, thanks!
[1/1] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings
https://git.kernel.org/krzk/linux-mem-ctrl/c/1332661e09304b7b8e84e5edc11811ba08d12abe
Best regards,
--
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-06 9:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-02 4:17 [PATCH] memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings Miaoqian Lin
2022-06-02 7:40 ` Lukasz Luba
2022-06-06 9:20 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).