Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <steve@sk2.org>
Link: https://lkml.kernel.org/r/20190927185110.29897-1-steve@sk2.org
Acked-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
[sboyd@kernel.org: Add grep command]
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Stephen Kitt and committed by
Stephen Boyd
e620a1e0 54ecb8f7

+9 -14
+1 -2
drivers/clk/at91/sckc.c
··· 478 478 if (IS_ERR(slow_osc)) 479 479 goto unregister_slow_rc; 480 480 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); 483 482 if (!clk_data) 484 483 goto unregister_slow_osc; 485 484
+1 -2
drivers/clk/imgtec/clk-boston.c
··· 58 58 cpu_div = ext_field(mmcmdiv, BOSTON_PLAT_MMCMDIV_CLK1DIV); 59 59 cpu_freq = mult_frac(in_freq, mul, cpu_div); 60 60 61 - onecell = kzalloc(sizeof(*onecell) + 62 - (BOSTON_CLK_COUNT * sizeof(struct clk_hw *)), 61 + onecell = kzalloc(struct_size(onecell, hws, BOSTON_CLK_COUNT), 63 62 GFP_KERNEL); 64 63 if (!onecell) 65 64 return;
+1 -2
drivers/clk/ingenic/tcu.c
··· 358 358 } 359 359 } 360 360 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), 363 362 GFP_KERNEL); 364 363 if (!tcu->clocks) { 365 364 ret = -ENOMEM;
+2 -2
drivers/clk/mvebu/ap-cpu-clk.c
··· 274 274 if (!ap_cpu_clk) 275 275 return -ENOMEM; 276 276 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), 279 279 GFP_KERNEL); 280 280 if (!ap_cpu_data) 281 281 return -ENOMEM;
+2 -2
drivers/clk/mvebu/cp110-system-controller.c
··· 235 235 if (ret) 236 236 return ret; 237 237 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), 240 240 GFP_KERNEL); 241 241 if (!cp110_clk_data) 242 242 return -ENOMEM;
+1 -2
drivers/clk/samsung/clk.c
··· 60 60 struct samsung_clk_provider *ctx; 61 61 int i; 62 62 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); 65 64 if (!ctx) 66 65 panic("could not allocate clock provider context.\n"); 67 66
+1 -2
drivers/clk/uniphier/clk-uniphier-core.c
··· 64 64 for (p = data; p->name; p++) 65 65 clk_num = max(clk_num, p->idx + 1); 66 66 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), 69 68 GFP_KERNEL); 70 69 if (!hw_data) 71 70 return -ENOMEM;