* [PATCH 1/3] dmaengine: at_hdmac: check return value of of_find_device_by_node() in at_dma_xlate()
2020-08-17 11:57 [PATCH V2 0/3] do exception handling appropriately in at_dma_xlate() Yu Kuai
@ 2020-08-17 11:57 ` Yu Kuai
2020-08-17 11:57 ` [PATCH 2/3] dmaengine: at_hdmac: add missing put_device() call " Yu Kuai
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Yu Kuai @ 2020-08-17 11:57 UTC (permalink / raw)
To: ludovic.desroches, tudor.ambarus, vkoul, dan.j.williams,
nicolas.ferre, plagnioj, arnd
Cc: linux-arm-kernel, dmaengine, linux-kernel, yi.zhang, yukuai3
The reurn value of of_find_device_by_node() is not checked, thus null
pointer dereference will be triggered if of_find_device_by_node()
failed.
Fixes: bbe89c8e3d59 ("at_hdmac: move to generic DMA binding")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/dma/at_hdmac.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 45bbcd6146fd..1c941f839c42 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -1650,6 +1650,8 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
return NULL;
dmac_pdev = of_find_device_by_node(dma_spec->np);
+ if (!dmac_pdev)
+ return NULL;
dma_cap_zero(mask);
dma_cap_set(DMA_SLAVE, mask);
--
2.25.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] dmaengine: at_hdmac: add missing put_device() call in at_dma_xlate()
2020-08-17 11:57 [PATCH V2 0/3] do exception handling appropriately in at_dma_xlate() Yu Kuai
2020-08-17 11:57 ` [PATCH 1/3] dmaengine: at_hdmac: check return value of of_find_device_by_node() " Yu Kuai
@ 2020-08-17 11:57 ` Yu Kuai
2020-08-17 11:57 ` [PATCH 3/3] dmaengine: at_hdmac: add missing kfree() " Yu Kuai
2020-08-19 4:29 ` [PATCH V2 0/3] do exception handling appropriately " Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Yu Kuai @ 2020-08-17 11:57 UTC (permalink / raw)
To: ludovic.desroches, tudor.ambarus, vkoul, dan.j.williams,
nicolas.ferre, plagnioj, arnd
Cc: linux-arm-kernel, dmaengine, linux-kernel, yi.zhang, yukuai3
If of_find_device_by_node() succeed, at_dma_xlate() doesn't have a
corresponding put_device(). Thus add put_device() to fix the exception
handling for this function implementation.
Fixes: bbe89c8e3d59 ("at_hdmac: move to generic DMA binding")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/dma/at_hdmac.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 1c941f839c42..bf874367097c 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -1657,8 +1657,10 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
dma_cap_set(DMA_SLAVE, mask);
atslave = kmalloc(sizeof(*atslave), GFP_KERNEL);
- if (!atslave)
+ if (!atslave) {
+ put_device(&dmac_pdev->dev);
return NULL;
+ }
atslave->cfg = ATC_DST_H2SEL_HW | ATC_SRC_H2SEL_HW;
/*
@@ -1687,8 +1689,10 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
atslave->dma_dev = &dmac_pdev->dev;
chan = dma_request_channel(mask, at_dma_filter, atslave);
- if (!chan)
+ if (!chan) {
+ put_device(&dmac_pdev->dev);
return NULL;
+ }
atchan = to_at_dma_chan(chan);
atchan->per_if = dma_spec->args[0] & 0xff;
--
2.25.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] dmaengine: at_hdmac: add missing kfree() call in at_dma_xlate()
2020-08-17 11:57 [PATCH V2 0/3] do exception handling appropriately in at_dma_xlate() Yu Kuai
2020-08-17 11:57 ` [PATCH 1/3] dmaengine: at_hdmac: check return value of of_find_device_by_node() " Yu Kuai
2020-08-17 11:57 ` [PATCH 2/3] dmaengine: at_hdmac: add missing put_device() call " Yu Kuai
@ 2020-08-17 11:57 ` Yu Kuai
2020-08-19 4:29 ` [PATCH V2 0/3] do exception handling appropriately " Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Yu Kuai @ 2020-08-17 11:57 UTC (permalink / raw)
To: ludovic.desroches, tudor.ambarus, vkoul, dan.j.williams,
nicolas.ferre, plagnioj, arnd
Cc: linux-arm-kernel, dmaengine, linux-kernel, yi.zhang, yukuai3
If memory allocation for 'atslave' succeed, at_dma_xlate() doesn't have a
corresponding kfree() in exception handling. Thus add kfree() for this
function implementation.
Fixes: bbe89c8e3d59 ("at_hdmac: move to generic DMA binding")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
---
drivers/dma/at_hdmac.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index bf874367097c..a2cf25c6e3b3 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -1691,6 +1691,7 @@ static struct dma_chan *at_dma_xlate(struct of_phandle_args *dma_spec,
chan = dma_request_channel(mask, at_dma_filter, atslave);
if (!chan) {
put_device(&dmac_pdev->dev);
+ kfree(atslave);
return NULL;
}
--
2.25.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2 0/3] do exception handling appropriately in at_dma_xlate()
2020-08-17 11:57 [PATCH V2 0/3] do exception handling appropriately in at_dma_xlate() Yu Kuai
` (2 preceding siblings ...)
2020-08-17 11:57 ` [PATCH 3/3] dmaengine: at_hdmac: add missing kfree() " Yu Kuai
@ 2020-08-19 4:29 ` Vinod Koul
3 siblings, 0 replies; 5+ messages in thread
From: Vinod Koul @ 2020-08-19 4:29 UTC (permalink / raw)
To: Yu Kuai
Cc: ludovic.desroches, tudor.ambarus, dan.j.williams, nicolas.ferre,
plagnioj, arnd, linux-arm-kernel, dmaengine, linux-kernel,
yi.zhang
On 17-08-20, 19:57, Yu Kuai wrote:
> changes from V1:
> -separate different changes to different patches, as suggested by Vinod.
Please write proper cover letter explaining the patch series and also
the changes from v1..
I have applied the patches.
Thanks
> Yu Kuai (3):
> dmaengine: at_hdmac: check return value of of_find_device_by_node() in
> at_dma_xlate()
> dmaengine: at_hdmac: add missing put_device() call in at_dma_xlate()
> dmaengine: at_hdmac: add missing kfree() call in at_dma_xlate()
>
> drivers/dma/at_hdmac.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> --
> 2.25.4
--
~Vinod
^ permalink raw reply [flat|nested] 5+ messages in thread