Skip to contentSkip to conversation

clk: qcom: Allocate space for NULL terimation in DFS table

PATCH Applied Douglas Anderson 2 participants 2 messages Aug 30, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: qcom: Allocate space for NULL terimation in DFS table

The table allocated in clk_rcg2_dfs_populate_freq_table() is eventually iterated over by qcom_find_freq() which assumes that the table is NULL terminated. Allocate one extra space in the array for the NULL termination. Initting of the NULL termination is implicit due to kcalloc().

Fixes cc4f6944d0e3 ("clk: qcom: Add support for RCG to register for DFS")

---

 drivers/clk/qcom/clk-rcg2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/qcom/clk-rcg2.c +2 -1
index d5d77f9ad170..6e3bd195d012 100644
@@ -993,7 +993,8 @@ static int clk_rcg2_dfs_populate_freq_table(struct clk_rcg2 *rcg)
 	struct freq_tbl *freq_tbl;
 	int i;
 
-	freq_tbl = kcalloc(MAX_PERF_LEVEL, sizeof(*freq_tbl), GFP_KERNEL);
+	/* Allocate space for 1 extra since table is NULL terminated */
+	freq_tbl = kcalloc(MAX_PERF_LEVEL + 1, sizeof(*freq_tbl), GFP_KERNEL);
 	if (!freq_tbl)
 		return -ENOMEM;
 	rcg->freq_tbl = freq_tbl;
Signature · 1 line
2.19.0.rc0.228.g281dcd1b4d0-goog
maintainer Applied
#1 lore raw

Quoting Douglas Anderson (2018-08-30 10:34:37)

Quoted 9 lines

The table allocated in clk_rcg2_dfs_populate_freq_table() is eventually iterated over by qcom_find_freq() which assumes that the table is NULL terminated. Allocate one extra space in the array for the NULL termination. Initting of the NULL termination is implicit due to kcalloc().

Fixes cc4f6944d0e3 ("clk: qcom: Add support for RCG to register for DFS")

---

Applied to clk-next