linux-stable/sound/soc
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
..
adi
amd ASoC: amd: acp-da7219-max98357: Make symbol da7219_dai_clk static 2018-04-16 18:01:54 +01:00
atmel Merge remote-tracking branches 'asoc/topic/arizona', 'asoc/topic/atmel', 'asoc/topic/bd28623', 'asoc/topic/blackfin' and 'asoc/topic/bt-sco' into asoc-next 2018-03-28 10:29:01 +08:00
au1x ASoC: au1x: dma: replace platform to component 2018-02-12 11:45:36 +00:00
bcm Merge remote-tracking branches 'asoc/topic/cx20442', 'asoc/topic/cygnus', 'asoc/topic/da7210', 'asoc/topic/da7213' and 'asoc/topic/da7218' into asoc-next 2018-03-28 10:29:26 +08:00
cirrus
codecs ASoC: msm8916-wcd-analog: use threaded context for mbhc events 2018-04-19 12:30:42 +01:00
davinci ASoC: davinci-i2s: replace platform to component 2018-02-12 11:45:21 +00:00
dwc Merge remote-tracking branches 'asoc/topic/dwc', 'asoc/topic/es7134', 'asoc/topic/es8316', 'asoc/topic/es8328' and 'asoc/topic/fsl' into asoc-next 2018-03-28 10:29:36 +08:00
fsl ASoC: Fixes for v4.17 2018-04-25 12:22:20 +02:00
generic
hisilicon
img ASoC: pistachio: replace codec to component 2018-02-12 11:08:03 +00:00
intel ASoC: Intel: atom: fix ACPI/PCI Kconfig 2018-04-12 15:46:34 +01:00
jz4740
kirkwood ASoC: kirkwood: replace platform to component 2018-02-12 11:45:28 +00:00
mediatek Merge remote-tracking branches 'asoc/topic/rt5645', 'asoc/topic/rt5651', 'asoc/topic/rt5659' and 'asoc/topic/rt5660' into asoc-next 2018-03-28 10:30:29 +08:00
mxs
nuc900 ASoC: nuc900-pcm: replace platform to component 2018-02-12 11:45:37 +00:00
omap ASoC: dmic: Fix clock parenting 2018-04-12 13:00:54 +01:00
pxa Merge remote-tracking branches 'asoc/topic/pistachio', 'asoc/topic/pxa', 'asoc/topic/rsnd', 'asoc/topic/rt274' and 'asoc/topic/rt286' into asoc-next 2018-03-28 10:30:19 +08:00
qcom ASoC: qcom: lpass-platform: replace platform to component 2018-02-12 11:45:30 +00:00
rockchip Merge remote-tracking branches 'asoc/topic/rt5645', 'asoc/topic/rt5651', 'asoc/topic/rt5659' and 'asoc/topic/rt5660' into asoc-next 2018-03-28 10:30:29 +08:00
samsung Merge remote-tracking branches 'asoc/topic/wm8991', 'asoc/topic/wm8994', 'asoc/topic/wm8995', 'asoc/topic/wm8996' and 'asoc/topic/wm9081' into asoc-next 2018-03-28 10:31:54 +08:00
sh ASoC: rsnd: mark PM functions __maybe_unused 2018-04-12 15:45:34 +01:00
sirf ASoC: sirf: remove duplicated bit-wise or of USP_RXFIFO_THD_INT 2018-02-26 10:19:20 +00:00
spear
sti
stm ASoC: stm32: sai: Add support of S/PDIF playback 2018-02-26 11:19:04 +00:00
sunxi Merge remote-tracking branches 'asoc/topic/sta529', 'asoc/topic/sti-sas', 'asoc/topic/stm32', 'asoc/topic/sun4i' and 'asoc/topic/sun8i' into asoc-next 2018-03-28 10:30:49 +08:00
tegra ASoC: wm8903: replace codec to component 2018-02-12 09:41:37 +00:00
txx9 ASoC: txx9aclc: replace platform to component 2018-02-12 11:45:38 +00:00
uniphier ASoC: uniphier: add syscon property for UniPhier sound system 2018-03-18 17:57:54 -07:00
ux500
xtensa ASoC: xtfpga-i2s: replace platform to component 2018-02-12 11:45:32 +00:00
zte
Kconfig ASoC: remove blackfin drivers 2018-03-14 09:35:29 -07:00
Makefile ASoC: remove blackfin drivers 2018-03-14 09:35:29 -07:00
soc-ac97.c ASoC: ac97: replace codec to component 2018-02-12 09:37:29 +00:00
soc-acpi.c
soc-cache.c
soc-compress.c Merge remote-tracking branches 'asoc/fix/compress', 'asoc/fix/core', 'asoc/fix/dapm', 'asoc/fix/mtk' and 'asoc/fix/stm' into asoc-next 2018-02-07 11:21:02 +00:00
soc-core.c Merge remote-tracking branch 'asoc/topic/samsung' into asoc-next 2018-03-28 10:26:30 +08:00
soc-dapm.c treewide: Use struct_size() for kmalloc()-family 2018-06-06 11:15:43 -07:00
soc-devres.c
soc-generic-dmaengine-pcm.c ASoC: Revert "ASoC: soc-generic-dmaengine-pcm: Fix error handling" 2018-02-26 19:59:31 +00:00
soc-io.c ASoC: soc-io: Fix snd_soc_component_update_bits_legacy 2018-03-12 09:58:02 -07:00
soc-jack.c
soc-ops.c
soc-pcm.c ASoC: pcm: improve debug output for DPCM BE searching. 2018-03-19 15:07:15 +08:00
soc-topology.c ASoC: topology: Check widget kcontrols before deref 2018-04-17 18:06:54 +01:00
soc-utils.c ASoC: soc-utils: replace codec to component 2018-02-12 11:46:14 +00:00