Skip to contentSkip to conversation

clk: tegra: annotate struct tegra210_clk_emc_provider with __counted_by_ptr

PATCH Applied Bill Wendling 4 participants 4 messages Sep 22 – Sep 24

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

PATCH 1/1 clk: tegra: annotate struct tegra210_clk_emc_provider with __counted_by_ptr

Annotate the "configs" pointer field of "struct tegra210_clk_emc_provider" with the "__counted_by_ptr" attribute, allowing the compiler to perform runtime bounds checking on accesses to "configs" based on the value of "num_configs".

The "emc->provider.configs = devm_kcalloc(...)" call uses "emc->num_timings" for the number of elements, which is then assigned to "emc->provider.num_configs" before any accesses to "configs". The "num_configs" field isn't modified after assignment.

---
 include/linux/clk/tegra.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/clk/tegra.h +1 -1
index 3650e926e93f..f1034e14c1a4 100644
@@ -170,7 +170,7 @@ struct tegra210_clk_emc_provider {
 	struct module *owner;
 	struct device *dev;
 
-	struct tegra210_clk_emc_config *configs;
+	struct tegra210_clk_emc_config *configs __counted_by_ptr(num_configs);
 	unsigned int num_configs;
 
 	int (*set_rate)(struct device *dev,
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Bill Wendling

Annotate the "configs" pointer field of "struct tegra210_clk_emc_provider" with the "__counted_by_ptr" attribute, allowing the compiler to perform runtime bounds checking on accesses to "configs" based on the value of "num_configs".

Quoted 8 lines

The "emc->provider.configs = devm_kcalloc(...)" call uses "emc->num_timings" for the number of elements, which is then assigned to "emc->provider.num_configs" before any accesses to "configs". The "num_configs" field isn't modified after assignment.

Thanks
-Gustavo

Quoted 17 lines
---
  include/linux/clk/tegra.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/clk/tegra.h +1 -1
index 3650e926e93f..f1034e14c1a4 100644
@@ -170,7 +170,7 @@ struct tegra210_clk_emc_provider {
  	struct module *owner;
  	struct device *dev;
 
-	struct tegra210_clk_emc_config *configs;
+	struct tegra210_clk_emc_config *configs __counted_by_ptr(num_configs);
  	unsigned int num_configs;
 
  	int (*set_rate)(struct device *dev,
Reviewed-by on v1 1/1
#2 lore raw
In reply to Bill Wendling
Quoted 9 lines · Bill Wendling

Annotate the "configs" pointer field of "struct tegra210_clk_emc_provider" with the "__counted_by_ptr" attribute, allowing the compiler to perform runtime bounds checking on accesses to "configs" based on the value of "num_configs".

The "emc->provider.configs = devm_kcalloc(...)" call uses "emc->num_timings" for the number of elements, which is then assigned to "emc->provider.num_configs" before any accesses to "configs". The "num_configs" field isn't modified after assignment.

Yup, that's the only assignment I can find.

Quoted 3 lines
Signature · 1 line
Kees Cook
Applied
#3 lore raw
In reply to Bill Wendling
Quoted 1 line · Bill Wendling

clk: tegra: annotate struct tegra210_clk_emc_provider with __counted_by_ptr

Applied, thanks!

[1/1] clk: tegra: annotate struct tegra210_clk_emc_provider with __counted_by_ptr

      commit: a1f2029b89ccd7bef54e187384417db4d72d0a11

Best regards,

Signature · 1 line
Brian Masney <[email protected]>