diff mbox series

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

Message ID 20230816020355.3002617-1-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/fsl-edma.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Vinod Koul Aug. 21, 2023, 5:47 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.
> 
> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
> ---
>  drivers/dma/fsl-edma.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
> index e40769666e39..caca3566ba82 100644
> --- a/drivers/dma/fsl-edma.c
> +++ b/drivers/dma/fsl-edma.c
> @@ -270,7 +270,6 @@ 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 ret, i;
> @@ -288,7 +287,7 @@ static int fsl_edma_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> -	len = sizeof(*fsl_edma) + sizeof(*fsl_chan) * chans;
> +	len = struct_size(fsl_edma, chans, chans);
>  	fsl_edma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);

Drop len and use struct_size() here...

>  	if (!fsl_edma)
>  		return -ENOMEM;
> -- 
> 2.25.1
Yu Liao Aug. 21, 2023, 6:06 a.m. UTC | #2
On 2023/8/21 13:47, Vinod Koul wrote:
> 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.
>>
>> Signed-off-by: Yu Liao <liaoyu15@huawei.com>
>> ---
>>  drivers/dma/fsl-edma.c | 3 +--
>>  1 file changed, 1 insertion(+), 2 deletions(-)
>>
>> diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
>> index e40769666e39..caca3566ba82 100644
>> --- a/drivers/dma/fsl-edma.c
>> +++ b/drivers/dma/fsl-edma.c
>> @@ -270,7 +270,6 @@ 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 ret, i;
>> @@ -288,7 +287,7 @@ static int fsl_edma_probe(struct platform_device *pdev)
>>  		return ret;
>>  	}
>>  
>> -	len = sizeof(*fsl_edma) + sizeof(*fsl_chan) * chans;
>> +	len = struct_size(fsl_edma, chans, chans);
>>  	fsl_edma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
> 
> Drop len and use struct_size() here...

Thank you for the review. I'll make the suggested changes and send you
the V2.

Best regards,
Yu
> 
>>  	if (!fsl_edma)
>>  		return -ENOMEM;
>> -- 
>> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
index e40769666e39..caca3566ba82 100644
--- a/drivers/dma/fsl-edma.c
+++ b/drivers/dma/fsl-edma.c
@@ -270,7 +270,6 @@  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 ret, i;
@@ -288,7 +287,7 @@  static int fsl_edma_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	len = sizeof(*fsl_edma) + sizeof(*fsl_chan) * chans;
+	len = struct_size(fsl_edma, chans, chans);
 	fsl_edma = devm_kzalloc(&pdev->dev, len, GFP_KERNEL);
 	if (!fsl_edma)
 		return -ENOMEM;