diff mbox series

[-next,2/2] dmaengine: mcf-edma: use struct_size() helper

Message ID 20230816020355.3002617-2-liaoyu15@huawei.com (mailing list archive)
State Superseded
Headers show
Series [-next,1/2] dmaengine: fsl-edma: use struct_size() helper | expand

Commit Message

Yu Liao Aug. 16, 2023, 2:03 a.m. UTC
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 <liaoyu15@huawei.com>
---
 drivers/dma/mcf-edma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Vinod Koul Aug. 21, 2023, 5:48 a.m. UTC | #1
On 16-08-23, 10:03, Yu Liao wrote:
> 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.

Duplicate to 923b13838892 ("dmaengine: mcf-edma: Use struct_size()")

> 
> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
> ---
>  drivers/dma/mcf-edma.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/mcf-edma.c b/drivers/dma/mcf-edma.c
> index 9413fad08a60..444b5c1bd7dc 100644
> --- a/drivers/dma/mcf-edma.c
> +++ b/drivers/dma/mcf-edma.c
> @@ -180,7 +180,6 @@ static int mcf_edma_probe(struct platform_device *pdev)
>  {
>  	struct mcf_edma_platform_data *pdata;
>  	struct fsl_edma_engine *mcf_edma;
> -	struct fsl_edma_chan *mcf_chan;
>  	struct edma_regs *regs;
>  	int ret, i, len, chans;
>  
> @@ -197,7 +196,7 @@ static int mcf_edma_probe(struct platform_device *pdev)
>  		chans = pdata->dma_channels;
>  	}
>  
> -	len = sizeof(*mcf_edma) + sizeof(*mcf_chan) * chans;
> +	len = struct_size(mcf_edma, chans, chans);
>  	mcf_edma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
>  	if (!mcf_edma)
>  		return -ENOMEM;
> -- 
> 2.25.1
diff mbox series

Patch

diff --git a/drivers/dma/mcf-edma.c b/drivers/dma/mcf-edma.c
index 9413fad08a60..444b5c1bd7dc 100644
--- a/drivers/dma/mcf-edma.c
+++ b/drivers/dma/mcf-edma.c
@@ -180,7 +180,6 @@  static int mcf_edma_probe(struct platform_device *pdev)
 {
 	struct mcf_edma_platform_data *pdata;
 	struct fsl_edma_engine *mcf_edma;
-	struct fsl_edma_chan *mcf_chan;
 	struct edma_regs *regs;
 	int ret, i, len, chans;
 
@@ -197,7 +196,7 @@  static int mcf_edma_probe(struct platform_device *pdev)
 		chans = pdata->dma_channels;
 	}
 
-	len = sizeof(*mcf_edma) + sizeof(*mcf_chan) * chans;
+	len = struct_size(mcf_edma, chans, chans);
 	mcf_edma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
 	if (!mcf_edma)
 		return -ENOMEM;