Commit 1332661e authored by Miaoqian Lin's avatar Miaoqian Lin Committed by Krzysztof Kozlowski

memory: samsung: exynos5422-dmc: Fix refcount leak in of_get_dram_timings

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: 6e7674c3 ("memory: Add DMC driver for Exynos5422")
Signed-off-by: default avatarMiaoqian Lin <linmq006@gmail.com>
Reviewed-by: default avatarLukasz Luba <lukasz.luba@arm.com>
Link: https://lore.kernel.org/r/20220602041721.64348-1-linmq006@gmail.comSigned-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
parent 038ae37c
...@@ -1187,33 +1187,39 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc) ...@@ -1187,33 +1187,39 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
dmc->timing_row = devm_kmalloc_array(dmc->dev, TIMING_COUNT, dmc->timing_row = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
sizeof(u32), GFP_KERNEL); sizeof(u32), GFP_KERNEL);
if (!dmc->timing_row) if (!dmc->timing_row) {
return -ENOMEM; ret = -ENOMEM;
goto put_node;
}
dmc->timing_data = devm_kmalloc_array(dmc->dev, TIMING_COUNT, dmc->timing_data = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
sizeof(u32), GFP_KERNEL); sizeof(u32), GFP_KERNEL);
if (!dmc->timing_data) if (!dmc->timing_data) {
return -ENOMEM; ret = -ENOMEM;
goto put_node;
}
dmc->timing_power = devm_kmalloc_array(dmc->dev, TIMING_COUNT, dmc->timing_power = devm_kmalloc_array(dmc->dev, TIMING_COUNT,
sizeof(u32), GFP_KERNEL); sizeof(u32), GFP_KERNEL);
if (!dmc->timing_power) if (!dmc->timing_power) {
return -ENOMEM; ret = -ENOMEM;
goto put_node;
}
dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dmc->dev, dmc->timings = of_lpddr3_get_ddr_timings(np_ddr, dmc->dev,
DDR_TYPE_LPDDR3, DDR_TYPE_LPDDR3,
&dmc->timings_arr_size); &dmc->timings_arr_size);
if (!dmc->timings) { if (!dmc->timings) {
of_node_put(np_ddr);
dev_warn(dmc->dev, "could not get timings from DT\n"); 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); dmc->min_tck = of_lpddr3_get_min_tck(np_ddr, dmc->dev);
if (!dmc->min_tck) { if (!dmc->min_tck) {
of_node_put(np_ddr);
dev_warn(dmc->dev, "could not get tck from DT\n"); 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 */ /* Sorted array of OPPs with frequency ascending */
...@@ -1227,13 +1233,14 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc) ...@@ -1227,13 +1233,14 @@ static int of_get_dram_timings(struct exynos5_dmc *dmc)
clk_period_ps); clk_period_ps);
} }
of_node_put(np_ddr);
/* Take the highest frequency's timings as 'bypass' */ /* Take the highest frequency's timings as 'bypass' */
dmc->bypass_timing_row = dmc->timing_row[idx - 1]; dmc->bypass_timing_row = dmc->timing_row[idx - 1];
dmc->bypass_timing_data = dmc->timing_data[idx - 1]; dmc->bypass_timing_data = dmc->timing_data[idx - 1];
dmc->bypass_timing_power = dmc->timing_power[idx - 1]; dmc->bypass_timing_power = dmc->timing_power[idx - 1];
put_node:
of_node_put(np_ddr);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment