1
0
Fork 0
alistair23-linux/drivers/clk
Kees Cook acafe7e302 treewide: Use struct_size() for kmalloc()-family
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
    int stuff;
    void *entry[];
};

instance = kmalloc(sizeof(struct foo) + sizeof(void *) * count, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kmalloc(struct_size(instance, entry, count), GFP_KERNEL);

This patch makes the changes for kmalloc()-family (and kvmalloc()-family)
uses. It was done via automatic conversion with manual review for the
"CHECKME" non-standard cases noted below, using the following Coccinelle
script:

// pkey_cache = kmalloc(sizeof *pkey_cache + tprops->pkey_tbl_len *
//                      sizeof *pkey_cache->table, GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@

- alloc(sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(struct_size(VAR, ELEMENT, COUNT), GFP)

// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "kmalloc|kzalloc|kvmalloc|kvzalloc";
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@

- alloc(sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-06 11:15:43 -07:00
..
at91 clk: at91: pmc: Support backup for programmable clocks 2017-12-21 16:34:06 -08:00
axis clk: axis: Use new macro CLK_OF_DECLARE_DRIVER 2016-08-12 18:00:37 -07:00
axs10x clk: axs10x: introduce AXS10X pll driver 2017-07-17 11:50:59 -07:00
bcm treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
berlin treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
davinci clk: davinci: add a reset lookup table for psc0 2018-04-06 13:37:19 -07:00
h8300 clk: h8300: pr_err() strings should end with newlines 2017-12-06 22:40:02 -08:00
hisilicon The large diff this time around is from the addition of a new clk driver 2018-04-13 15:51:06 -07:00
imgtec Update MIPS email addresses 2017-11-03 09:02:30 -07:00
imx The large diff this time around is from the addition of a new clk driver 2018-04-13 15:51:06 -07:00
ingenic clk: Add Ingenic jz4770 CGU driver 2018-01-18 22:05:55 +00:00
keystone clk: keystone: sci-clk: add support for dynamically probing clocks 2018-03-08 11:43:15 +02:00
loongson1 CLK: Add Loongson1C clock support 2016-09-23 14:49:21 -07:00
mediatek Merge branches 'clk-mediatek', 'clk-hisi', 'clk-allwinner', 'clk-ux500' and 'clk-renesas' into clk-next 2018-04-06 13:21:57 -07:00
meson First round of fixes for meson clocks targeted for v4.17 2018-05-01 14:44:16 -07:00
microchip clk: microchip: Initialize SOSC clock rate for PIC32MZDA. 2016-08-24 16:05:24 -07:00
mmp We have two changes to the core framework this time around. The first being a 2017-11-17 20:04:24 -08:00
mvebu clk: mvebu: armada-38x: add support for missing clocks 2018-03-19 13:53:57 -07:00
mxs clk: mxs: make clk_ops const 2017-11-01 23:25:43 -07:00
nxp clk: lpc32xx: Set name of regmap_config 2018-03-19 14:35:16 -07:00
pistachio
pxa clk: pxa: unbreak lookup of CLK_POUT 2017-12-28 10:43:30 -08:00
qcom The large diff this time around is from the addition of a new clk driver 2018-04-13 15:51:06 -07:00
renesas clk: renesas: Updates for v4.17 (take two) 2018-03-23 09:40:52 -07:00
rockchip clk: rockchip: assign correct id for pclk_ddr and hclk_sd in rk3399 2018-03-23 09:09:19 +01:00
samsung treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
sirf We have two changes to the core framework this time around. The first being a 2017-11-17 20:04:24 -08:00
socfpga clk: socfpga: stratix10: add clock driver for Stratix10 platform 2018-04-06 10:12:35 -07:00
spear SPEAr: clk: pr_err() strings should end with newlines 2017-12-06 22:39:59 -08:00
sprd clk: sprd: add RTC gate for SC9860 2018-03-16 15:53:30 -07:00
st License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
sunxi The core framework has a handful of patches this time around, mostly due 2018-02-01 16:56:07 -08:00
sunxi-ng The large diff this time around is from the addition of a new clk driver 2018-04-13 15:51:06 -07:00
tegra clk: tegra: Fix pll_u rate configuration 2018-03-12 13:59:06 +01:00
ti The large diff this time around is from the addition of a new clk driver 2018-04-13 15:51:06 -07:00
uniphier clk: uniphier: add additional ethernet clock lines for Pro4 2018-04-05 15:03:51 -07:00
ux500 clk: ux500: Drop AB8540/9540 support 2018-03-23 09:36:11 -07:00
versatile clk: versatile: Remove WARNs in ->round_rate() 2018-03-16 15:31:16 -07:00
x86 clk: x86: Do not gate clocks enabled by the firmware 2017-07-18 16:23:13 -07:00
zte clk: move clock common macros out from vendor directories 2017-12-21 15:00:38 -08:00
zynq
Kconfig The large diff this time around is from the addition of a new clk driver 2018-04-13 15:51:06 -07:00
Makefile The large diff this time around is from the addition of a new clk driver 2018-04-13 15:51:06 -07:00
clk-asm9260.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
clk-aspeed.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
clk-axi-clkgen.c clk: axi-clkgen: Round closest in round_rate() and recalc_rate() 2017-12-21 18:07:53 -08:00
clk-axm5516.c clk: axm5516: Migrate to clk_hw based OF and registration APIs 2016-08-24 16:11:07 -07:00
clk-bulk.c clk: Export clk_bulk_prepare() 2017-09-29 14:17:17 -07:00
clk-cdce706.c clk: cdce: Migrate to clk_hw based OF and registration APIs 2016-08-24 16:12:38 -07:00
clk-cdce925.c clk: cdce925: remove redundant check for non-null parent_name 2017-11-13 17:44:15 -08:00
clk-clps711x.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
clk-composite.c
clk-conf.c clk: Convert to using %pOF instead of full_name 2017-07-21 15:49:54 -07:00
clk-cs2000-cp.c clk: cs2000: mark resume function as __maybe_unused 2018-04-16 09:07:22 -07:00
clk-devres.c clk: add managed version of clk_bulk_get 2017-06-02 15:37:49 -07:00
clk-divider.c clk: divider: read-only divider can propagate rate change 2018-03-12 15:10:26 -07:00
clk-efm32gg.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
clk-fixed-factor.c clk: fixed-factor: Remove export symbol on setup function 2016-08-15 15:08:03 -07:00
clk-fixed-rate.c clk: fixed-rate: Remove export symbol on setup function 2016-08-15 15:08:06 -07:00
clk-fractional-divider.c clk: fractional-divider: allow overriding of approximation 2017-08-08 17:39:48 +02:00
clk-gate.c clk: gate: expose clk_gate_ops::is_enabled 2017-08-31 18:35:45 -07:00
clk-gemini.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
clk-gpio.c clk: clk-gpio: Allow GPIO to sleep in set/get_parent 2018-03-19 13:53:08 -07:00
clk-hi655x.c clk: hi6220: Add the hi655x's pmic clock 2017-04-21 19:18:53 -07:00
clk-highbank.c clk: highbank: Migrate to clk_hw based registration and OF APIs 2016-06-30 12:25:28 -07:00
clk-hsdk-pll.c ARC: clk: fix spelling mistake: "configurarion" -> "configuration" 2017-11-13 17:44:26 -08:00
clk-max77686.c clk: max77686: fix number of clocks setup for clk_hw based registration 2016-10-17 15:31:59 -07:00
clk-moxart.c clk: Convert to using %pOF instead of full_name 2017-07-21 15:49:54 -07:00
clk-multiplier.c
clk-mux.c clk: honor CLK_MUX_ROUND_CLOSEST in generic clk mux 2018-04-16 09:25:07 -07:00
clk-nomadik.c clk: nomadik: Delete error messages for a failed memory allocation in two functions 2017-04-21 19:47:14 -07:00
clk-nspire.c clk: nspire: Migrate to clk_hw based OF and registration APIs 2016-08-24 17:23:21 -07:00
clk-oxnas.c clk: oxnas: Add OX820 Gate clocks 2016-10-23 10:18:45 -07:00
clk-palmas.c clk: palmas: undo preparation of a clock source. 2017-06-02 10:51:34 -07:00
clk-pwm.c clk: pwm: Migrate to clk_hw based OF and registration APIs 2016-08-24 17:23:27 -07:00
clk-qoriq.c clk: qoriq: add more divider clocks support 2017-12-21 15:57:28 -08:00
clk-rk808.c clk: rk808: Pass the right pointer as the get_hw context 2016-09-09 11:07:07 -07:00
clk-s2mps11.c clk: s2mps11: Migrate to clk_hw based OF and registration APIs 2016-06-30 12:29:14 -07:00
clk-scmi.c clk: scmi: use devm_of_clk_add_hw_provider() API and drop scmi_clocks_remove 2018-03-20 16:23:26 +00:00
clk-scpi.c clk: scpi: error when clock fails to register 2017-06-29 18:47:35 -07:00
clk-si514.c clk: si514: Migrate to clk_hw based OF and registration APIs 2016-08-24 17:29:59 -07:00
clk-si544.c clk: Add driver for the si544 clock generator chip 2018-03-23 10:05:25 -07:00
clk-si570.c clk: si570: Migrate to clk_hw based OF and registration APIs 2016-08-24 17:30:01 -07:00
clk-si5351.c clk: si5351: _si5351_clkout_reset_pll() can be static 2017-12-28 10:49:48 -08:00
clk-si5351.h
clk-stm32f4.c clk: stm32: Add clk entry for SDMMC2 on stm32F769 2018-03-19 13:46:07 -07:00
clk-stm32h7.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
clk-stm32mp1.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
clk-tango4.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
clk-twl6040.c clk: make clk_init_data const 2017-11-01 23:25:51 -07:00
clk-u300.c clk: clk-u300: Fix a typo in two comment lines 2017-11-13 17:39:43 -08:00
clk-versaclock5.c clk: vc5: Add support for IDT VersaClock 5P49V5925 2017-07-17 11:51:00 -07:00
clk-vt8500.c clk: vt8500: Migrate to clk_hw based registration APIs 2016-08-24 17:35:48 -07:00
clk-wm831x.c clk: make clk_init_data const 2017-11-01 23:25:51 -07:00
clk-xgene.c clk: clk-xgene: Adjust six checks for null pointers 2017-11-13 17:40:03 -08:00
clk.c clk: honor CLK_MUX_ROUND_CLOSEST in generic clk mux 2018-04-16 09:25:07 -07:00
clk.h clk: Move __clk_{get,put}() into private clk.h API 2018-01-04 15:13:29 -08:00
clkdev.c clk: Prepare to remove asm-generic/clkdev.h 2018-01-02 16:12:00 -08:00