Skip to content

Commit f316cdf

Browse files
keesbebarino
authored andcommitted
clk: Annotate struct clk_hw_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 clk_hw_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: Michael Turquette <[email protected]> Cc: Stephen Boyd <[email protected]> Cc: Joel Stanley <[email protected]> Cc: Andrew Jeffery <[email protected]> Cc: Taichi Sugaya <[email protected]> Cc: Takao Orito <[email protected]> Cc: Qin Jian <[email protected]> Cc: Andrew Lunn <[email protected]> Cc: Gregory Clement <[email protected]> Cc: Sebastian Hesselbarth <[email protected]> Cc: Andy Gross <[email protected]> Cc: Bjorn Andersson <[email protected]> Cc: Konrad Dybcio <[email protected]> Cc: Sergio Paracuellos <[email protected]> Cc: Matthias Brugger <[email protected]> Cc: AngeloGioacchino Del Regno <[email protected]> Cc: Maxime Ripard <[email protected]> Cc: Chen-Yu Tsai <[email protected]> Cc: Jernej Skrabec <[email protected]> Cc: David Airlie <[email protected]> Cc: Daniel Vetter <[email protected]> Cc: Samuel Holland <[email protected]> Cc: Vinod Koul <[email protected]> Cc: Kishon Vijay Abraham I <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Gustavo A. R. Silva <[email protected]> Signed-off-by: Stephen Boyd <[email protected]>
1 parent 06c2afb commit f316cdf

File tree

11 files changed

+11
-16
lines changed

11 files changed

+11
-16
lines changed

drivers/clk/clk-aspeed.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ static void __init aspeed_cc_init(struct device_node *np)
701701
GFP_KERNEL);
702702
if (!aspeed_clk_data)
703703
return;
704+
aspeed_clk_data->num = ASPEED_NUM_CLKS;
704705

705706
/*
706707
* This way all clocks fetched before the platform device probes,
@@ -732,8 +733,6 @@ static void __init aspeed_cc_init(struct device_node *np)
732733
aspeed_ast2500_cc(map);
733734
else
734735
pr_err("unknown platform, failed to add clocks\n");
735-
736-
aspeed_clk_data->num = ASPEED_NUM_CLKS;
737736
ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, aspeed_clk_data);
738737
if (ret)
739738
pr_err("failed to add DT provider: %d\n", ret);

drivers/clk/clk-ast2600.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ static void __init aspeed_g6_cc_init(struct device_node *np)
839839
ASPEED_G6_NUM_CLKS), GFP_KERNEL);
840840
if (!aspeed_g6_clk_data)
841841
return;
842+
aspeed_g6_clk_data->num = ASPEED_G6_NUM_CLKS;
842843

843844
/*
844845
* This way all clocks fetched before the platform device probes,
@@ -860,7 +861,6 @@ static void __init aspeed_g6_cc_init(struct device_node *np)
860861
}
861862

862863
aspeed_g6_cc(map);
863-
aspeed_g6_clk_data->num = ASPEED_G6_NUM_CLKS;
864864
ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, aspeed_g6_clk_data);
865865
if (ret)
866866
pr_err("failed to add DT provider: %d\n", ret);

drivers/clk/clk-gemini.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ static void __init gemini_cc_init(struct device_node *np)
404404
GFP_KERNEL);
405405
if (!gemini_clk_data)
406406
return;
407+
gemini_clk_data->num = GEMINI_NUM_CLKS;
407408

408409
/*
409410
* This way all clock fetched before the platform device probes,
@@ -457,7 +458,6 @@ static void __init gemini_cc_init(struct device_node *np)
457458
gemini_clk_data->hws[GEMINI_CLK_APB] = hw;
458459

459460
/* Register the clocks to be accessed by the device tree */
460-
gemini_clk_data->num = GEMINI_NUM_CLKS;
461461
of_clk_add_hw_provider(np, of_clk_hw_onecell_get, gemini_clk_data);
462462
}
463463
CLK_OF_DECLARE_DRIVER(gemini_cc, "cortina,gemini-syscon", gemini_cc_init);

drivers/clk/clk-milbeaut.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ static void __init m10v_cc_init(struct device_node *np)
618618

619619
if (!m10v_clk_data)
620620
return;
621+
m10v_clk_data->num = M10V_NUM_CLKS;
621622

622623
base = of_iomap(np, 0);
623624
if (!base) {
@@ -654,8 +655,6 @@ static void __init m10v_cc_init(struct device_node *np)
654655
base + CLKSEL(1), 0, 3, 0, rclk_table,
655656
&m10v_crglock, NULL);
656657
m10v_clk_data->hws[M10V_RCLK_ID] = hw;
657-
658-
m10v_clk_data->num = M10V_NUM_CLKS;
659658
of_clk_add_hw_provider(np, of_clk_hw_onecell_get, m10v_clk_data);
660659
}
661660
CLK_OF_DECLARE_DRIVER(m10v_cc, "socionext,milbeaut-m10v-ccu", m10v_cc_init);

