Skip to content

Commit e620a1e

Browse files
skittbebarino
authored andcommitted
drivers/clk: convert VL struct to struct_size
There are a few manually-calculated variable-length struct allocations left, this converts them to use struct_size. Found with the following git grep command git grep -A1 'kzalloc.*sizeof[^_].*+' Signed-off-by: Stephen Kitt <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Acked-by: Gustavo A. R. Silva <[email protected]> [[email protected]: Add grep command] Signed-off-by: Stephen Boyd <[email protected]>
1 parent 54ecb8f commit e620a1e

File tree

7 files changed

+9
-14
lines changed

7 files changed

+9
-14
lines changed

drivers/clk/at91/sckc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ static void __init of_sam9x60_sckc_setup(struct device_node *np)
478478
if (IS_ERR(slow_osc))
479479
goto unregister_slow_rc;
480480

481-
clk_data = kzalloc(sizeof(*clk_data) + (2 * sizeof(struct clk_hw *)),
482-
GFP_KERNEL);
481+
clk_data = kzalloc(struct_size(clk_data, hws, 2), GFP_KERNEL);
483482
if (!clk_data)
484483
goto unregister_slow_osc;
485484

drivers/clk/imgtec/clk-boston.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ static void __init clk_boston_setup(struct device_node *np)
5858
cpu_div = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_CLK1DIV);
5959
cpu_freq = mult_frac(in_freq, mul, cpu_div);
6060

61-
onecell = kzalloc(sizeof(*onecell) +
62-
(BOSTON_CLK_COUNT * sizeof(struct clk_hw *)),
61+
onecell = kzalloc(struct_size(onecell, hws, BOSTON_CLK_COUNT),
6362
GFP_KERNEL);
6463
if (!onecell)
6564
return;

drivers/clk/ingenic/tcu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ static int __init ingenic_tcu_probe(struct device_node *np)
358358
}
359359
}
360360

361-
tcu->clocks = kzalloc(sizeof(*tcu->clocks) +
362-
sizeof(*tcu->clocks->hws) * TCU_CLK_COUNT,
361+
tcu->clocks = kzalloc(struct_size(tcu->clocks, hws, TCU_CLK_COUNT),
363362
GFP_KERNEL);
364363
if (!tcu->clocks) {
365364
ret = -ENOMEM;

drivers/clk/mvebu/ap-cpu-clk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ static int ap_cpu_clock_probe(struct platform_device *pdev)
274274
if (!ap_cpu_clk)
275275
return -ENOMEM;
276276

277-
ap_cpu_data = devm_kzalloc(dev, sizeof(*ap_cpu_data) +
278-
sizeof(struct clk_hw *) * nclusters,
277+
ap_cpu_data = devm_kzalloc(dev, struct_size(ap_cpu_data, hws,
278+
nclusters),
279279
GFP_KERNEL);
280280
if (!ap_cpu_data)
281281
return -ENOMEM;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ static int cp110_syscon_common_probe(struct platform_device *pdev,
235235
if (ret)
236236
return ret;
237237

238-
cp110_clk_data = devm_kzalloc(dev, sizeof(*cp110_clk_data) +
239-
sizeof(struct clk_hw *) * CP110_CLK_NUM,
238+
cp110_clk_data = devm_kzalloc(dev, struct_size(cp110_clk_data, hws,
239+
CP110_CLK_NUM),
240240
GFP_KERNEL);
241241
if (!cp110_clk_data)
242242
return -ENOMEM;

drivers/clk/samsung/clk.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ struct samsung_clk_provider *__init samsung_clk_init(struct device_node *np,
6060
struct samsung_clk_provider *ctx;
6161
int i;
6262

63-
ctx = kzalloc(sizeof(struct samsung_clk_provider) +
64-
sizeof(*ctx->clk_data.hws) * nr_clks, GFP_KERNEL);
63+
ctx = kzalloc(struct_size(ctx, clk_data.hws, nr_clks), GFP_KERNEL);
6564
if (!ctx)
6665
panic("could not allocate clock provider context.\n");
6766

drivers/clk/uniphier/clk-uniphier-core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ static int uniphier_clk_probe(struct platform_device *pdev)
6464
for (p = data; p->name; p++)
6565
clk_num = max(clk_num, p->idx + 1);
6666

67-
hw_data = devm_kzalloc(dev,
68-
sizeof(*hw_data) + clk_num * sizeof(struct clk_hw *),
67+
hw_data = devm_kzalloc(dev, struct_size(hw_data, hws, clk_num),
6968
GFP_KERNEL);
7069
if (!hw_data)
7170
return -ENOMEM;

0 commit comments

Comments
 (0)