Skip to contentSkip to conversation

interconnect: icc-clk: Add missed num_nodes initialization

PATCH In review Kees Cook 2 participants 2 messages Jul 16, 2024 Interconnect API

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 interconnect: icc-clk: Add missed num_nodes initialization

With the new __counted_by annotation, the "num_nodes" struct member must be set before accessing the "nodes" array. This initialization was done in other places where a new struct icc_onecell_data is allocated, but this case in icc_clk_register() was missed. Set "num_nodes" after allocation.

Fixes dd4904f3b924 ("interconnect: qcom: Annotate struct icc_onecell_data with __counted_by")

---
Cc: Georgi Djakov <[email protected]>
Cc: [email protected]

---
 drivers/interconnect/icc-clk.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/interconnect/icc-clk.c +1 -2
index f788db15cd76..b956e4050f38 100644
@@ -87,6 +87,7 @@ struct icc_provider *icc_clk_register(struct device *dev,
 	onecell = devm_kzalloc(dev, struct_size(onecell, nodes, 2 * num_clocks), GFP_KERNEL);
 	if (!onecell)
 		return ERR_PTR(-ENOMEM);
+	onecell->num_nodes = 2 * num_clocks;
 
 	qp = devm_kzalloc(dev, struct_size(qp, clocks, num_clocks), GFP_KERNEL);
 	if (!qp)
@@ -133,8 +134,6 @@ struct icc_provider *icc_clk_register(struct device *dev,
 		onecell->nodes[j++] = node;
 	}
 
-	onecell->num_nodes = j;
-
 	ret = icc_provider_register(provider);
 	if (ret)
 		goto err;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Kees Cook

With the new __counted_by annotation, the "num_nodes" struct member must be set before accessing the "nodes" array. This initialization was done in other places where a new struct icc_onecell_data is allocated, but this case in icc_clk_register() was missed. Set "num_nodes" after allocation.

Fixes dd4904f3b924 ("interconnect: qcom: Annotate struct icc_onecell_data with __counted_by")

Thanks

Signature · 1 line
Gustavo
Quoted 28 lines

---
Cc: Georgi Djakov <[email protected]>
Cc: [email protected]

---
  drivers/interconnect/icc-clk.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
drivers/interconnect/icc-clk.c +1 -2
index f788db15cd76..b956e4050f38 100644
@@ -87,6 +87,7 @@ struct icc_provider *icc_clk_register(struct device *dev,
  	onecell = devm_kzalloc(dev, struct_size(onecell, nodes, 2 * num_clocks), GFP_KERNEL);
  	if (!onecell)
  		return ERR_PTR(-ENOMEM);
+	onecell->num_nodes = 2 * num_clocks;
 
  	qp = devm_kzalloc(dev, struct_size(qp, clocks, num_clocks), GFP_KERNEL);
  	if (!qp)
@@ -133,8 +134,6 @@ struct icc_provider *icc_clk_register(struct device *dev,
  		onecell->nodes[j++] = node;
  	}
 
-	onecell->num_nodes = j;
-
  	ret = icc_provider_register(provider);
  	if (ret)
  		goto err;