Skip to content

Commit dd4904f

Browse files
keesGeorgi Djakov
authored andcommitted
interconnect: qcom: Annotate struct icc_onecell_data with __counted_by
Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). As found with Coccinelle[1], add __counted_by for struct icc_onecell_data. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Andy Gross <[email protected]> Cc: Bjorn Andersson <[email protected]> Cc: Konrad Dybcio <[email protected]> Cc: Georgi Djakov <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Acked-by: Konrad Dybcio <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Georgi Djakov <[email protected]>
1 parent 6f0c60f commit dd4904f

File tree

4 files changed

+4
-5
lines changed

4 files changed

+4
-5
lines changed

drivers/interconnect/qcom/icc-rpmh.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ int qcom_icc_rpmh_probe(struct platform_device *pdev)
185185
data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes), GFP_KERNEL);
186186
if (!data)
187187
return -ENOMEM;
188+
data->num_nodes = num_nodes;
188189

189190
provider = &qp->provider;
190191
provider->dev = dev;
@@ -228,8 +229,6 @@ int qcom_icc_rpmh_probe(struct platform_device *pdev)
228229
data->nodes[i] = node;
229230
}
230231

231-
data->num_nodes = num_nodes;
232-
233232
ret = icc_provider_register(provider);
234233
if (ret)
235234
goto err_remove_nodes;

drivers/interconnect/qcom/msm8974.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ static int msm8974_icc_probe(struct platform_device *pdev)
675675
GFP_KERNEL);
676676
if (!data)
677677
return -ENOMEM;
678+
data->num_nodes = num_nodes;
678679

679680
qp->bus_clks = devm_kmemdup(dev, msm8974_icc_bus_clocks,
680681
sizeof(msm8974_icc_bus_clocks), GFP_KERNEL);
@@ -721,7 +722,6 @@ static int msm8974_icc_probe(struct platform_device *pdev)
721722

722723
data->nodes[i] = node;
723724
}
724-
data->num_nodes = num_nodes;
725725

726726
ret = icc_provider_register(provider);
727727
if (ret)

drivers/interconnect/qcom/osm-l3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static int qcom_osm_l3_probe(struct platform_device *pdev)
232232
data = devm_kzalloc(&pdev->dev, struct_size(data, nodes, num_nodes), GFP_KERNEL);
233233
if (!data)
234234
return -ENOMEM;
235+
data->num_nodes = num_nodes;
235236

236237
provider = &qp->provider;
237238
provider->dev = &pdev->dev;
@@ -261,7 +262,6 @@ static int qcom_osm_l3_probe(struct platform_device *pdev)
261262

262263
data->nodes[i] = node;
263264
}
264-
data->num_nodes = num_nodes;
265265

266266
ret = icc_provider_register(provider);
267267
if (ret)

include/linux/interconnect-provider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct icc_node_data {
3333
*/
3434
struct icc_onecell_data {
3535
unsigned int num_nodes;
36-
struct icc_node *nodes[];
36+
struct icc_node *nodes[] __counted_by(num_nodes);
3737
};
3838

3939
struct icc_node *of_icc_xlate_onecell(struct of_phandle_args *spec,

0 commit comments

Comments
 (0)