* [PATCH] dmaengine: Add a null pointer check to the dma_request_chan
@ 2024-01-18 3:30 Kunwu Chan
2024-01-22 11:25 ` Vinod Koul
0 siblings, 1 reply; 3+ messages in thread
From: Kunwu Chan @ 2024-01-18 3:30 UTC (permalink / raw)
To: vkoul; +Cc: dmaengine, linux-kernel, Kunwu Chan
kasprintf() returns a pointer to dynamically allocated memory
which can be NULL upon failure. Ensure the allocation was successful
by checking the pointer validity.
Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
---
drivers/dma/dmaengine.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 491b22240221..a6f808d13aa4 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -856,6 +856,8 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
#ifdef CONFIG_DEBUG_FS
chan->dbg_client_name = kasprintf(GFP_KERNEL, "%s:%s", dev_name(dev),
name);
+ if (!chan->dbg_client_name)
+ return chan;
#endif
chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: Add a null pointer check to the dma_request_chan
2024-01-18 3:30 [PATCH] dmaengine: Add a null pointer check to the dma_request_chan Kunwu Chan
@ 2024-01-22 11:25 ` Vinod Koul
2024-01-23 8:00 ` Kunwu Chan
0 siblings, 1 reply; 3+ messages in thread
From: Vinod Koul @ 2024-01-22 11:25 UTC (permalink / raw)
To: Kunwu Chan; +Cc: dmaengine, linux-kernel
On 18-01-24, 11:30, Kunwu Chan wrote:
> kasprintf() returns a pointer to dynamically allocated memory
> which can be NULL upon failure. Ensure the allocation was successful
> by checking the pointer validity.
>
> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
> ---
> drivers/dma/dmaengine.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
> index 491b22240221..a6f808d13aa4 100644
> --- a/drivers/dma/dmaengine.c
> +++ b/drivers/dma/dmaengine.c
> @@ -856,6 +856,8 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
> #ifdef CONFIG_DEBUG_FS
> chan->dbg_client_name = kasprintf(GFP_KERNEL, "%s:%s", dev_name(dev),
> name);
> + if (!chan->dbg_client_name)
> + return chan;
That is wrong, you cant return a half done channel here
Pls see rest of the code for reference
> #endif
>
> chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
> --
> 2.39.2
--
~Vinod
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] dmaengine: Add a null pointer check to the dma_request_chan
2024-01-22 11:25 ` Vinod Koul
@ 2024-01-23 8:00 ` Kunwu Chan
0 siblings, 0 replies; 3+ messages in thread
From: Kunwu Chan @ 2024-01-23 8:00 UTC (permalink / raw)
To: Vinod Koul; +Cc: dmaengine, linux-kernel
Thanks for your reply.
On 2024/1/22 19:25, Vinod Koul wrote:
> On 18-01-24, 11:30, Kunwu Chan wrote:
>> kasprintf() returns a pointer to dynamically allocated memory
>> which can be NULL upon failure. Ensure the allocation was successful
>> by checking the pointer validity.
>>
>> Signed-off-by: Kunwu Chan <chentao@kylinos.cn>
>> ---
>> drivers/dma/dmaengine.c | 2 ++
>> 1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
>> index 491b22240221..a6f808d13aa4 100644
>> --- a/drivers/dma/dmaengine.c
>> +++ b/drivers/dma/dmaengine.c
>> @@ -856,6 +856,8 @@ struct dma_chan *dma_request_chan(struct device *dev, const char *name)
>> #ifdef CONFIG_DEBUG_FS
>> chan->dbg_client_name = kasprintf(GFP_KERNEL, "%s:%s", dev_name(dev),
>> name);
>> + if (!chan->dbg_client_name)
>> + return chan;
>
> That is wrong, you cant return a half done channel here
> Pls see rest of the code for reference
I handle the error path like line 862 in 'dma_request_chan', though i
think it's not so perfect. Why it just return chan in line 862 when in
error? I would be very grateful if it could help me solve this puzzle
dma_request_chan find and return the ``name`` DMA channel associated
with the 'dev' device. The association is done via DT, ACPI or board
file based dma_slave_map matching table.
So when error occurs, just do the opposite, like in 'dma_release_channel'.
look likes:
---
chan->dbg_client_name = kasprintf(GFP_KERNEL, "%s:%s",
dev_name(dev),
name);
+ if (!chan->dbg_client_name) {
+ dma_cap_clear(DMA_SLAVE, chan->device->cap_mask);
+ dma_cap_zero(chan->device->cap_mask);
+ dma_chan_put(chan);
+ chan->slave = NULL;
+ chan = NULL;
+ return chan;
+ }
---
It's that right by clear the cap and set chan to NULL?
>
>> #endif
>>
>> chan->name = kasprintf(GFP_KERNEL, "dma:%s", name);
>> --
>> 2.39.2
>
--
Thanks,
Kunwu
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-01-23 8:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18 3:30 [PATCH] dmaengine: Add a null pointer check to the dma_request_chan Kunwu Chan
2024-01-22 11:25 ` Vinod Koul
2024-01-23 8:00 ` Kunwu Chan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.