diff options
| author | Kees Cook <keescook@chromium.org> | 2018-05-08 19:08:53 -0400 |
|---|---|---|
| committer | Kees Cook <keescook@chromium.org> | 2018-06-06 14:15:43 -0400 |
| commit | 0ed2dd03b94b7b7f66e23f25073b5385d0416589 (patch) | |
| tree | 5b46cbc179ffcdaf40715d53b8308f5a937b5c40 | |
| parent | b4b06db115bbbc10252287ae2d326fb5ecefaf18 (diff) | |
treewide: Use struct_size() for devm_kmalloc() and friends
Replaces open-coded struct size calculations with struct_size() for
devm_*, f2fs_*, and sock_* allocations. Automatically generated (and
manually adjusted) from the following Coccinelle script:
// Direct reference to struct field.
@@
identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
expression HANDLE;
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@
- alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
+ alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)
// mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
@@
identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
expression HANDLE;
expression GFP;
identifier VAR, ELEMENT;
expression COUNT;
@@
- alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
+ alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)
// Same pattern, but can't trivially locate the trailing element name,
// or variable name.
@@
identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
expression HANDLE;
expression GFP;
expression SOMETHING, COUNT, ELEMENT;
@@
- alloc(HANDLE, sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
+ alloc(HANDLE, CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)
Signed-off-by: Kees Cook <keescook@chromium.org>
32 files changed, 71 insertions, 71 deletions
diff --git a/crypto/af_alg.c b/crypto/af_alg.c index 7846c0c20cfe..bcbf6774f431 100644 --- a/crypto/af_alg.c +++ b/crypto/af_alg.c | |||
| @@ -501,8 +501,8 @@ int af_alg_alloc_tsgl(struct sock *sk) | |||
| 501 | sg = sgl->sg; | 501 | sg = sgl->sg; |
| 502 | 502 | ||
| 503 | if (!sg || sgl->cur >= MAX_SGL_ENTS) { | 503 | if (!sg || sgl->cur >= MAX_SGL_ENTS) { |
| 504 | sgl = sock_kmalloc(sk, sizeof(*sgl) + | 504 | sgl = sock_kmalloc(sk, |
| 505 | sizeof(sgl->sg[0]) * (MAX_SGL_ENTS + 1), | 505 | struct_size(sgl, sg, (MAX_SGL_ENTS + 1)), |
| 506 | GFP_KERNEL); | 506 | GFP_KERNEL); |
| 507 | if (!sgl) | 507 | if (!sgl) |
| 508 | return -ENOMEM; | 508 | return -ENOMEM; |
diff --git a/drivers/clk/bcm/clk-bcm2835-aux.c b/drivers/clk/bcm/clk-bcm2835-aux.c index 77e276d61702..f225ad29b110 100644 --- a/drivers/clk/bcm/clk-bcm2835-aux.c +++ b/drivers/clk/bcm/clk-bcm2835-aux.c | |||
| @@ -40,8 +40,10 @@ static int bcm2835_aux_clk_probe(struct platform_device *pdev) | |||
| 40 | if (IS_ERR(reg)) | 40 | if (IS_ERR(reg)) |
| 41 | return PTR_ERR(reg); | 41 | return PTR_ERR(reg); |
| 42 | 42 | ||
| 43 | onecell = devm_kmalloc(dev, sizeof(*onecell) + sizeof(*onecell->hws) * | 43 | onecell = devm_kmalloc(dev, |
| 44 | BCM2835_AUX_CLOCK_COUNT, GFP_KERNEL); | 44 | struct_size(onecell, hws, |
| 45 | BCM2835_AUX_CLOCK_COUNT), | ||
| 46 | GFP_KERNEL); | ||
| 45 | if (!onecell) | 47 | if (!onecell) |
| 46 | return -ENOMEM; | 48 | return -ENOMEM; |
| 47 | onecell->num = BCM2835_AUX_CLOCK_COUNT; | 49 | onecell->num = BCM2835_AUX_CLOCK_COUNT; |
diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index fa0d5c8611a0..6d4e69edfb36 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c | |||
| @@ -2147,8 +2147,8 @@ static int bcm2835_clk_probe(struct platform_device *pdev) | |||
| 2147 | size_t i; | 2147 | size_t i; |
| 2148 | int ret; | 2148 | int ret; |
| 2149 | 2149 | ||
| 2150 | cprman = devm_kzalloc(dev, sizeof(*cprman) + | 2150 | cprman = devm_kzalloc(dev, |
| 2151 | sizeof(*cprman->onecell.hws) * asize, | 2151 | struct_size(cprman, onecell.hws, asize), |
| 2152 | GFP_KERNEL); | 2152 | GFP_KERNEL); |
| 2153 | if (!cprman) | 2153 | if (!cprman) |
| 2154 | return -ENOMEM; | 2154 | return -ENOMEM; |
diff --git a/drivers/clk/clk-s2mps11.c b/drivers/clk/clk-s2mps11.c index fbaa84a33c46..d44e0eea31ec 100644 --- a/drivers/clk/clk-s2mps11.c +++ b/drivers/clk/clk-s2mps11.c | |||
| @@ -147,8 +147,8 @@ static int s2mps11_clk_probe(struct platform_device *pdev) | |||
| 147 | if (!s2mps11_clks) | 147 | if (!s2mps11_clks) |
| 148 | return -ENOMEM; | 148 | return -ENOMEM; |
| 149 | 149 | ||
| 150 | clk_data = devm_kzalloc(&pdev->dev, sizeof(*clk_data) + | 150 | clk_data = devm_kzalloc(&pdev->dev, |
| 151 | sizeof(*clk_data->hws) * S2MPS11_CLKS_NUM, | 151 | struct_size(clk_data, hws, S2MPS11_CLKS_NUM), |
| 152 | GFP_KERNEL); | 152 | GFP_KERNEL); |
| 153 | if (!clk_data) | 153 | if (!clk_data) |
| 154 | return -ENOMEM; | 154 | return -ENOMEM; |
diff --git a/drivers/clk/clk-scmi.c b/drivers/clk/clk-scmi.c index 488c21376b55..bb2a6f2f5516 100644 --- a/drivers/clk/clk-scmi.c +++ b/drivers/clk/clk-scmi.c | |||
| @@ -137,8 +137,8 @@ static int scmi_clocks_probe(struct scmi_device *sdev) | |||
| 137 | return -EINVAL; | 137 | return -EINVAL; |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | clk_data = devm_kzalloc(dev, sizeof(*clk_data) + | 140 | clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, count), |
| 141 | sizeof(*clk_data->hws) * count, GFP_KERNEL); | 141 | GFP_KERNEL); |
| 142 | if (!clk_data) | 142 | if (!clk_data) |
| 143 | return -ENOMEM; | 143 | return -ENOMEM; |
| 144 | 144 | ||
diff --git a/drivers/clk/davinci/da8xx-cfgchip.c b/drivers/clk/davinci/da8xx-cfgchip.c index c971111d2601..aae62a5b8734 100644 --- a/drivers/clk/davinci/da8xx-cfgchip.c +++ b/drivers/clk/davinci/da8xx-cfgchip.c | |||
| @@ -650,8 +650,8 @@ static int of_da8xx_usb_phy_clk_init(struct device *dev, struct regmap *regmap) | |||
| 650 | struct da8xx_usb0_clk48 *usb0; | 650 | struct da8xx_usb0_clk48 *usb0; |
| 651 | struct da8xx_usb1_clk48 *usb1; | 651 | struct da8xx_usb1_clk48 *usb1; |
| 652 | 652 | ||
| 653 | clk_data = devm_kzalloc(dev, sizeof(*clk_data) + 2 * | 653 | clk_data = devm_kzalloc(dev, struct_size(clk_data, hws, 2), |
| 654 | sizeof(*clk_data->hws), GFP_KERNEL); | 654 | GFP_KERNEL); |
| 655 | if (!clk_data) | 655 | if (!clk_data) |
| 656 | return -ENOMEM; | 656 | return -ENOMEM; |
| 657 | 657 | ||
diff --git a/drivers/clk/mvebu/armada-37xx-periph.c b/drivers/clk/mvebu/armada-37xx-periph.c index 87213ea7fc84..6860bd5a37c5 100644 --- a/drivers/clk/mvebu/armada-37xx-periph.c +++ b/drivers/clk/mvebu/armada-37xx-periph.c | |||
| @@ -667,9 +667,10 @@ static int armada_3700_periph_clock_probe(struct platform_device *pdev) | |||
| 667 | if (!driver_data) | 667 | if (!driver_data) |
| 668 | return -ENOMEM; | 668 | return -ENOMEM; |
| 669 | 669 | ||
| 670 | driver_data->hw_data = devm_kzalloc(dev, sizeof(*driver_data->hw_data) + | 670 | driver_data->hw_data = devm_kzalloc(dev, |
| 671 | sizeof(*driver_data->hw_data->hws) * num_periph, | 671 | struct_size(driver_data->hw_data, |
| 672 | GFP_KERNEL); | 672 | hws, num_periph), |
| 673 | GFP_KERNEL); | ||
| 673 | if (!driver_data->hw_data) | 674 | if (!driver_data->hw_data) |
| 674 | return -ENOMEM; | 675 | return -ENOMEM; |
| 675 | driver_data->hw_data->num = num_periph; | 676 | driver_data->hw_data->num = num_periph; |
diff --git a/drivers/clk/mvebu/armada-37xx-tbg.c b/drivers/clk/mvebu/armada-37xx-tbg.c index aa80db11f543..7ff041f73b55 100644 --- a/drivers/clk/mvebu/armada-37xx-tbg.c +++ b/drivers/clk/mvebu/armada-37xx-tbg.c | |||
| @@ -91,8 +91,8 @@ static int armada_3700_tbg_clock_probe(struct platform_device *pdev) | |||
| 91 | void __iomem *reg; | 91 | void __iomem *reg; |
| 92 | int i, ret; | 92 | int i, ret; |
| 93 | 93 | ||
| 94 | hw_tbg_data = devm_kzalloc(&pdev->dev, sizeof(*hw_tbg_data) | 94 | hw_tbg_data = devm_kzalloc(&pdev->dev, |
| 95 | + sizeof(*hw_tbg_data->hws) * NUM_TBG, | 95 | struct_size(hw_tbg_data, hws, NUM_TBG), |
| 96 | GFP_KERNEL); | 96 | GFP_KERNEL); |
| 97 | if (!hw_tbg_data) | 97 | if (!hw_tbg_data) |
| 98 | return -ENOMEM; | 98 | return -ENOMEM; |
diff --git a/drivers/clk/qcom/clk-spmi-pmic-div.c b/drivers/clk/qcom/clk-spmi-pmic-div.c index 8672ab84746f..c90dfdd6c147 100644 --- a/drivers/clk/qcom/clk-spmi-pmic-div.c +++ b/drivers/clk/qcom/clk-spmi-pmic-div.c | |||
| @@ -239,8 +239,7 @@ static int spmi_pmic_clkdiv_probe(struct platform_device *pdev) | |||
| 239 | if (!nclks) | 239 | if (!nclks) |
| 240 | return -EINVAL; | 240 | return -EINVAL; |
| 241 | 241 | ||
| 242 | cc = devm_kzalloc(dev, sizeof(*cc) + sizeof(*cc->clks) * nclks, | 242 | cc = devm_kzalloc(dev, struct_size(cc, clks, nclks), GFP_KERNEL); |
| 243 | GFP_KERNEL); | ||
| 244 | if (!cc) | 243 | if (!cc) |
| 245 | return -ENOMEM; | 244 | return -ENOMEM; |
| 246 | cc->nclks = nclks; | 245 | cc->nclks = nclks; |
diff --git a/drivers/clk/samsung/clk-exynos-audss.c b/drivers/clk/samsung/clk-exynos-audss.c index b4b057c7301c..f659c5cbf1d5 100644 --- a/drivers/clk/samsung/clk-exynos-audss.c +++ b/drivers/clk/samsung/clk-exynos-audss.c | |||
| @@ -149,8 +149,8 @@ static int exynos_audss_clk_probe(struct platform_device *pdev) | |||
| 149 | epll = ERR_PTR(-ENODEV); | 149 | epll = ERR_PTR(-ENODEV); |
| 150 | 150 | ||
| 151 | clk_data = devm_kzalloc(dev, | 151 | clk_data = devm_kzalloc(dev, |
| 152 | sizeof(*clk_data) + | 152 | struct_size(clk_data, hws, |
| 153 | sizeof(*clk_data->hws) * EXYNOS_AUDSS_MAX_CLKS, | 153 | EXYNOS_AUDSS_MAX_CLKS), |
| 154 | GFP_KERNEL); | 154 | GFP_KERNEL); |
| 155 | if (!clk_data) | 155 | if (!clk_data) |
| 156 | return -ENOMEM; | 156 | return -ENOMEM; |
diff --git a/drivers/clk/samsung/clk-exynos5433.c b/drivers/clk/samsung/clk-exynos5433.c index 5305ace514b2..162de44df099 100644 --- a/drivers/clk/samsung/clk-exynos5433.c +++ b/drivers/clk/samsung/clk-exynos5433.c | |||
| @@ -5505,8 +5505,8 @@ static int __init exynos5433_cmu_probe(struct platform_device *pdev) | |||
| 5505 | 5505 | ||
| 5506 | info = of_device_get_match_data(dev); | 5506 | info = of_device_get_match_data(dev); |
| 5507 | 5507 | ||
| 5508 | data = devm_kzalloc(dev, sizeof(*data) + | 5508 | data = devm_kzalloc(dev, |
| 5509 | sizeof(*data->ctx.clk_data.hws) * info->nr_clk_ids, | 5509 | struct_size(data, ctx.clk_data.hws, info->nr_clk_ids), |
| 5510 | GFP_KERNEL); | 5510 | GFP_KERNEL); |
| 5511 | if (!data) | 5511 | if (!data) |
| 5512 | return -ENOMEM; | 5512 | return -ENOMEM; |
diff --git a/drivers/clk/samsung/clk-s3c2410-dclk.c b/drivers/clk/samsung/clk-s3c2410-dclk.c index 077df3e539a7..66a904758761 100644 --- a/drivers/clk/samsung/clk-s3c2410-dclk.c +++ b/drivers/clk/samsung/clk-s3c2410-dclk.c | |||
| @@ -247,9 +247,10 @@ static int s3c24xx_dclk_probe(struct platform_device *pdev) | |||
| 247 | struct clk_hw **clk_table; | 247 | struct clk_hw **clk_table; |
| 248 | int ret, i; | 248 | int ret, i; |
| 249 | 249 | ||
| 250 | s3c24xx_dclk = devm_kzalloc(&pdev->dev, sizeof(*s3c24xx_dclk) + | 250 | s3c24xx_dclk = devm_kzalloc(&pdev->dev, |
| 251 | sizeof(*s3c24xx_dclk->clk_data.hws) * DCLK_MAX_CLKS, | 251 | struct_size(s3c24xx_dclk, clk_data.hws, |
| 252 | GFP_KERNEL); | 252 | DCLK_MAX_CLKS), |
| 253 | GFP_KERNEL); | ||
| 253 | if (!s3c24xx_dclk) | 254 | if (!s3c24xx_dclk) |
| 254 | return -ENOMEM; | 255 | return -ENOMEM; |
| 255 | 256 | ||
diff --git a/drivers/clk/samsung/clk-s5pv210-audss.c b/drivers/clk/samsung/clk-s5pv210-audss.c index b9641414ddc6..22b18e728b88 100644 --- a/drivers/clk/samsung/clk-s5pv210-audss.c +++ b/drivers/clk/samsung/clk-s5pv210-audss.c | |||
| @@ -81,8 +81,7 @@ static int s5pv210_audss_clk_probe(struct platform_device *pdev) | |||
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | clk_data = devm_kzalloc(&pdev->dev, | 83 | clk_data = devm_kzalloc(&pdev->dev, |
| 84 | sizeof(*clk_data) + | 84 | struct_size(clk_data, hws, AUDSS_MAX_CLKS), |
| 85 | sizeof(*clk_data->hws) * AUDSS_MAX_CLKS, | ||
| 86 | GFP_KERNEL); | 85 | GFP_KERNEL); |
| 87 | 86 | ||
| 88 | if (!clk_data) | 87 | if (!clk_data) |
diff --git a/drivers/dma/bcm-sba-raid.c b/drivers/dma/bcm-sba-raid.c index 3956a018bf5a..72878ac5c78d 100644 --- a/drivers/dma/bcm-sba-raid.c +++ b/drivers/dma/bcm-sba-raid.c | |||
| @@ -1499,9 +1499,8 @@ static int sba_prealloc_channel_resources(struct sba_device *sba) | |||
| 1499 | 1499 | ||
| 1500 | for (i = 0; i < sba->max_req; i++) { | 1500 | for (i = 0; i < sba->max_req; i++) { |
| 1501 | req = devm_kzalloc(sba->dev, | 1501 | req = devm_kzalloc(sba->dev, |
| 1502 | sizeof(*req) + | 1502 | struct_size(req, cmds, sba->max_cmd_per_req), |
| 1503 | sba->max_cmd_per_req * sizeof(req->cmds[0]), | 1503 | GFP_KERNEL); |
| 1504 | GFP_KERNEL); | ||
| 1505 | if (!req) { | 1504 | if (!req) { |
| 1506 | ret = -ENOMEM; | 1505 | ret = -ENOMEM; |
| 1507 | goto fail_free_cmds_pool; | 1506 | goto fail_free_cmds_pool; |
diff --git a/drivers/dma/nbpfaxi.c b/drivers/dma/nbpfaxi.c index 50559338239b..2f9974ddfbb2 100644 --- a/drivers/dma/nbpfaxi.c +++ b/drivers/dma/nbpfaxi.c | |||
| @@ -1305,8 +1305,8 @@ static int nbpf_probe(struct platform_device *pdev) | |||
| 1305 | cfg = of_device_get_match_data(dev); | 1305 | cfg = of_device_get_match_data(dev); |
| 1306 | num_channels = cfg->num_channels; | 1306 | num_channels = cfg->num_channels; |
| 1307 | 1307 | ||
| 1308 | nbpf = devm_kzalloc(dev, sizeof(*nbpf) + num_channels * | 1308 | nbpf = devm_kzalloc(dev, struct_size(nbpf, chan, num_channels), |
| 1309 | sizeof(nbpf->chan[0]), GFP_KERNEL); | 1309 | GFP_KERNEL); |
| 1310 | if (!nbpf) | 1310 | if (!nbpf) |
| 1311 | return -ENOMEM; | 1311 | return -ENOMEM; |
| 1312 | 1312 | ||
diff --git a/drivers/dma/sprd-dma.c b/drivers/dma/sprd-dma.c index b106e8a60af6..52ebccb483be 100644 --- a/drivers/dma/sprd-dma.c +++ b/drivers/dma/sprd-dma.c | |||
| @@ -805,8 +805,8 @@ static int sprd_dma_probe(struct platform_device *pdev) | |||
| 805 | return ret; | 805 | return ret; |
| 806 | } | 806 | } |
| 807 | 807 | ||
| 808 | sdev = devm_kzalloc(&pdev->dev, sizeof(*sdev) + | 808 | sdev = devm_kzalloc(&pdev->dev, |
| 809 | sizeof(*dma_chn) * chn_count, | 809 | struct_size(sdev, channels, chn_count), |
| 810 | GFP_KERNEL); | 810 | GFP_KERNEL); |
| 811 | if (!sdev) | 811 | if (!sdev) |
| 812 | return -ENOMEM; | 812 | return -ENOMEM; |
diff --git a/drivers/gpio/gpio-uniphier.c b/drivers/gpio/gpio-uniphier.c index 761d8279abca..d3cf9502e7e7 100644 --- a/drivers/gpio/gpio-uniphier.c +++ b/drivers/gpio/gpio-uniphier.c | |||
| @@ -371,8 +371,7 @@ static int uniphier_gpio_probe(struct platform_device *pdev) | |||
| 371 | return ret; | 371 | return ret; |
| 372 | 372 | ||
| 373 | nregs = uniphier_gpio_get_nbanks(ngpios) * 2 + 3; | 373 | nregs = uniphier_gpio_get_nbanks(ngpios) * 2 + 3; |
| 374 | priv = devm_kzalloc(dev, | 374 | priv = devm_kzalloc(dev, struct_size(priv, saved_vals, nregs), |
| 375 | sizeof(*priv) + sizeof(priv->saved_vals[0]) * nregs, | ||
| 376 | GFP_KERNEL); | 375 | GFP_KERNEL); |
| 377 | if (!priv) | 376 | if (!priv) |
| 378 | return -ENOMEM; | 377 | return -ENOMEM; |
diff --git a/drivers/hwspinlock/sirf_hwspinlock.c b/drivers/hwspinlock/sirf_hwspinlock.c index 16018544d431..cb38e487c6c4 100644 --- a/drivers/hwspinlock/sirf_hwspinlock.c +++ b/drivers/hwspinlock/sirf_hwspinlock.c | |||
| @@ -62,8 +62,10 @@ static int sirf_hwspinlock_probe(struct platform_device *pdev) | |||
| 62 | if (!pdev->dev.of_node) | 62 | if (!pdev->dev.of_node) |
| 63 | return -ENODEV; | 63 | return -ENODEV; |
| 64 | 64 | ||
| 65 | hwspin = devm_kzalloc(&pdev->dev, sizeof(*hwspin) + | 65 | hwspin = devm_kzalloc(&pdev->dev, |
| 66 | sizeof(*hwlock) * HW_SPINLOCK_NUMBER, GFP_KERNEL); | 66 | struct_size(hwspin, bank.lock, |
| 67 | HW_SPINLOCK_NUMBER), | ||
| 68 | GFP_KERNEL); | ||
| 67 | if (!hwspin) | 69 | if (!hwspin) |
| 68 | return -ENOMEM; | 70 | return -ENOMEM; |
| 69 | 71 | ||
diff --git a/drivers/input/keyboard/cap11xx.c b/drivers/input/keyboard/cap11xx.c index 1a1eacae3ea1..312916f99597 100644 --- a/drivers/input/keyboard/cap11xx.c +++ b/drivers/input/keyboard/cap11xx.c | |||
| @@ -357,8 +357,7 @@ static int cap11xx_i2c_probe(struct i2c_client *i2c_client, | |||
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | priv = devm_kzalloc(dev, | 359 | priv = devm_kzalloc(dev, |
| 360 | sizeof(*priv) + | 360 | struct_size(priv, keycodes, cap->num_channels), |
| 361 | cap->num_channels * sizeof(priv->keycodes[0]), | ||
| 362 | GFP_KERNEL); | 361 | GFP_KERNEL); |
| 363 | if (!priv) | 362 | if (!priv) |
| 364 | return -ENOMEM; | 363 | return -ENOMEM; |
diff --git a/drivers/mfd/qcom-pm8xxx.c b/drivers/mfd/qcom-pm8xxx.c index f08758f6b418..e6e8d81c15fd 100644 --- a/drivers/mfd/qcom-pm8xxx.c +++ b/drivers/mfd/qcom-pm8xxx.c | |||
| @@ -563,8 +563,8 @@ static int pm8xxx_probe(struct platform_device *pdev) | |||
| 563 | pr_info("PMIC revision 2: %02X\n", val); | 563 | pr_info("PMIC revision 2: %02X\n", val); |
| 564 | rev |= val << BITS_PER_BYTE; | 564 | rev |= val << BITS_PER_BYTE; |
| 565 | 565 | ||
| 566 | chip = devm_kzalloc(&pdev->dev, sizeof(*chip) + | 566 | chip = devm_kzalloc(&pdev->dev, |
| 567 | sizeof(chip->config[0]) * data->num_irqs, | 567 | struct_size(chip, config, data->num_irqs), |
| 568 | GFP_KERNEL); | 568 | GFP_KERNEL); |
| 569 | if (!chip) | 569 | if (!chip) |
| 570 | return -ENOMEM; | 570 | return -ENOMEM; |
diff --git a/drivers/misc/cb710/core.c b/drivers/misc/cb710/core.c index fb397e7d1cce..4d4acf763b65 100644 --- a/drivers/misc/cb710/core.c +++ b/drivers/misc/cb710/core.c | |||
| @@ -232,8 +232,8 @@ static int cb710_probe(struct pci_dev *pdev, | |||
| 232 | if (val & CB710_SLOT_SM) | 232 | if (val & CB710_SLOT_SM) |
| 233 | ++n; | 233 | ++n; |
| 234 | 234 | ||
| 235 | chip = devm_kzalloc(&pdev->dev, | 235 | chip = devm_kzalloc(&pdev->dev, struct_size(chip, slot, n), |
| 236 | sizeof(*chip) + n * sizeof(*chip->slot), GFP_KERNEL); | 236 | GFP_KERNEL); |
| 237 | if (!chip) | 237 | if (!chip) |
| 238 | return -ENOMEM; | 238 | return -ENOMEM; |
| 239 | 239 | ||
diff --git a/drivers/mtd/spi-nor/aspeed-smc.c b/drivers/mtd/spi-nor/aspeed-smc.c index 8d3cbe27efb6..95e54468cf7d 100644 --- a/drivers/mtd/spi-nor/aspeed-smc.c +++ b/drivers/mtd/spi-nor/aspeed-smc.c | |||
| @@ -861,8 +861,9 @@ static int aspeed_smc_probe(struct platform_device *pdev) | |||
| 861 | return -ENODEV; | 861 | return -ENODEV; |
| 862 | info = match->data; | 862 | info = match->data; |
| 863 | 863 | ||
| 864 | controller = devm_kzalloc(&pdev->dev, sizeof(*controller) + | 864 | controller = devm_kzalloc(&pdev->dev, |
| 865 | info->nce * sizeof(controller->chips[0]), GFP_KERNEL); | 865 | struct_size(controller, chips, info->nce), |
| 866 | GFP_KERNEL); | ||
| 866 | if (!controller) | 867 | if (!controller) |
| 867 | return -ENOMEM; | 868 | return -ENOMEM; |
| 868 | controller->info = info; | 869 | controller->info = info; |
diff --git a/drivers/net/can/peak_canfd/peak_pciefd_main.c b/drivers/net/can/peak_canfd/peak_pciefd_main.c index 3c51a884db87..b9e28578bc7b 100644 --- a/drivers/net/can/peak_canfd/peak_pciefd_main.c +++ b/drivers/net/can/peak_canfd/peak_pciefd_main.c | |||
| @@ -752,8 +752,7 @@ static int peak_pciefd_probe(struct pci_dev *pdev, | |||
| 752 | can_count = 1; | 752 | can_count = 1; |
| 753 | 753 | ||
| 754 | /* allocate board structure object */ | 754 | /* allocate board structure object */ |
| 755 | pciefd = devm_kzalloc(&pdev->dev, sizeof(*pciefd) + | 755 | pciefd = devm_kzalloc(&pdev->dev, struct_size(pciefd, can, can_count), |
| 756 | can_count * sizeof(*pciefd->can), | ||
| 757 | GFP_KERNEL); | 756 | GFP_KERNEL); |
| 758 | if (!pciefd) { | 757 | if (!pciefd) { |
| 759 | err = -ENOMEM; | 758 | err = -ENOMEM; |
diff --git a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c index 288e6567ceb1..c399f0932af5 100644 --- a/drivers/pinctrl/samsung/pinctrl-s3c64xx.c +++ b/drivers/pinctrl/samsung/pinctrl-s3c64xx.c | |||
| @@ -483,8 +483,8 @@ static int s3c64xx_eint_gpio_init(struct samsung_pinctrl_drv_data *d) | |||
| 483 | ++nr_domains; | 483 | ++nr_domains; |
| 484 | } | 484 | } |
| 485 | 485 | ||
| 486 | data = devm_kzalloc(dev, sizeof(*data) | 486 | data = devm_kzalloc(dev, struct_size(data, domains, nr_domains), |
| 487 | + nr_domains * sizeof(*data->domains), GFP_KERNEL); | 487 | GFP_KERNEL); |
| 488 | if (!data) | 488 | if (!data) |
| 489 | return -ENOMEM; | 489 | return -ENOMEM; |
| 490 | data->drvdata = d; | 490 | data->drvdata = d; |
diff --git a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c index ec0f77afeaa4..add8e870667b 100644 --- a/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c +++ b/drivers/pinctrl/uniphier/pinctrl-uniphier-core.c | |||
| @@ -759,8 +759,7 @@ static int uniphier_pinctrl_add_reg_region(struct device *dev, | |||
| 759 | 759 | ||
| 760 | nregs = DIV_ROUND_UP(count * width, 32); | 760 | nregs = DIV_ROUND_UP(count * width, 32); |
| 761 | 761 | ||
| 762 | region = devm_kzalloc(dev, | 762 | region = devm_kzalloc(dev, struct_size(region, vals, nregs), |
| 763 | sizeof(*region) + sizeof(region->vals[0]) * nregs, | ||
| 764 | GFP_KERNEL); | 763 | GFP_KERNEL); |
| 765 | if (!region) | 764 | if (!region) |
| 766 | return -ENOMEM; | 765 | return -ENOMEM; |
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c index fe4c7d677f9c..0e0277bd91a8 100644 --- a/drivers/regulator/mc13783-regulator.c +++ b/drivers/regulator/mc13783-regulator.c | |||
| @@ -409,9 +409,9 @@ static int mc13783_regulator_probe(struct platform_device *pdev) | |||
| 409 | if (num_regulators <= 0) | 409 | if (num_regulators <= 0) |
| 410 | return -EINVAL; | 410 | return -EINVAL; |
| 411 | 411 | ||
| 412 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + | 412 | priv = devm_kzalloc(&pdev->dev, |
| 413 | num_regulators * sizeof(priv->regulators[0]), | 413 | struct_size(priv, regulators, num_regulators), |
| 414 | GFP_KERNEL); | 414 | GFP_KERNEL); |
| 415 | if (!priv) | 415 | if (!priv) |
| 416 | return -ENOMEM; | 416 | return -ENOMEM; |
| 417 | 417 | ||
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c index 0d17c9206816..15dd7bc7b529 100644 --- a/drivers/regulator/mc13892-regulator.c +++ b/drivers/regulator/mc13892-regulator.c | |||
| @@ -547,9 +547,9 @@ static int mc13892_regulator_probe(struct platform_device *pdev) | |||
| 547 | if (num_regulators <= 0) | 547 | if (num_regulators <= 0) |
| 548 | return -EINVAL; | 548 | return -EINVAL; |
| 549 | 549 | ||
| 550 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv) + | 550 | priv = devm_kzalloc(&pdev->dev, |
| 551 | num_regulators * sizeof(priv->regulators[0]), | 551 | struct_size(priv, regulators, num_regulators), |
| 552 | GFP_KERNEL); | 552 | GFP_KERNEL); |
| 553 | if (!priv) | 553 | if (!priv) |
| 554 | return -ENOMEM; | 554 | return -ENOMEM; |
| 555 | 555 | ||
diff --git a/drivers/rtc/rtc-ac100.c b/drivers/rtc/rtc-ac100.c index 3fe576fdd45e..784b676284bf 100644 --- a/drivers/rtc/rtc-ac100.c +++ b/drivers/rtc/rtc-ac100.c | |||
| @@ -317,10 +317,10 @@ static int ac100_rtc_register_clks(struct ac100_rtc_dev *chip) | |||
| 317 | const char *parents[2] = {AC100_RTC_32K_NAME}; | 317 | const char *parents[2] = {AC100_RTC_32K_NAME}; |
| 318 | int i, ret; | 318 | int i, ret; |
| 319 | 319 | ||
| 320 | chip->clk_data = devm_kzalloc(chip->dev, sizeof(*chip->clk_data) + | 320 | chip->clk_data = devm_kzalloc(chip->dev, |
| 321 | sizeof(*chip->clk_data->hws) * | 321 | struct_size(chip->clk_data, hws, |
| 322 | AC100_CLKOUT_NUM, | 322 | AC100_CLKOUT_NUM), |
| 323 | GFP_KERNEL); | 323 | GFP_KERNEL); |
| 324 | if (!chip->clk_data) | 324 | if (!chip->clk_data) |
| 325 | return -ENOMEM; | 325 | return -ENOMEM; |
| 326 | 326 | ||
diff --git a/drivers/soc/actions/owl-sps.c b/drivers/soc/actions/owl-sps.c index 8477f0f18e24..032921d8d41f 100644 --- a/drivers/soc/actions/owl-sps.c +++ b/drivers/soc/actions/owl-sps.c | |||
| @@ -117,8 +117,8 @@ static int owl_sps_probe(struct platform_device *pdev) | |||
| 117 | 117 | ||
| 118 | sps_info = match->data; | 118 | sps_info = match->data; |
| 119 | 119 | ||
| 120 | sps = devm_kzalloc(&pdev->dev, sizeof(*sps) + | 120 | sps = devm_kzalloc(&pdev->dev, |
| 121 | sps_info->num_domains * sizeof(sps->domains[0]), | 121 | struct_size(sps, domains, sps_info->num_domains), |
| 122 | GFP_KERNEL); | 122 | GFP_KERNEL); |
| 123 | if (!sps) | 123 | if (!sps) |
| 124 | return -ENOMEM; | 124 | return -ENOMEM; |
diff --git a/drivers/soc/rockchip/pm_domains.c b/drivers/soc/rockchip/pm_domains.c index 53efc386b1ad..111c44fc1c12 100644 --- a/drivers/soc/rockchip/pm_domains.c +++ b/drivers/soc/rockchip/pm_domains.c | |||
| @@ -626,8 +626,7 @@ static int rockchip_pm_domain_probe(struct platform_device *pdev) | |||
| 626 | pmu_info = match->data; | 626 | pmu_info = match->data; |
| 627 | 627 | ||
| 628 | pmu = devm_kzalloc(dev, | 628 | pmu = devm_kzalloc(dev, |
| 629 | sizeof(*pmu) + | 629 | struct_size(pmu, domains, pmu_info->num_domains), |
| 630 | pmu_info->num_domains * sizeof(pmu->domains[0]), | ||
| 631 | GFP_KERNEL); | 630 | GFP_KERNEL); |
| 632 | if (!pmu) | 631 | if (!pmu) |
| 633 | return -ENOMEM; | 632 | return -ENOMEM; |
diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 3f9fe6aa51cc..c2c34425279d 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c | |||
| @@ -112,7 +112,6 @@ static int tsens_probe(struct platform_device *pdev) | |||
| 112 | int ret, i; | 112 | int ret, i; |
| 113 | struct device *dev; | 113 | struct device *dev; |
| 114 | struct device_node *np; | 114 | struct device_node *np; |
| 115 | struct tsens_sensor *s; | ||
| 116 | struct tsens_device *tmdev; | 115 | struct tsens_device *tmdev; |
| 117 | const struct tsens_data *data; | 116 | const struct tsens_data *data; |
| 118 | const struct of_device_id *id; | 117 | const struct of_device_id *id; |
| @@ -135,8 +134,9 @@ static int tsens_probe(struct platform_device *pdev) | |||
| 135 | return -EINVAL; | 134 | return -EINVAL; |
| 136 | } | 135 | } |
| 137 | 136 | ||
| 138 | tmdev = devm_kzalloc(dev, sizeof(*tmdev) + | 137 | tmdev = devm_kzalloc(dev, |
| 139 | data->num_sensors * sizeof(*s), GFP_KERNEL); | 138 | struct_size(tmdev, sensor, data->num_sensors), |
| 139 | GFP_KERNEL); | ||
| 140 | if (!tmdev) | 140 | if (!tmdev) |
| 141 | return -ENOMEM; | 141 | return -ENOMEM; |
| 142 | 142 | ||
diff --git a/sound/soc/qcom/apq8016_sbc.c b/sound/soc/qcom/apq8016_sbc.c index 704428735e3c..1dd23bba1bed 100644 --- a/sound/soc/qcom/apq8016_sbc.c +++ b/sound/soc/qcom/apq8016_sbc.c | |||
| @@ -147,7 +147,8 @@ static struct apq8016_sbc_data *apq8016_sbc_parse_of(struct snd_soc_card *card) | |||
| 147 | num_links = of_get_child_count(node); | 147 | num_links = of_get_child_count(node); |
| 148 | 148 | ||
| 149 | /* Allocate the private data and the DAI link array */ | 149 | /* Allocate the private data and the DAI link array */ |
| 150 | data = devm_kzalloc(dev, sizeof(*data) + sizeof(*link) * num_links, | 150 | data = devm_kzalloc(dev, |
| 151 | struct_size(data, dai_link, num_links), | ||
| 151 | GFP_KERNEL); | 152 | GFP_KERNEL); |
| 152 | if (!data) | 153 | if (!data) |
| 153 | return ERR_PTR(-ENOMEM); | 154 | return ERR_PTR(-ENOMEM); |
