Skip to content

Commit

Permalink
interconnect: qcom: Annotate struct icc_onecell_data with __counted_by
Browse files Browse the repository at this point in the history
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 <agross@kernel.org>
Cc: Bjorn Andersson <andersson@kernel.org>
Cc: Konrad Dybcio <konrad.dybcio@linaro.org>
Cc: Georgi Djakov <djakov@kernel.org>
Cc: linux-arm-msm@vger.kernel.org
Cc: linux-pm@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Konrad Dybcio <konrad.dybcio@linaro.org>
Link: https://lore.kernel.org/r/20230817204215.never.916-kees@kernel.org
Signed-off-by: Georgi Djakov <djakov@kernel.org>
  • Loading branch information
kees authored and Georgi Djakov committed Aug 21, 2023
1 parent 6f0c60f commit dd4904f
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
3 changes: 1 addition & 2 deletions drivers/interconnect/qcom/icc-rpmh.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ int qcom_icc_rpmh_probe(struct platform_device *pdev)
data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->num_nodes = num_nodes;

provider = &qp->provider;
provider->dev = dev;
Expand Down Expand Up @@ -228,8 +229,6 @@ int qcom_icc_rpmh_probe(struct platform_device *pdev)
data->nodes[i] = node;
}

data->num_nodes = num_nodes;

ret = icc_provider_register(provider);
if (ret)
goto err_remove_nodes;
Expand Down
2 changes: 1 addition & 1 deletion drivers/interconnect/qcom/msm8974.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ static int msm8974_icc_probe(struct platform_device *pdev)
GFP_KERNEL);
if (!data)
return -ENOMEM;
data->num_nodes = num_nodes;

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

data->nodes[i] = node;
}
data->num_nodes = num_nodes;

ret = icc_provider_register(provider);
if (ret)
Expand Down
2 changes: 1 addition & 1 deletion drivers/interconnect/qcom/osm-l3.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ static int qcom_osm_l3_probe(struct platform_device *pdev)
data = devm_kzalloc(&pdev->dev, struct_size(data, nodes, num_nodes), GFP_KERNEL);
if (!data)
return -ENOMEM;
data->num_nodes = num_nodes;

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

data->nodes[i] = node;
}
data->num_nodes = num_nodes;

ret = icc_provider_register(provider);
if (ret)
Expand Down
2 changes: 1 addition & 1 deletion include/linux/interconnect-provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct icc_node_data {
*/
struct icc_onecell_data {
unsigned int num_nodes;
struct icc_node *nodes[];
struct icc_node *nodes[] __counted_by(num_nodes);
};

struct icc_node *of_icc_xlate_onecell(struct of_phandle_args *spec,
Expand Down

0 comments on commit dd4904f

Please sign in to comment.