* [PATCH -next 1/2] dmaengine: fsl-edma: use struct_size() helper
@ 2023-08-16 2:03 Yu Liao
2023-08-16 2:03 ` [PATCH -next 2/2] dmaengine: mcf-edma: " Yu Liao
2023-08-21 5:47 ` [PATCH -next 1/2] dmaengine: fsl-edma: " Vinod Koul
0 siblings, 2 replies; 5+ messages in thread
From: Yu Liao @ 2023-08-16 2:03 UTC (permalink / raw)
To: vkoul; +Cc: liaoyu15, liwei391, dmaengine
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);
if (!fsl_edma)
return -ENOMEM;
--
2.25.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH -next 2/2] dmaengine: mcf-edma: use struct_size() helper
2023-08-16 2:03 [PATCH -next 1/2] dmaengine: fsl-edma: use struct_size() helper Yu Liao
@ 2023-08-16 2:03 ` Yu Liao
2023-08-21 5:48 ` Vinod Koul
2023-08-21 5:47 ` [PATCH -next 1/2] dmaengine: fsl-edma: " Vinod Koul
1 sibling, 1 reply; 5+ messages in thread
From: Yu Liao @ 2023-08-16 2:03 UTC (permalink / raw)
To: vkoul; +Cc: liaoyu15, liwei391, dmaengine
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(-)
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
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH -next 2/2] dmaengine: mcf-edma: use struct_size() helper
2023-08-16 2:03 ` [PATCH -next 2/2] dmaengine: mcf-edma: " Yu Liao
@ 2023-08-21 5:48 ` Vinod Koul
0 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2023-08-21 5:48 UTC (permalink / raw)
To: Yu Liao; +Cc: liwei391, dmaengine
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
--
~Vinod
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next 1/2] dmaengine: fsl-edma: use struct_size() helper
2023-08-16 2:03 [PATCH -next 1/2] dmaengine: fsl-edma: use struct_size() helper Yu Liao
2023-08-16 2:03 ` [PATCH -next 2/2] dmaengine: mcf-edma: " Yu Liao
@ 2023-08-21 5:47 ` Vinod Koul
2023-08-21 6:06 ` Yu Liao
1 sibling, 1 reply; 5+ messages in thread
From: Vinod Koul @ 2023-08-21 5:47 UTC (permalink / raw)
To: Yu Liao; +Cc: liwei391, dmaengine
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
--
~Vinod
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next 1/2] dmaengine: fsl-edma: use struct_size() helper
2023-08-21 5:47 ` [PATCH -next 1/2] dmaengine: fsl-edma: " Vinod Koul
@ 2023-08-21 6:06 ` Yu Liao
0 siblings, 0 replies; 5+ messages in thread
From: Yu Liao @ 2023-08-21 6:06 UTC (permalink / raw)
To: Vinod Koul; +Cc: liwei391, dmaengine
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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-21 6:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-16 2:03 [PATCH -next 1/2] dmaengine: fsl-edma: use struct_size() helper Yu Liao
2023-08-16 2:03 ` [PATCH -next 2/2] dmaengine: mcf-edma: " Yu Liao
2023-08-21 5:48 ` Vinod Koul
2023-08-21 5:47 ` [PATCH -next 1/2] dmaengine: fsl-edma: " Vinod Koul
2023-08-21 6:06 ` Yu Liao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox