DMA Engine development
 help / color / mirror / Atom feed
* [PATCH v1] dmaengine: ti: Add NULL check in udma_probe()
@ 2025-04-02  2:39 Henry Martin
  2025-04-17 21:51 ` Nathan Lynch
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Henry Martin @ 2025-04-02  2:39 UTC (permalink / raw)
  To: peter.ujfalusi, vkoul; +Cc: dmaengine, linux-kernel, Henry Martin

devm_kasprintf() returns NULL when memory allocation fails. Currently,
udma_probe() does not check for this case, which results in a NULL
pointer dereference.

Add NULL check after devm_kasprintf() to prevent this issue.

Fixes: 25dcb5dd7b7c ("dmaengine: ti: New driver for K3 UDMA")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 drivers/dma/ti/k3-udma.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 7ed1956b4642..f1c2f8170730 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -5582,7 +5582,8 @@ static int udma_probe(struct platform_device *pdev)
 		uc->config.dir = DMA_MEM_TO_MEM;
 		uc->name = devm_kasprintf(dev, GFP_KERNEL, "%s chan%d",
 					  dev_name(dev), i);
-
+		if (!uc->name)
+			return -ENOMEM;
 		vchan_init(&uc->vc, &ud->ddev);
 		/* Use custom vchan completion handling */
 		tasklet_setup(&uc->vc.task, udma_vchan_complete);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] dmaengine: ti: Add NULL check in udma_probe()
  2025-04-02  2:39 [PATCH v1] dmaengine: ti: Add NULL check in udma_probe() Henry Martin
@ 2025-04-17 21:51 ` Nathan Lynch
  2025-04-24  3:10 ` henry martin
  2025-05-14 15:03 ` Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Nathan Lynch @ 2025-04-17 21:51 UTC (permalink / raw)
  To: Henry Martin, peter.ujfalusi, vkoul; +Cc: dmaengine, linux-kernel, Henry Martin

Henry Martin <bsdhenrymartin@gmail.com> writes:
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> udma_probe() does not check for this case, which results in a NULL
> pointer dereference.

Yes, it does look like this would happen when uc->name is eventually
passed to dma_pool_create(), at least.

>
> Add NULL check after devm_kasprintf() to prevent this issue.
>
> Fixes: 25dcb5dd7b7c ("dmaengine: ti: New driver for K3 UDMA")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> ---
>  drivers/dma/ti/k3-udma.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
> index 7ed1956b4642..f1c2f8170730 100644
> --- a/drivers/dma/ti/k3-udma.c
> +++ b/drivers/dma/ti/k3-udma.c
> @@ -5582,7 +5582,8 @@ static int udma_probe(struct platform_device *pdev)
>  		uc->config.dir = DMA_MEM_TO_MEM;
>  		uc->name = devm_kasprintf(dev, GFP_KERNEL, "%s chan%d",
>  					  dev_name(dev), i);
> -
> +		if (!uc->name)
> +			return -ENOMEM;
>  		vchan_init(&uc->vc, &ud->ddev);
>  		/* Use custom vchan completion handling */
>  		tasklet_setup(&uc->vc.task, udma_vchan_complete);

Returning -ENOMEM directly seems fine, even though this is in a loop
200+ lines into udma_probe(). I don't see any unmanaged device resources
that need to be released before returning, and if I missed one, all the
error paths this code precedes would have the same problem.

Reviewed-by: Nathan Lynch <nathan.lynch@amd.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] dmaengine: ti: Add NULL check in udma_probe()
  2025-04-02  2:39 [PATCH v1] dmaengine: ti: Add NULL check in udma_probe() Henry Martin
  2025-04-17 21:51 ` Nathan Lynch
@ 2025-04-24  3:10 ` henry martin
  2025-05-01 10:37   ` Péter Ujfalusi
  2025-05-14 15:03 ` Vinod Koul
  2 siblings, 1 reply; 5+ messages in thread
From: henry martin @ 2025-04-24  3:10 UTC (permalink / raw)
  To: peter.ujfalusi, vkoul; +Cc: dmaengine, linux-kernel, nathan.lynch

Hi Peter, Vinod,

I hope this email finds you well. I wanted to follow up on my previous patch
submission to check if there are any additional feedback or changes you'd like
me to address. If so, I’d be happy to incorporate them and send a v2.

Please let me know your thoughts. Thanks for your time and review!

Best regards,
Henry

Henry Martin <bsdhenrymartin@gmail.com> 于2025年4月2日周三 10:39写道:
>
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> udma_probe() does not check for this case, which results in a NULL
> pointer dereference.
>
> Add NULL check after devm_kasprintf() to prevent this issue.
>
> Fixes: 25dcb5dd7b7c ("dmaengine: ti: New driver for K3 UDMA")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> ---
>  drivers/dma/ti/k3-udma.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
> index 7ed1956b4642..f1c2f8170730 100644
> --- a/drivers/dma/ti/k3-udma.c
> +++ b/drivers/dma/ti/k3-udma.c
> @@ -5582,7 +5582,8 @@ static int udma_probe(struct platform_device *pdev)
>                 uc->config.dir = DMA_MEM_TO_MEM;
>                 uc->name = devm_kasprintf(dev, GFP_KERNEL, "%s chan%d",
>                                           dev_name(dev), i);
> -
> +               if (!uc->name)
> +                       return -ENOMEM;
>                 vchan_init(&uc->vc, &ud->ddev);
>                 /* Use custom vchan completion handling */
>                 tasklet_setup(&uc->vc.task, udma_vchan_complete);
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] dmaengine: ti: Add NULL check in udma_probe()
  2025-04-24  3:10 ` henry martin
@ 2025-05-01 10:37   ` Péter Ujfalusi
  0 siblings, 0 replies; 5+ messages in thread
From: Péter Ujfalusi @ 2025-05-01 10:37 UTC (permalink / raw)
  To: henry martin, vkoul; +Cc: dmaengine, linux-kernel, nathan.lynch

Hi,

On 4/24/25 6:10 AM, henry martin wrote:
> Hi Peter, Vinod,
> 
> I hope this email finds you well. I wanted to follow up on my previous patch
> submission to check if there are any additional feedback or changes you'd like
> me to address. If so, I’d be happy to incorporate them and send a v2.

For some reason I don't have the original patch in my mailbox, but looks
good, thank you.

> Please let me know your thoughts. Thanks for your time and review!

Acked-by: Peter Ujfalusi <peter.ujfalusi@gmail.com>
> Best regards,
> Henry
> 
> Henry Martin <bsdhenrymartin@gmail.com> 于2025年4月2日周三 10:39写道:
>>
>> devm_kasprintf() returns NULL when memory allocation fails. Currently,
>> udma_probe() does not check for this case, which results in a NULL
>> pointer dereference.
>>
>> Add NULL check after devm_kasprintf() to prevent this issue.
>>
>> Fixes: 25dcb5dd7b7c ("dmaengine: ti: New driver for K3 UDMA")
>> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
>> ---
>>  drivers/dma/ti/k3-udma.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
>> index 7ed1956b4642..f1c2f8170730 100644
>> --- a/drivers/dma/ti/k3-udma.c
>> +++ b/drivers/dma/ti/k3-udma.c
>> @@ -5582,7 +5582,8 @@ static int udma_probe(struct platform_device *pdev)
>>                 uc->config.dir = DMA_MEM_TO_MEM;
>>                 uc->name = devm_kasprintf(dev, GFP_KERNEL, "%s chan%d",
>>                                           dev_name(dev), i);
>> -
>> +               if (!uc->name)
>> +                       return -ENOMEM;
>>                 vchan_init(&uc->vc, &ud->ddev);
>>                 /* Use custom vchan completion handling */
>>                 tasklet_setup(&uc->vc.task, udma_vchan_complete);
>> --
>> 2.34.1
>>

-- 
Péter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1] dmaengine: ti: Add NULL check in udma_probe()
  2025-04-02  2:39 [PATCH v1] dmaengine: ti: Add NULL check in udma_probe() Henry Martin
  2025-04-17 21:51 ` Nathan Lynch
  2025-04-24  3:10 ` henry martin
@ 2025-05-14 15:03 ` Vinod Koul
  2 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2025-05-14 15:03 UTC (permalink / raw)
  To: peter.ujfalusi, Henry Martin; +Cc: dmaengine, linux-kernel


On Wed, 02 Apr 2025 10:39:00 +0800, Henry Martin wrote:
> devm_kasprintf() returns NULL when memory allocation fails. Currently,
> udma_probe() does not check for this case, which results in a NULL
> pointer dereference.
> 
> Add NULL check after devm_kasprintf() to prevent this issue.
> 
> 
> [...]

Applied, thanks!

[1/1] dmaengine: ti: Add NULL check in udma_probe()
      commit: fd447415e74bccd7362f760d4ea727f8e1ebfe91

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-05-14 15:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02  2:39 [PATCH v1] dmaengine: ti: Add NULL check in udma_probe() Henry Martin
2025-04-17 21:51 ` Nathan Lynch
2025-04-24  3:10 ` henry martin
2025-05-01 10:37   ` Péter Ujfalusi
2025-05-14 15:03 ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox