From: Yu Liao Date: Mon, 21 Aug 2023 07:36:00 +0000 (+0800) Subject: dmaengine: fsl-edma: use struct_size() helper X-Git-Tag: v6.6.7~1989^2~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=33a0b734543ed5a44135e15f00429b94f75f2866;p=platform%2Fkernel%2Flinux-starfive.git dmaengine: fsl-edma: use struct_size() helper Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Signed-off-by: Yu Liao Link: https://lore.kernel.org/r/20230821073600.4078584-1-liaoyu15@huawei.com Signed-off-by: Vinod Koul --- diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c index e407696..8c9ee9f 100644 --- a/drivers/dma/fsl-edma.c +++ b/drivers/dma/fsl-edma.c @@ -270,9 +270,8 @@ static int fsl_edma_probe(struct platform_device *pdev) struct device_node *np = pdev->dev.of_node; struct fsl_edma_engine *fsl_edma; const struct fsl_edma_drvdata *drvdata = NULL; - struct fsl_edma_chan *fsl_chan; struct edma_regs *regs; - int len, chans; + int chans; int ret, i; if (of_id) @@ -288,8 +287,8 @@ static int fsl_edma_probe(struct platform_device *pdev) return ret; } - len = sizeof(*fsl_edma) + sizeof(*fsl_chan) * chans; - fsl_edma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); + fsl_edma = devm_kzalloc(&pdev->dev, struct_size(fsl_edma, chans, chans), + GFP_KERNEL); if (!fsl_edma) return -ENOMEM;