drivers/clk/clk-sp7021.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ static int sp7021_clk_probe(struct platform_device *pdev)
621621
GFP_KERNEL);
622622
if (!clk_data)
623623
return -ENOMEM;
624+
clk_data->num = CLK_MAX;
624625

625626
hws = clk_data->hws;
626627
pd_ext.index = 0;
@@ -688,8 +689,6 @@ static int sp7021_clk_probe(struct platform_device *pdev)
688689
return PTR_ERR(hws[i]);
689690
}
690691

691-
clk_data->num = CLK_MAX;
692-
693692
return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_data);
694693
}
695694

drivers/clk/mvebu/cp110-system-controller.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
240240
GFP_KERNEL);
241241
if (!cp110_clk_data)
242242
return -ENOMEM;
243+
cp110_clk_data->num = CP110_CLK_NUM;
243244

244245
cp110_clks = cp110_clk_data->hws;
245-
cp110_clk_data->num = CP110_CLK_NUM;
246246

247247
/* Register the PLL0 which is the root of the hw tree */
248248
pll0_name = ap_cp_unique_name(dev, syscon_node, "pll0");

drivers/clk/qcom/clk-cpu-8996.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ static int qcom_cpu_clk_msm8996_driver_probe(struct platform_device *pdev)
590590
data = devm_kzalloc(dev, struct_size(data, hws, 2), GFP_KERNEL);
591591
if (!data)
592592
return -ENOMEM;
593+
data->num = 2;
593594

594595
base = devm_platform_ioremap_resource(pdev, 0);
595596
if (IS_ERR(base))
@@ -605,7 +606,6 @@ static int qcom_cpu_clk_msm8996_driver_probe(struct platform_device *pdev)
605606

606607
data->hws[0] = &pwrcl_pmux.clkr.hw;
607608
data->hws[1] = &perfcl_pmux.clkr.hw;
608-
data->num = 2;
609609

610610
return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, data);
611611
}

drivers/clk/ralink/clk-mt7621.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ static int mt7621_clk_probe(struct platform_device *pdev)
521521
GFP_KERNEL);
522522
if (!clk_data)
523523
return -ENOMEM;
524+
clk_data->num = count;
524525

525526
for (i = 0; i < ARRAY_SIZE(mt7621_clks_base); i++)
526527
clk_data->hws[i] = mt7621_clk_early[i];
@@ -537,8 +538,6 @@ static int mt7621_clk_probe(struct platform_device *pdev)
537538
goto unreg_clk_fixed;
538539
}
539540

540-
clk_data->num = count;
541-
542541
ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, clk_data);
543542
if (ret) {
544543
dev_err(dev, "Couldn't add clk hw provider\n");

drivers/gpu/drm/sun4i/sun8i_tcon_top.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ static int sun8i_tcon_top_bind(struct device *dev, struct device *master,
141141
GFP_KERNEL);
142142
if (!clk_data)
143143
return -ENOMEM;
144+
clk_data->num = CLK_NUM;
144145
tcon_top->clk_data = clk_data;
145146

146147
spin_lock_init(&tcon_top->reg_lock);
@@ -213,8 +214,6 @@ static int sun8i_tcon_top_bind(struct device *dev, struct device *master,
213214
goto err_unregister_gates;
214215
}
215216

216-
clk_data->num = CLK_NUM;
217-
218217
ret = of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
219218
clk_data);
220219
if (ret)

drivers/phy/qualcomm/phy-qcom-edp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ static int qcom_edp_clks_register(struct qcom_edp *edp, struct device_node *np)
746746
data = devm_kzalloc(edp->dev, struct_size(data, hws, 2), GFP_KERNEL);
747747
if (!data)
748748
return -ENOMEM;
749+
data->num = 2;
749750

750751
snprintf(name, sizeof(name), "%s::link_clk", dev_name(edp->dev));
751752
init.ops = &qcom_edp_dp_link_clk_ops;
@@ -765,7 +766,6 @@ static int qcom_edp_clks_register(struct qcom_edp *edp, struct device_node *np)
765766

766767
data->hws[0] = &edp->dp_link_hw;
767768
data->hws[1] = &edp->dp_pixel_hw;
768-
data->num = 2;
769769

770770
return devm_of_clk_add_hw_provider(edp->dev, of_clk_hw_onecell_get, data);
771771
}

include/linux/clk-provider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ struct clk_onecell_data {
13791379

13801380
struct clk_hw_onecell_data {
13811381
unsigned int num;
1382-
struct clk_hw *hws[];
1382+
struct clk_hw *hws[] __counted_by(num);
13831383
};
13841384

13851385
#define CLK_OF_DECLARE(name, compat, fn) \

0 commit comments

Comments
 (0)