dmaengine: Fix teardown races, resource leaks, and error handling
Subsystems (8)
v2 cover dmaengine: Fix teardown races, resource leaks, and error handling
These issues were reported by Sashiko.
v1 => v2:
- ae4dma: Make the completion work terminable, so that cancelling it can no longer hang, and stop it before destroying the descriptor cache (Basavaraj)
- jz4780: Correct the Fixes: tag
v1: https://lore.kernel.org/all/[email protected]/
Lee Jones (11):
dmaengine: pl08x: Defer OF DMA controller registration until slave
setup
dmaengine: ae4dma: Let the pending work exit before cancelling it
dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove()
dmaengine: ptdma: Unmap descriptor in pt_do_cleanup()
dmaengine: ptdma: Remove completed descriptor under vc.lock in
pt_cmd_callback_work()
dmaengine: amlogic: Destroy free_wq after devres DMA device
unregistration
dmaengine: arm-dma350: Query dma_cookie_status() under vc.lock in
d350_tx_status()
dmaengine: bestcomm: Defer publishing bcom_eng until initialisation
completes
dmaengine: bestcomm: Check rh_create() return value in
bcom_sram_init()
dmaengine: jz4780: Fix descriptor cleanup on hwdesc setup failure
dmaengine: dmatest: Avoid unsigned underflow in min_odd()
drivers/dma/amba-pl08x.c | 23 +++++++++ drivers/dma/amd/ae4dma/ae4dma-dev.c | 8 +++ drivers/dma/amd/ae4dma/ae4dma-pci.c | 6 +++ drivers/dma/amd/ae4dma/ae4dma.h | 1 + drivers/dma/amd/ptdma/ptdma-dmaengine.c | 3 +- drivers/dma/amlogic-dma.c | 3 +- drivers/dma/arm-dma350.c | 3 +- drivers/dma/bestcomm/bestcomm.c | 69 +++++++++++++------------ drivers/dma/bestcomm/sram.c | 6 +++ drivers/dma/dma-jz4780.c | 5 +- drivers/dma/dmatest.c | 6 +++ 11 files changed, 93 insertions(+), 40 deletions(-)
Signature · 1 line
2.56.0.679.gc527c65306-goog
PATCH v2 1/11 dmaengine: pl08x: Defer OF DMA controller registration until slave setup
pl08x_of_probe() registers the controller with of_dma_controller_register() before pl08x_dma_init_virtual_channels() initialises the slave channels list and before dma_async_device_register() registers the slave DMA device, and pl08x_probe() does not unregister the OF DMA controller if subsequent initialisation fails.
Move of_dma_controller_register() after dma_async_device_register() for the slave device and unwind slave device registration if OF controller registration fails.
---
v1 => v2: No changes
drivers/dma/amba-pl08x.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
drivers/dma/amba-pl08x.c +23 -0
@@ -2678,6 +2678,12 @@ static int pl08x_of_probe(struct amba_device *adev, pl08x->pd = pd; +return 0 ; +} + +static int pl08x_of_register (struct amba_device *adev, +struct pl08x_driver_data *pl08x) +{return of_dma_controller_register (adev->dev.of_node, pl08x_of_xlate, pl08x); }
@@ -2688,6 +2694,12 @@ static inline int pl08x_of_probe(struct amba_device *adev, {return -EINVAL ; } + +static inline int pl08x_of_register (struct amba_device *adev, +struct pl08x_driver_data *pl08x) +{ +return 0 ; +}#endif static int pl08x_probe (struct amba_device *adev,const struct amba_id *id)
@@ -2944,6 +2956,15 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id) __func__, ret); goto out_no_slave_reg; } +if (np) { + ret =pl08x_of_register (adev, pl08x); +if (ret) { +dev_warn (&pl08x->adev->dev, +"%s failed to register OF DMA controller - %d\n" , + __func__, ret); + goto out_no_of_dma; + } + } }amba_set_drvdata (adev, pl08x);
@@ -2954,6 +2975,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)return 0 ; +out_no_of_dma: +dma_async_device_unregister (&pl08x->slave); out_no_slave_reg:dma_async_device_unregister (&pl08x->memcpy); out_no_memcpy_reg:
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 01/11] dmaengine: pl08x: Defer OF DMA controller registration until slave setup
Quoted 7 lines · Lee Jones
pl08x_of_probe()registers the controller withof_dma_controller_register()beforepl08x_dma_init_virtual_channels()initialises the slave channels list and beforedma_async_device_register()registers the slave DMA device, andpl08x_probe()does not unregister the OF DMA controller if subsequent initialisation fails.
Quoted 8 lines
Move
of_dma_controller_register()afterdma_async_device_register()for the slave device and unwind slave device registration if OF controller registration fails.Fixes aa4734da6674 ("dmaengine: pl08x: support dt channel assignment")Signed-off-by Lee Jones <[email protected]>
Fair enough,
Yours,
Linus Walleij
Re: [PATCH v2 01/11] dmaengine: pl08x: Defer OF DMA controller registration until slave setup
In reply to Lee JonesQuoted 69 lines · Lee Jones
pl08x_of_probe()registers the controller withof_dma_controller_register()beforepl08x_dma_init_virtual_channels()initialises the slave channels list and beforedma_async_device_register()registers the slave DMA device, andpl08x_probe()does not unregister the OF DMA controller if subsequent initialisation fails.Move
of_dma_controller_register()afterdma_async_device_register()for the slave device and unwind slave device registration if OF controller registration fails.Fixes aa4734da6674 ("dmaengine: pl08x: support dt channel assignment")Signed-off-by Lee Jones <[email protected]>---
v1 => v2: No changes
drivers/dma/amba-pl08x.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)drivers/dma/amba-pl08x.c +21
-0@@ -2678,6 +2678,12 @@ static int pl08x_of_probe(struct amba_device *adev, pl08x->pd = pd; +return 0 ; +} + +static int pl08x_of_register (struct amba_device *adev, +struct pl08x_driver_data *pl08x) +{return of_dma_controller_register (adev->dev.of_node, pl08x_of_xlate, pl08x); }@@ -2688,6 +2694,12 @@ static inline int pl08x_of_probe(struct amba_device *adev, {return -EINVAL ; } + +static inline int pl08x_of_register (struct amba_device *adev, +struct pl08x_driver_data *pl08x) +{ +return 0 ; +}#endif static int pl08x_probe (struct amba_device *adev,const struct amba_id *id)@@ -2944,6 +2956,15 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id) __func__, ret); goto out_no_slave_reg; } +if (np) { + ret =pl08x_of_register (adev, pl08x); +if (ret) { +dev_warn (&pl08x->adev->dev, +"%s failed to register OF DMA controller - %d\n" , + __func__, ret); + goto out_no_of_dma; + } + } }amba_set_drvdata (adev, pl08x);
drivers/dma/amba-pl08x.c static int pl08x_probe(struct amba_device *adev, const struct amba_id *id) · line 2981
Quoted 7 lines
drivers/dma/amba-pl08x.c +2
-0@@ -2954,6 +2975,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)return 0 ; +out_no_of_dma: +dma_async_device_unregister (&pl08x->slave); out_no_slave_reg:dma_async_device_unregister (&pl08x->memcpy);
It'd better switch to dmaenginem_async_device_register()
Quoted 4 lines
drivers/dma/amba-pl08x.c +0
-1out_no_memcpy_reg: --2.56.0.679.gc527c65306-goog
PATCH v2 2/11 dmaengine: ae4dma: Let the pending work exit before cancelling it
In reply to Lee Jonesae4_pending_work() loops forever waiting for interrupts, so it never returns once it has started running, which it does 100us after probe. ae4_destroy_work() calls cancel_delayed_work_sync() on it, which waits for the running work to finish and therefore blocks indefinitely, hanging device removal and, once the work has started, the probe error path in ae4_core_init().
Add a per-queue stop flag that ae4_destroy_work() sets, then wake the queue's wait queue so that the work leaves its loop before it is cancelled and its workqueue destroyed.
---
v1 => v2: New patch, so that ae4_destroy_work() can no longer hang
drivers/dma/amd/ae4dma/ae4dma-dev.c | 8 ++++++++ drivers/dma/amd/ae4dma/ae4dma.h | 1 + 2 files changed, 9 insertions(+)
drivers/dma/amd/ae4dma/ae4dma-dev.c +8 -0
@@ -23,9 +23,13 @@ static void ae4_pending_work(struct work_struct *work)for (;;) {wait_event_interruptible (ae4cmd_q->q_w, +READ_ONCE (ae4cmd_q->stop) || ((atomic64_read (&ae4cmd_q->done_cnt)) <atomic64_read (&ae4cmd_q->intr_cnt))); +if (READ_ONCE (ae4cmd_q->stop)) +break ; +atomic64_inc (&ae4cmd_q->done_cnt);mutex_lock (&ae4cmd_q->cmd_lock);
@@ -81,6 +85,10 @@ void ae4_destroy_work(struct ae4_device *ae4)if (!ae4cmd_q->pws)break ; +/* Make ae4_pending_work() leave its loop so that it can be cancelled */ +WRITE_ONCE (ae4cmd_q->stop, true); +wake_up (&ae4cmd_q->q_w); +cancel_delayed_work_sync (&ae4cmd_q->p_work);destroy_workqueue (ae4cmd_q->pws); }
drivers/dma/amd/ae4dma/ae4dma.h +1 -0
@@ -60,6 +60,7 @@ struct ae4_cmd_queue {u32 dridx;u32 tail_wi;u32 id; +bool stop; };union dwou {
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 02/11] dmaengine: ae4dma: Let the pending work exit before cancelling it
Quoted 7 lines · Lee Jones
ae4_pending_work()loops forever waiting for interrupts, so it never returns once it has started running, which it does 100us after probe.ae4_destroy_work()callscancel_delayed_work_sync()on it, which waits for the running work to finish and therefore blocks indefinitely, hanging device removal and, once the work has started, the probe error path inae4_core_init().
Quoted 8 lines
Add a per-queue stop flag that
ae4_destroy_work()sets, then wake the queue's wait queue so that the work leaves its loop before it is cancelled and its workqueue destroyed.Fixes 90a30e268d9b ("dmaengine: ae4dma: Add AMD ae4dma controller driver")Signed-off-by Lee Jones <[email protected]>---
Quoted 51 lines
v1 => v2: New patch, so that
ae4_destroy_work()can no longer hangdrivers/dma/amd/ae4dma/ae4dma-dev.c | 8 ++++++++ drivers/dma/amd/ae4dma/ae4dma.h | 1 + 2 files changed, 9 insertions(+)drivers/dma/amd/ae4dma/ae4dma-dev.c +8
-0@@ -23,9 +23,13 @@ static void ae4_pending_work(struct work_struct *work)for (;;) {wait_event_interruptible (ae4cmd_q->q_w, +READ_ONCE (ae4cmd_q->stop) || ((atomic64_read (&ae4cmd_q->done_cnt)) <atomic64_read (&ae4cmd_q->intr_cnt))); +if (READ_ONCE (ae4cmd_q->stop)) +break ; +atomic64_inc (&ae4cmd_q->done_cnt);mutex_lock (&ae4cmd_q->cmd_lock);@@ -81,6 +85,10 @@ void ae4_destroy_work(struct ae4_device *ae4)if (!ae4cmd_q->pws)break ; +/* Make ae4_pending_work() leave its loop so that it can be cancelled */ +WRITE_ONCE (ae4cmd_q->stop, true); +wake_up (&ae4cmd_q->q_w); +cancel_delayed_work_sync (&ae4cmd_q->p_work);destroy_workqueue (ae4cmd_q->pws); }drivers/dma/amd/ae4dma/ae4dma.h +1
-1@@ -60,6 +60,7 @@ struct ae4_cmd_queue {u32 dridx;u32 tail_wi;u32 id; +bool stop; };union dwou { --2.56.0.679.gc527c65306-goog
Re: [PATCH v2 02/11] dmaengine: ae4dma: Let the pending work exit before cancelling it
In reply to Lee JonesQuoted 56 lines · Lee Jones
ae4_pending_work()loops forever waiting for interrupts, so it never returns once it has started running, which it does 100us after probe.ae4_destroy_work()callscancel_delayed_work_sync()on it, which waits for the running work to finish and therefore blocks indefinitely, hanging device removal and, once the work has started, the probe error path inae4_core_init().Add a per-queue stop flag that
ae4_destroy_work()sets, then wake the queue's wait queue so that the work leaves its loop before it is cancelled and its workqueue destroyed.Fixes 90a30e268d9b ("dmaengine: ae4dma: Add AMD ae4dma controller driver")Signed-off-by Lee Jones <[email protected]>---
v1 => v2: New patch, so that
ae4_destroy_work()can no longer hangdrivers/dma/amd/ae4dma/ae4dma-dev.c | 8 ++++++++ drivers/dma/amd/ae4dma/ae4dma.h | 1 + 2 files changed, 9 insertions(+)drivers/dma/amd/ae4dma/ae4dma-dev.c +8
-0@@ -23,9 +23,13 @@ static void ae4_pending_work(struct work_struct *work)for (;;) {wait_event_interruptible (ae4cmd_q->q_w, +READ_ONCE (ae4cmd_q->stop) || ((atomic64_read (&ae4cmd_q->done_cnt)) <atomic64_read (&ae4cmd_q->intr_cnt))); +if (READ_ONCE (ae4cmd_q->stop)) +break ; +atomic64_inc (&ae4cmd_q->done_cnt);mutex_lock (&ae4cmd_q->cmd_lock);@@ -81,6 +85,10 @@ void ae4_destroy_work(struct ae4_device *ae4)if (!ae4cmd_q->pws)break ; +/* Make ae4_pending_work() leave its loop so that it can be cancelled */ +WRITE_ONCE (ae4cmd_q->stop, true); +wake_up (&ae4cmd_q->q_w); +cancel_delayed_work_sync (&ae4cmd_q->p_work);destroy_workqueue (ae4cmd_q->pws); }drivers/dma/amd/ae4dma/ae4dma.h +0
-0
drivers/dma/amd/ae4dma/ae4dma.h struct ae4_cmd_queue { · line 66
Quoted 7 lines
drivers/dma/amd/ae4dma/ae4dma.h +1
-0@@ -60,6 +60,7 @@ struct ae4_cmd_queue {u32 dridx;u32 tail_wi;u32 id; +bool stop; };union dwou {
Thanks,
--
Basavaraj
PATCH v2 3/11 dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove()
In reply to Lee Jonesae4_core_init() registers the DMA device and creates the descriptor slab cache via pt_dmaengine_register(), but ae4_pci_remove() never undoes either, leaking the descriptor cache and leaving a dangling DMA device registered after device removal.
Unregister the DMA device first, so that no channels remain available to clients, then stop the per-queue completion work, which may still free descriptors into the cache, and only then destroy the descriptor cache. pt_dmaengine_unregister() is open-coded here because it destroys the cache immediately after unregistering, before the completion work has been stopped.
Unregistering the DMA device also removes the ptdma debugfs entries, which were previously left behind after removal, pointing at freed device data.
---
v1 => v2:
- Stop the completion work before destroying the descriptor cache
- Open-code the unregistration rather than exporting pt_dmaengine_unregister()
drivers/dma/amd/ae4dma/ae4dma-pci.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/dma/amd/ae4dma/ae4dma-pci.c +6 -0
@@ -131,8 +131,14 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)static void ae4_pci_remove (struct pci_dev *pdev) {struct ae4_device *ae4 =dev_get_drvdata (&pdev->dev); +struct pt_device *pt = &ae4->pt; +dma_async_device_unregister (&pt->dma_dev); + +/* Completion processing frees descriptors into the cache, so stop it first */ ae4_destroy_work (ae4); +kmem_cache_destroy (pt->dma_desc_cache); +ae4_deinit (ae4); }
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 03/11] dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove()
Quoted 16 lines · Lee Jones
ae4_core_init()registers the DMA device and creates the descriptor slab cache viapt_dmaengine_register(), butae4_pci_remove()never undoes either, leaking the descriptor cache and leaving a dangling DMA device registered after device removal.Unregister the DMA device first, so that no channels remain available to clients, then stop the per-queue completion work, which may still free descriptors into the cache, and only then destroy the descriptor cache.
pt_dmaengine_unregister()is open-coded here because it destroys the cache immediately after unregistering, before the completion work has been stopped.Unregistering the DMA device also removes the ptdma debugfs entries, which were previously left behind after removal, pointing at freed device data.
Quoted 5 lines
Fixes 98f5a4432622 ("dmaengine: ae4dma: Register AE4DMA using pt_dmaengine_register")Signed-off-by Lee Jones <[email protected]>---
Quoted 30 lines
v1 => v2:
- Stop the completion work before destroying the descriptor cache
- Open-code the unregistration rather than exportingpt_dmaengine_unregister()drivers/dma/amd/ae4dma/ae4dma-pci.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/dma/amd/ae4dma/ae4dma-pci.c +6
-1@@ -131,8 +131,14 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)static void ae4_pci_remove (struct pci_dev *pdev) {struct ae4_device *ae4 =dev_get_drvdata (&pdev->dev); +struct pt_device *pt = &ae4->pt; +dma_async_device_unregister (&pt->dma_dev); + +/* Completion processing frees descriptors into the cache, so stop it first */ ae4_destroy_work (ae4); +kmem_cache_destroy (pt->dma_desc_cache); +ae4_deinit (ae4); } --2.56.0.679.gc527c65306-goog
Re: [PATCH v2 03/11] dmaengine: ae4dma: Unregister DMA engine in ae4_pci_remove()
In reply to Lee JonesQuoted 38 lines · Lee Jones
ae4_core_init()registers the DMA device and creates the descriptor slab cache viapt_dmaengine_register(), butae4_pci_remove()never undoes either, leaking the descriptor cache and leaving a dangling DMA device registered after device removal.Unregister the DMA device first, so that no channels remain available to clients, then stop the per-queue completion work, which may still free descriptors into the cache, and only then destroy the descriptor cache.
pt_dmaengine_unregister()is open-coded here because it destroys the cache immediately after unregistering, before the completion work has been stopped.Unregistering the DMA device also removes the ptdma debugfs entries, which were previously left behind after removal, pointing at freed device data.
Fixes 98f5a4432622 ("dmaengine: ae4dma: Register AE4DMA using pt_dmaengine_register")Signed-off-by Lee Jones <[email protected]>---
v1 => v2:
- Stop the completion work before destroying the descriptor cache
- Open-code the unregistration rather than exportingpt_dmaengine_unregister()drivers/dma/amd/ae4dma/ae4dma-pci.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/dma/amd/ae4dma/ae4dma-pci.c +1
-0@@ -131,8 +131,14 @@ static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)static void ae4_pci_remove (struct pci_dev *pdev) {struct ae4_device *ae4 =dev_get_drvdata (&pdev->dev); +struct pt_device *pt = &ae4->pt;
drivers/dma/amd/ae4dma/ae4dma-pci.c static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 144
Quoted 10 lines
drivers/dma/amd/ae4dma/ae4dma-pci.c +5
-0+dma_async_device_unregister (&pt->dma_dev); + +/* Completion processing frees descriptors into the cache, so stop it first */ ae4_destroy_work (ae4); +kmem_cache_destroy (pt->dma_desc_cache); +ae4_deinit (ae4); }
Thanks,
--
Basavaraj
PATCH v2 4/11 dmaengine: ptdma: Unmap descriptor in pt_do_cleanup()
In reply to Lee JonesWhen descriptors are freed on abort via vchan_dma_desc_free_list(), pt_do_cleanup() frees the descriptor without calling dma_descriptor_unmap(), leaking any attached dmaengine_unmap_data and DMA mappings.
Call dma_descriptor_unmap(&vd->tx) in pt_do_cleanup() before freeing the descriptor.
---
v1 => v2: No changes
drivers/dma/amd/ptdma/ptdma-dmaengine.c | 1 + 1 file changed, 1 insertion(+)
drivers/dma/amd/ptdma/ptdma-dmaengine.c +1 -0
@@ -91,6 +91,7 @@ static void pt_do_cleanup(struct virt_dma_desc *vd)struct pt_dma_desc *desc =to_pt_desc (vd);struct pt_device *pt = desc->pt; +dma_descriptor_unmap (&vd->tx);kmem_cache_free (pt->dma_desc_cache, desc); }
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 04/11] dmaengine: ptdma: Unmap descriptor in pt_do_cleanup()
Quoted 5 lines · Lee Jones
When descriptors are freed on abort via
vchan_dma_desc_free_list(),pt_do_cleanup()frees the descriptor without callingdma_descriptor_unmap(), leaking any attacheddmaengine_unmap_dataand DMA mappings.
Quoted 8 lines
Call
dma_descriptor_unmap(&vd->tx)inpt_do_cleanup()before freeing the descriptor.Fixes b0b4a6b10577 ("dmaengine: ptdma: register PTDMA controller as a DMA resource")Signed-off-by Lee Jones <[email protected]>---
Quoted 21 lines
v1 => v2: No changes
drivers/dma/amd/ptdma/ptdma-dmaengine.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/amd/ptdma/ptdma-dmaengine.c +1
-1@@ -91,6 +91,7 @@ static void pt_do_cleanup(struct virt_dma_desc *vd)struct pt_dma_desc *desc =to_pt_desc (vd);struct pt_device *pt = desc->pt; +dma_descriptor_unmap (&vd->tx);kmem_cache_free (pt->dma_desc_cache, desc); } --2.56.0.679.gc527c65306-goog
Re: [PATCH v2 04/11] dmaengine: ptdma: Unmap descriptor in pt_do_cleanup()
In reply to Lee JonesQuoted 24 lines · Lee Jones
When descriptors are freed on abort via
vchan_dma_desc_free_list(),pt_do_cleanup()frees the descriptor without callingdma_descriptor_unmap(), leaking any attacheddmaengine_unmap_dataand DMA mappings.Call
dma_descriptor_unmap(&vd->tx)inpt_do_cleanup()before freeing the descriptor.Fixes b0b4a6b10577 ("dmaengine: ptdma: register PTDMA controller as a DMA resource")Signed-off-by Lee Jones <[email protected]>---
v1 => v2: No changes
drivers/dma/amd/ptdma/ptdma-dmaengine.c | 1 + 1 file changed, 1 insertion(+)drivers/dma/amd/ptdma/ptdma-dmaengine.c +0
-0
drivers/dma/amd/ptdma/ptdma-dmaengine.c static void pt_do_cleanup(struct virt_dma_desc *vd) · line 97
Quoted 7 lines
drivers/dma/amd/ptdma/ptdma-dmaengine.c +1
-0@@ -91,6 +91,7 @@ static void pt_do_cleanup(struct virt_dma_desc *vd)struct pt_dma_desc *desc =to_pt_desc (vd);struct pt_device *pt = desc->pt; +dma_descriptor_unmap (&vd->tx);kmem_cache_free (pt->dma_desc_cache, desc); }
Thanks,
--
Basavaraj
PATCH v2 5/11 dmaengine: ptdma: Remove completed descriptor under vc.lock in pt_cmd_callback_work()
In reply to Lee Jonespt_cmd_callback_work() drops chan->vc.lock before calling list_del(&desc->vd.node), racing with concurrent virt-dma list operations such as pt_terminate_all().
Move list_del(&desc->vd.node) inside the chan->vc.lock critical section, matching pt_handle_active_desc().
---
v1 => v2: No changes
drivers/dma/amd/ptdma/ptdma-dmaengine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/dma/amd/ptdma/ptdma-dmaengine.c +1 -1
@@ -365,6 +365,7 @@ static void pt_cmd_callback_work(void *data, int err)dma_cookie_complete (tx_desc);dma_descriptor_unmap (tx_desc); +list_del (&desc->vd.node); }else { tx_desc =NULL ; }
@@ -373,7 +374,6 @@ static void pt_cmd_callback_work(void *data, int err)if (tx_desc) {dmaengine_desc_get_callback_invoke (tx_desc,NULL );dma_run_dependencies (tx_desc); -list_del (&desc->vd.node);vchan_vdesc_fini (vd); } }
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 05/11] dmaengine: ptdma: Remove completed descriptor under vc.lock in pt_cmd_callback_work()
Quoted 4 lines · Lee Jones
pt_cmd_callback_work()dropschan->vc.lockbefore callinglist_del(&desc->vd.node), racing with concurrent virt-dma list operations such aspt_terminate_all().
Quoted 8 lines
Move
list_del(&desc->vd.node)inside thechan->vc.lockcritical section, matchingpt_handle_active_desc().Fixes 656543989457 ("dmaengine: ptdma: Utilize the AE4DMA engine's multi-queue functionality")Signed-off-by Lee Jones <[email protected]>---
Quoted 29 lines
v1 => v2: No changes
drivers/dma/amd/ptdma/ptdma-dmaengine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/dma/amd/ptdma/ptdma-dmaengine.c +1
-2@@ -365,6 +365,7 @@ static void pt_cmd_callback_work(void *data, int err)dma_cookie_complete (tx_desc);dma_descriptor_unmap (tx_desc); +list_del (&desc->vd.node); }else { tx_desc =NULL ; }@@ -373,7 +374,6 @@ static void pt_cmd_callback_work(void *data, int err)if (tx_desc) {dmaengine_desc_get_callback_invoke (tx_desc,NULL );dma_run_dependencies (tx_desc); -list_del (&desc->vd.node);vchan_vdesc_fini (vd); } } --2.56.0.679.gc527c65306-goog
Re: [PATCH v2 05/11] dmaengine: ptdma: Remove completed descriptor under vc.lock in pt_cmd_callback_work()
In reply to Lee JonesQuoted 31 lines · Lee Jones
pt_cmd_callback_work()dropschan->vc.lockbefore callinglist_del(&desc->vd.node), racing with concurrent virt-dma list operations such aspt_terminate_all().Move
list_del(&desc->vd.node)inside thechan->vc.lockcritical section, matchingpt_handle_active_desc().Fixes 656543989457 ("dmaengine: ptdma: Utilize the AE4DMA engine's multi-queue functionality")Signed-off-by Lee Jones <[email protected]>---
v1 => v2: No changes
drivers/dma/amd/ptdma/ptdma-dmaengine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/dma/amd/ptdma/ptdma-dmaengine.c +1
-0@@ -365,6 +365,7 @@ static void pt_cmd_callback_work(void *data, int err)dma_cookie_complete (tx_desc);dma_descriptor_unmap (tx_desc); +list_del (&desc->vd.node); }else { tx_desc =NULL ; }
drivers/dma/amd/ptdma/ptdma-dmaengine.c static void pt_cmd_callback_work(void *data, int err) · line 379
Quoted 7 lines
drivers/dma/amd/ptdma/ptdma-dmaengine.c +0
-1@@ -373,7 +374,6 @@ static void pt_cmd_callback_work(void *data, int err)if (tx_desc) {dmaengine_desc_get_callback_invoke (tx_desc,NULL );dma_run_dependencies (tx_desc); -list_del (&desc->vd.node);vchan_vdesc_fini (vd); } }
Thanks,
--
Basavaraj
PATCH v2 6/11 dmaengine: amlogic: Destroy free_wq after devres DMA device unregistration
In reply to Lee Jonesaml_dma_probe() registers the DMA device with dmaenginem_async_device_register(), so dma_async_device_unregister() is deferred until devres release after aml_dma_remove() returns. However, aml_dma_remove() destroys aml_dma->free_wq directly, causing aml_dma_free_desc() to queue work onto a destroyed workqueue when channels and descriptors are released during devres teardown, and early error returns in aml_dma_probe() also leak aml_dma->free_wq.
Allocate aml_dma->free_wq with devm_alloc_ordered_workqueue() so it is destroyed on probe failure and after dmaenginem_async_device_register() unwinds on removal.
---
v1 => v2: No changes
drivers/dma/amlogic-dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/amlogic-dma.c +1 -2
@@ -620,7 +620,7 @@ static int aml_dma_probe(struct platform_device *pdev)if (!aml_dma)return -ENOMEM ; - aml_dma->free_wq =alloc_ordered_workqueue ("aml_dma_free" ,0 ); + aml_dma->free_wq =devm_alloc_ordered_workqueue (&pdev->dev,"aml_dma_free" ,0 );if (!aml_dma->free_wq)return -ENOMEM ;
@@ -712,7 +712,6 @@ static void aml_dma_remove(struct platform_device *pdev)if (aml_chan)tasklet_kill (&aml_chan->vchan.task); } -destroy_workqueue (aml_dma->free_wq); }static const struct of_device_id aml_dma_ids[] = {
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 06/11] dmaengine: amlogic: Destroy free_wq after devres DMA device unregistration
Quoted 12 lines · Lee Jones
aml_dma_probe()registers the DMA device withdmaenginem_async_device_register(), sodma_async_device_unregister()is deferred until devres release afteraml_dma_remove()returns. However,aml_dma_remove()destroysaml_dma->free_wqdirectly, causingaml_dma_free_desc()to queue work onto a destroyed workqueue when channels and descriptors are released during devres teardown, and early error returns inaml_dma_probe()also leakaml_dma->free_wq.Allocate
aml_dma->free_wqwithdevm_alloc_ordered_workqueue()so it is destroyed on probe failure and afterdmaenginem_async_device_register()unwinds on removal.
Quoted 5 lines
Fixes b84b5197e344 ("dmaengine: amlogic: Add general DMA driver for A9")Signed-off-by Lee Jones <[email protected]>---
Quoted 30 lines
v1 => v2: No changes
drivers/dma/amlogic-dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/dma/amlogic-dma.c +1
-3@@ -620,7 +620,7 @@ static int aml_dma_probe(struct platform_device *pdev)if (!aml_dma)return -ENOMEM ; - aml_dma->free_wq =alloc_ordered_workqueue ("aml_dma_free" ,0 ); + aml_dma->free_wq =devm_alloc_ordered_workqueue (&pdev->dev,"aml_dma_free" ,0 );if (!aml_dma->free_wq)return -ENOMEM ;@@ -712,7 +712,6 @@ static void aml_dma_remove(struct platform_device *pdev)if (aml_chan)tasklet_kill (&aml_chan->vchan.task); } -destroy_workqueue (aml_dma->free_wq); }static const struct of_device_id aml_dma_ids[] = { --2.56.0.679.gc527c65306-goog
PATCH v2 7/11 dmaengine: arm-dma350: Query dma_cookie_status() under vc.lock in d350_tx_status()
In reply to Lee JonesCalling dma_cookie_status() before acquiring dch->vc.lock in d350_tx_status() races with d350_irq() completing the active descriptor and starting the next queued transfer, causing d350_tx_status() to observe a stale DMA_IN_PROGRESS status and falsely return DMA_ERROR.
Move the dma_cookie_status() call inside the dch->vc.lock critical section.
---
v1 => v2: No changes
drivers/dma/arm-dma350.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/arm-dma350.c +1 -2
@@ -381,9 +381,8 @@ static enum dma_status d350_tx_status(struct dma_chan *chan, dma_cookie_t cookieunsigned long flags;u32 residue =0 ; +spin_lock_irqsave (&dch->vc.lock, flags); status =dma_cookie_status (chan, cookie, state); - -spin_lock_irqsave (&dch->vc.lock, flags);if (cookie == dch->cookie) { status = dch->status;if (status ==DMA_IN_PROGRESS || status ==DMA_PAUSED )
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 07/11] dmaengine: arm-dma350: Query dma_cookie_status() under vc.lock in d350_tx_status()
Quoted 5 lines · Lee Jones
Calling
dma_cookie_status()before acquiringdch->vc.lockind350_tx_status()races withd350_irq()completing the active descriptor and starting the next queued transfer, causingd350_tx_status()to observe a staleDMA_IN_PROGRESSstatus and falsely returnDMA_ERROR.
Quoted 8 lines
Move the
dma_cookie_status()call inside thedch->vc.lockcritical section.Fixes 5d099706449d ("dmaengine: Add Arm DMA-350 driver")Signed-off-by Lee Jones <[email protected]>---
Quoted 24 lines
v1 => v2: No changes
drivers/dma/arm-dma350.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/dma/arm-dma350.c +1
-3@@ -381,9 +381,8 @@ static enum dma_status d350_tx_status(struct dma_chan *chan, dma_cookie_t cookieunsigned long flags;u32 residue =0 ; +spin_lock_irqsave (&dch->vc.lock, flags); status =dma_cookie_status (chan, cookie, state); - -spin_lock_irqsave (&dch->vc.lock, flags);if (cookie == dch->cookie) { status = dch->status;if (status ==DMA_IN_PROGRESS || status ==DMA_PAUSED ) --2.56.0.679.gc527c65306-goog
PATCH v2 8/11 dmaengine: bestcomm: Defer publishing bcom_eng until initialisation completes
In reply to Lee Jonesmpc52xx_bcom_probe() assigns the newly allocated struct bcom_engine to the global bcom_eng pointer before calling bcom_engine_init(). A concurrent call to bcom_task_alloc() can observe a non-NULL bcom_eng pointer before its spinlock and task descriptor table are initialised.
Initialise the engine via a local pointer and only publish bcom_eng once initialisation has succeeded.
---
v1 => v2: No changes
drivers/dma/bestcomm/bestcomm.c | 69 +++++++++++++++++---------------- 1 file changed, 36 insertions(+), 33 deletions(-)
drivers/dma/bestcomm/bestcomm.c +36 -33
@@ -270,7 +270,7 @@ static u32 fdt_ops[] = { }; -static int bcom_engine_init (void ) +static int bcom_engine_init (struct bcom_engine *eng) {int task;phys_addr_t tdt_pa, ctx_pa, var_pa, fdt_pa;
@@ -282,56 +282,59 @@ static int bcom_engine_init(void) var_size =BCOM_MAX_TASKS * (BCOM_VAR_SIZE +BCOM_INC_SIZE ); fdt_size =BCOM_FDT_SIZE ; - bcom_eng->tdt =bcom_sram_alloc (tdt_size,sizeof (u32), &tdt_pa); - bcom_eng->ctx =bcom_sram_alloc (ctx_size,BCOM_CTX_ALIGN , &ctx_pa); - bcom_eng->var =bcom_sram_alloc (var_size,BCOM_VAR_ALIGN , &var_pa); - bcom_eng->fdt =bcom_sram_alloc (fdt_size,BCOM_FDT_ALIGN , &fdt_pa); + eng->tdt =bcom_sram_alloc (tdt_size,sizeof (u32), &tdt_pa); + eng->ctx =bcom_sram_alloc (ctx_size,BCOM_CTX_ALIGN , &ctx_pa); + eng->var =bcom_sram_alloc (var_size,BCOM_VAR_ALIGN , &var_pa); + eng->fdt =bcom_sram_alloc (fdt_size,BCOM_FDT_ALIGN , &fdt_pa); -if (!bcom_eng->tdt || !bcom_eng->ctx || !bcom_eng->var || !bcom_eng->fdt) { +if (!eng->tdt || !eng->ctx || !eng->var || !eng->fdt) {printk (KERN_ERR "DMA: SRAM alloc failed in engine init !\n" ); -bcom_sram_free (bcom_eng->tdt); -bcom_sram_free (bcom_eng->ctx); -bcom_sram_free (bcom_eng->var); -bcom_sram_free (bcom_eng->fdt); +bcom_sram_free (eng->tdt); +bcom_sram_free (eng->ctx); +bcom_sram_free (eng->var); +bcom_sram_free (eng->fdt);return -ENOMEM ; } -memset_io (bcom_eng->tdt,0x00 , tdt_size); -memset_io (bcom_eng->ctx,0x00 , ctx_size); -memset_io (bcom_eng->var,0x00 , var_size); -memset_io (bcom_eng->fdt,0x00 , fdt_size); +memset_io (eng->tdt,0x00 , tdt_size); +memset_io (eng->ctx,0x00 , ctx_size); +memset_io (eng->var,0x00 , var_size); +memset_io (eng->fdt,0x00 , fdt_size);/* Copy the FDT for the EU#3 */ -memcpy_toio (&bcom_eng->fdt[48 ], fdt_ops,sizeof (fdt_ops)); +memcpy_toio (&eng->fdt[48 ], fdt_ops,sizeof (fdt_ops));/* Initialize Task base structure */ for (task=0 ; task<BCOM_MAX_TASKS ; task++) { -out_be16 (&bcom_eng->regs->tcr[task],0 ); -out_8 (&bcom_eng->regs->ipr[task],0 ); +out_be16 (&eng->regs->tcr[task],0 ); +out_8 (&eng->regs->ipr[task],0 ); - bcom_eng->tdt[task].context = ctx_pa; - bcom_eng->tdt[task].var = var_pa; - bcom_eng->tdt[task].fdt = fdt_pa; + eng->tdt[task].context = ctx_pa; + eng->tdt[task].var = var_pa; + eng->tdt[task].fdt = fdt_pa; var_pa +=BCOM_VAR_SIZE +BCOM_INC_SIZE ; ctx_pa +=BCOM_CTX_SIZE ; } -out_be32 (&bcom_eng->regs->taskBar, tdt_pa); +out_be32 (&eng->regs->taskBar, tdt_pa);/* Init 'always' initiator */ -out_8 (&bcom_eng->regs->ipr[BCOM_INITIATOR_ALWAYS ],BCOM_IPR_ALWAYS ); +out_8 (&eng->regs->ipr[BCOM_INITIATOR_ALWAYS ],BCOM_IPR_ALWAYS ); + +/* Init lock */ +spin_lock_init (&eng->lock); + +/* Ensure all engine fields are visible before publishing bcom_eng */ +smp_store_release (&bcom_eng, eng);/* Disable COMM Bus Prefetch on the original 5200; it's broken */ if ((mfspr (SPRN_SVR ) &MPC5200_SVR_MASK ) ==MPC5200_SVR )bcom_disable_prefetch (); -/* Init lock */ -spin_lock_init (&bcom_eng->lock); -return 0 ; }
@@ -363,6 +366,7 @@ bcom_engine_cleanup(void)static int mpc52xx_bcom_probe (struct platform_device *op) { +struct bcom_engine *eng;struct device_node *ofn_sram;struct resource *res_bcom;void __iomem *regs;
@@ -398,20 +402,20 @@ static int mpc52xx_bcom_probe(struct platform_device *op) }/* Get a clean struct */ - bcom_eng = kzalloc_obj(struct bcom_engine); -if (!bcom_eng) { + eng = kzalloc_obj(struct bcom_engine); +if (!eng) { rv = -ENOMEM ; goto error_sramclean; }/* Save the node */ - bcom_eng->ofnode = op->dev.of_node; + eng->ofnode = op->dev.of_node; - bcom_eng->regs = regs; - bcom_eng->regs_base = res_bcom->start; + eng->regs = regs; + eng->regs_base = res_bcom->start;/* Now, do the real init */ - rv =bcom_engine_init (); + rv =bcom_engine_init (eng);if (rv) goto error_sramclean;
@@ -423,8 +427,7 @@ static int mpc52xx_bcom_probe(struct platform_device *op)/* Error path */ error_sramclean: -kfree (bcom_eng); - bcom_eng =NULL ; +kfree (eng);bcom_sram_cleanup (); error_ofput:of_node_put (op->dev.of_node);
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 08/11] dmaengine: bestcomm: Defer publishing bcom_eng until initialisation completes
Quoted 5 lines · Lee Jones
mpc52xx_bcom_probe()assigns the newly allocated structbcom_engineto the globalbcom_engpointer before callingbcom_engine_init(). A concurrent call tobcom_task_alloc()can observe a non-NULLbcom_engpointer before its spinlock and task descriptor table are initialised.
Quoted 8 lines
Initialise the engine via a local pointer and only publish
bcom_engonce initialisation has succeeded.Fixes 2f9ea1bde0d1 ("[POWERPC] bestcomm: core bestcomm support for Freescale MPC5200")Signed-off-by Lee Jones <[email protected]>---
Quoted 151 lines
v1 => v2: No changes
drivers/dma/bestcomm/bestcomm.c | 69 +++++++++++++++++---------------- 1 file changed, 36 insertions(+), 33 deletions(-)drivers/dma/bestcomm/bestcomm.c +36
-34@@ -270,7 +270,7 @@ static u32 fdt_ops[] = { }; -static int bcom_engine_init (void ) +static int bcom_engine_init (struct bcom_engine *eng) {int task;phys_addr_t tdt_pa, ctx_pa, var_pa, fdt_pa;@@ -282,56 +282,59 @@ static int bcom_engine_init(void) var_size =BCOM_MAX_TASKS * (BCOM_VAR_SIZE +BCOM_INC_SIZE ); fdt_size =BCOM_FDT_SIZE ; - bcom_eng->tdt =bcom_sram_alloc (tdt_size,sizeof (u32), &tdt_pa); - bcom_eng->ctx =bcom_sram_alloc (ctx_size,BCOM_CTX_ALIGN , &ctx_pa); - bcom_eng->var =bcom_sram_alloc (var_size,BCOM_VAR_ALIGN , &var_pa); - bcom_eng->fdt =bcom_sram_alloc (fdt_size,BCOM_FDT_ALIGN , &fdt_pa); + eng->tdt =bcom_sram_alloc (tdt_size,sizeof (u32), &tdt_pa); + eng->ctx =bcom_sram_alloc (ctx_size,BCOM_CTX_ALIGN , &ctx_pa); + eng->var =bcom_sram_alloc (var_size,BCOM_VAR_ALIGN , &var_pa); + eng->fdt =bcom_sram_alloc (fdt_size,BCOM_FDT_ALIGN , &fdt_pa); -if (!bcom_eng->tdt || !bcom_eng->ctx || !bcom_eng->var || !bcom_eng->fdt) { +if (!eng->tdt || !eng->ctx || !eng->var || !eng->fdt) {printk (KERN_ERR "DMA: SRAM alloc failed in engine init !\n" ); -bcom_sram_free (bcom_eng->tdt); -bcom_sram_free (bcom_eng->ctx); -bcom_sram_free (bcom_eng->var); -bcom_sram_free (bcom_eng->fdt); +bcom_sram_free (eng->tdt); +bcom_sram_free (eng->ctx); +bcom_sram_free (eng->var); +bcom_sram_free (eng->fdt);return -ENOMEM ; } -memset_io (bcom_eng->tdt,0x00 , tdt_size); -memset_io (bcom_eng->ctx,0x00 , ctx_size); -memset_io (bcom_eng->var,0x00 , var_size); -memset_io (bcom_eng->fdt,0x00 , fdt_size); +memset_io (eng->tdt,0x00 , tdt_size); +memset_io (eng->ctx,0x00 , ctx_size); +memset_io (eng->var,0x00 , var_size); +memset_io (eng->fdt,0x00 , fdt_size);/* Copy the FDT for the EU#3 */ -memcpy_toio (&bcom_eng->fdt[48 ], fdt_ops,sizeof (fdt_ops)); +memcpy_toio (&eng->fdt[48 ], fdt_ops,sizeof (fdt_ops));/* Initialize Task base structure */ for (task=0 ; task<BCOM_MAX_TASKS ; task++) { -out_be16 (&bcom_eng->regs->tcr[task],0 ); -out_8 (&bcom_eng->regs->ipr[task],0 ); +out_be16 (&eng->regs->tcr[task],0 ); +out_8 (&eng->regs->ipr[task],0 ); - bcom_eng->tdt[task].context = ctx_pa; - bcom_eng->tdt[task].var = var_pa; - bcom_eng->tdt[task].fdt = fdt_pa; + eng->tdt[task].context = ctx_pa; + eng->tdt[task].var = var_pa; + eng->tdt[task].fdt = fdt_pa; var_pa +=BCOM_VAR_SIZE +BCOM_INC_SIZE ; ctx_pa +=BCOM_CTX_SIZE ; } -out_be32 (&bcom_eng->regs->taskBar, tdt_pa); +out_be32 (&eng->regs->taskBar, tdt_pa);/* Init 'always' initiator */ -out_8 (&bcom_eng->regs->ipr[BCOM_INITIATOR_ALWAYS ],BCOM_IPR_ALWAYS ); +out_8 (&eng->regs->ipr[BCOM_INITIATOR_ALWAYS ],BCOM_IPR_ALWAYS ); + +/* Init lock */ +spin_lock_init (&eng->lock); + +/* Ensure all engine fields are visible before publishing bcom_eng */ +smp_store_release (&bcom_eng, eng);/* Disable COMM Bus Prefetch on the original 5200; it's broken */ if ((mfspr (SPRN_SVR ) &MPC5200_SVR_MASK ) ==MPC5200_SVR )bcom_disable_prefetch (); -/* Init lock */ -spin_lock_init (&bcom_eng->lock); -return 0 ; }@@ -363,6 +366,7 @@ bcom_engine_cleanup(void)static int mpc52xx_bcom_probe (struct platform_device *op) { +struct bcom_engine *eng;struct device_node *ofn_sram;struct resource *res_bcom;void __iomem *regs;@@ -398,20 +402,20 @@ static int mpc52xx_bcom_probe(struct platform_device *op) }/* Get a clean struct */ - bcom_eng = kzalloc_obj(struct bcom_engine); -if (!bcom_eng) { + eng = kzalloc_obj(struct bcom_engine); +if (!eng) { rv = -ENOMEM ; goto error_sramclean; }/* Save the node */ - bcom_eng->ofnode = op->dev.of_node; + eng->ofnode = op->dev.of_node; - bcom_eng->regs = regs; - bcom_eng->regs_base = res_bcom->start; + eng->regs = regs; + eng->regs_base = res_bcom->start;/* Now, do the real init */ - rv =bcom_engine_init (); + rv =bcom_engine_init (eng);if (rv) goto error_sramclean;@@ -423,8 +427,7 @@ static int mpc52xx_bcom_probe(struct platform_device *op)/* Error path */ error_sramclean: -kfree (bcom_eng); - bcom_eng =NULL ; +kfree (eng);bcom_sram_cleanup (); error_ofput:of_node_put (op->dev.of_node); --2.56.0.679.gc527c65306-goog
PATCH v2 9/11 dmaengine: bestcomm: Check rh_create() return value in bcom_sram_init()
In reply to Lee Jonesrh_create() returns ERR_PTR(-ENOMEM) on allocation failure. bcom_sram_init() assigns this return value directly to bcom_sram->rh without checking IS_ERR() and passes it to rh_attach_region(), which dereferences the error pointer.
Check IS_ERR(bcom_sram->rh) after rh_create() and unmap the SRAM region on failure.
---
v1 => v2: No changes
drivers/dma/bestcomm/sram.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/dma/bestcomm/sram.c +6 -0
@@ -88,6 +88,10 @@ int bcom_sram_init(struct device_node *sram_node, char *owner)/* Create an rheap (defaults to 32 bits word alignment) */ bcom_sram->rh =rh_create (4 ); +if (IS_ERR (bcom_sram->rh)) { + rv =PTR_ERR (bcom_sram->rh); + goto error_unmap; + }/* Attach the free zones */ regaddr_p =NULL ;
@@ -111,6 +115,8 @@ int bcom_sram_init(struct device_node *sram_node, char *owner)return 0 ; +error_unmap: +iounmap ((void __iomem *)bcom_sram->base_virt); error_release:release_mem_region (res.start,resource_size (&res)); error_free:
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 09/11] dmaengine: bestcomm: Check rh_create() return value in bcom_sram_init()
Quoted 5 lines · Lee Jones
rh_create()returnsERR_PTR(-ENOMEM)on allocation failure.bcom_sram_init()assigns this return value directly tobcom_sram->rhwithout checkingIS_ERR()and passes it torh_attach_region(), which dereferences the error pointer.
Quoted 8 lines
Check
IS_ERR(bcom_sram->rh)afterrh_create()and unmap the SRAM region on failure.Fixes 2f9ea1bde0d1 ("[POWERPC] bestcomm: core bestcomm support for Freescale MPC5200")Signed-off-by Lee Jones <[email protected]>---
Quoted 33 lines
v1 => v2: No changes
drivers/dma/bestcomm/sram.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/dma/bestcomm/sram.c +6
-1@@ -88,6 +88,10 @@ int bcom_sram_init(struct device_node *sram_node, char *owner)/* Create an rheap (defaults to 32 bits word alignment) */ bcom_sram->rh =rh_create (4 ); +if (IS_ERR (bcom_sram->rh)) { + rv =PTR_ERR (bcom_sram->rh); + goto error_unmap; + }/* Attach the free zones */ regaddr_p =NULL ;@@ -111,6 +115,8 @@ int bcom_sram_init(struct device_node *sram_node, char *owner)return 0 ; +error_unmap: +iounmap ((void __iomem *)bcom_sram->base_virt); error_release:release_mem_region (res.start,resource_size (&res)); error_free: --2.56.0.679.gc527c65306-goog
PATCH v2 10/11 dmaengine: jz4780: Fix descriptor cleanup on hwdesc setup failure
In reply to Lee JonesWhen jz4780_dma_setup_hwdesc() fails in jz4780_dma_prep_slave_sg() or jz4780_dma_prep_dma_cyclic(), the error paths pass &jzchan->desc->vdesc to jz4780_dma_desc_free() instead of the newly allocated &desc->vdesc. This leaks the newly allocated descriptor and either dereferences NULL when jzchan->desc is NULL or frees the currently active descriptor while it is still in flight. Furthermore, jz4780_dma_desc_free() derives jzchan from vdesc->tx.chan, which is not yet initialised before vchan_tx_prep() is called.
Initialise desc->vdesc.tx.chan in jz4780_dma_desc_alloc() and pass &desc->vdesc to jz4780_dma_desc_free() in the preparation error paths.
---
v1 => v2: Correct the Fixes: tag to fc878efe84c3
drivers/dma/dma-jz4780.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma/dma-jz4780.c +3 -2
@@ -248,6 +248,7 @@ jz4780_dma_desc_alloc(struct jz4780_dma_chan *jzchan, unsigned int count,return NULL ; } + desc->vdesc.tx.chan = &jzchan->vchan.chan; desc->count = count; desc->type = type;
@@ -379,7 +380,7 @@ static struct dma_async_tx_descriptor *jz4780_dma_prep_slave_sg(sg_dma_len (&sgl[i]), direction);if (err <0 ) { -jz4780_dma_desc_free (&jzchan->desc->vdesc); +jz4780_dma_desc_free (&desc->vdesc);return NULL ; }
@@ -426,7 +427,7 @@ static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_cyclic( err =jz4780_dma_setup_hwdesc (jzchan, &desc->desc[i], buf_addr, period_len, direction);if (err <0 ) { -jz4780_dma_desc_free (&jzchan->desc->vdesc); +jz4780_dma_desc_free (&desc->vdesc);return NULL ; }
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 10/11] dmaengine: jz4780: Fix descriptor cleanup on hwdesc setup failure
Quoted 9 lines · Lee Jones
When
jz4780_dma_setup_hwdesc()fails injz4780_dma_prep_slave_sg()orjz4780_dma_prep_dma_cyclic(), the error paths pass&jzchan->desc->vdesctojz4780_dma_desc_free()instead of the newly allocated&desc->vdesc. This leaks the newly allocated descriptor and either dereferences NULL whenjzchan->descis NULL or frees the currently active descriptor while it is still in flight. Furthermore,jz4780_dma_desc_free()derives jzchan fromvdesc->tx.chan, which is not yet initialised beforevchan_tx_prep()is called.
Quoted 8 lines
Initialise
desc->vdesc.tx.chaninjz4780_dma_desc_alloc()and pass&desc->vdesctojz4780_dma_desc_free()in the preparation error paths.Fixes fc878efe84c3 ("dmaengine: jz4780: fix resource leaks on error exit return")Signed-off-by Lee Jones <[email protected]>---
Quoted 39 lines
v1 => v2: Correct the Fixes: tag to
fc878efe84c3drivers/dma/dma-jz4780.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/dma/dma-jz4780.c +3
-3@@ -248,6 +248,7 @@ jz4780_dma_desc_alloc(struct jz4780_dma_chan *jzchan, unsigned int count,return NULL ; } + desc->vdesc.tx.chan = &jzchan->vchan.chan; desc->count = count; desc->type = type;@@ -379,7 +380,7 @@ static struct dma_async_tx_descriptor *jz4780_dma_prep_slave_sg(sg_dma_len (&sgl[i]), direction);if (err <0 ) { -jz4780_dma_desc_free (&jzchan->desc->vdesc); +jz4780_dma_desc_free (&desc->vdesc);return NULL ; }@@ -426,7 +427,7 @@ static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_cyclic( err =jz4780_dma_setup_hwdesc (jzchan, &desc->desc[i], buf_addr, period_len, direction);if (err <0 ) { -jz4780_dma_desc_free (&jzchan->desc->vdesc); +jz4780_dma_desc_free (&desc->vdesc);return NULL ; } --2.56.0.679.gc527c65306-goog
Re: [PATCH v2 10/11] dmaengine: jz4780: Fix descriptor cleanup on hwdesc setup failure
In reply to Lee JonesHi Lee,
Le mardi 17 novembre 2026 à 16:37 +0000, Lee Jones a écrit :
Quoted 17 lines
When
jz4780_dma_setup_hwdesc()fails injz4780_dma_prep_slave_sg()orjz4780_dma_prep_dma_cyclic(), the error paths pass &jzchan->desc-Quoted 1 line
vdesc
to
jz4780_dma_desc_free()instead of the newly allocated &desc-Quoted 1 line
vdesc.
This leaks the newly allocated descriptor and either dereferences NULL
whenjzchan->descis NULL or frees the currently active descriptor while
it is still in flight. Furthermore,jz4780_dma_desc_free()derives jzchan fromvdesc->tx.chan, which is not yet initialised beforevchan_tx_prep()is called.Initialise
desc->vdesc.tx.chaninjz4780_dma_desc_alloc()and pass&desc->vdesctojz4780_dma_desc_free()in the preparation error paths.
Quoted 6 lines
Fixes fc878efe84c3 ("dmaengine: jz4780: fix resource leaks on errorexit return")
Closes:
https://sashiko.dev/#/bug/linux-b39121ef-5ffb-401a-9d04-0afccd467bdeSigned-off-by Lee Jones <[email protected]>
(I had added it on your v1 btw)
Cheers,
-Paul
Quoted 42 lines
---
v1 => v2: Correct the Fixes: tag to
fc878efe84c3drivers/dma/dma-jz4780.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)drivers/dma/dma-jz4780.c +0
-0@@ -248,6 +248,7 @@ jz4780_dma_desc_alloc(struct jz4780_dma_chan *jzchan, unsigned int count, return NULL; }drivers/dma/dma-jz4780.c +1
-0+ desc->vdesc.tx.chan = &jzchan->vchan.chan;
desc->count= count;
desc->type= type;drivers/dma/dma-jz4780.c +1
-1@@ -379,7 +380,7 @@ static struct dma_async_tx_descriptor *jz4780_dma_prep_slave_sg ( sg_dma_len(&sgl[i]), direction); if (err < 0) { -jz4780_dma_desc_free (&jzchan->desc->vdesc); +jz4780_dma_desc_free (&desc->vdesc); return NULL; }drivers/dma/dma-jz4780.c +0
-0@@ -426,7 +427,7 @@ static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_cyclic(err = jz4780_dma_setup_hwdesc(jzchan, &desc-
Quoted 1 line
desc[i],
buf_addr,
period_len, direction);
if (err < 0) {drivers/dma/dma-jz4780.c +1
-1-jz4780_dma_desc_free (&jzchan->desc->vdesc); +jz4780_dma_desc_free (&desc->vdesc);return NULL;
}
PATCH v2 11/11 dmaengine: dmatest: Avoid unsigned underflow in min_odd()
In reply to Lee JonesWhen either argument to min_odd() is zero (for example when a DMA device reports max_xor or max_pq as 0), val evaluates to 0 and val - 1 underflows to UINT_MAX. In dmatest_func(), this sets src->cnt to UINT_MAX, which wraps around the (src->cnt + dst->cnt) >= 255 check and causes dmatest_alloc_test_data() to pass 0 to kcalloc() and dereference ZERO_SIZE_PTR.
Return 0 from min_odd() when the minimum value is 0, and abort dmatest_func() if src->cnt is 0.
---
v1 => v2: No changes
drivers/dma/dmatest.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/dma/dmatest.c +6 -0
@@ -457,6 +457,9 @@ static unsigned int min_odd(unsigned int x, unsigned int y) {unsigned int val =min (x, y); +if (!val) +return 0 ; +return val %2 ? val : val -1 ; }
@@ -650,6 +653,9 @@ static int dmatest_func(void *data) }else goto err_thread_type; +if (!src->cnt) + goto err_free_coefs; +/* Check if buffer count fits into map count variable (u8) */ if ((src->cnt + dst->cnt) >=255 ) { pr_err("too many buffers (%d of 255 supported)\n",
Signature · 1 line
2.56.0.679.gc527c65306-goog
Re: [PATCH v2 11/11] dmaengine: dmatest: Avoid unsigned underflow in min_odd()
Quoted 7 lines · Lee Jones
When either argument to
min_odd()is zero (for example when a DMA device reportsmax_xorormax_pqas 0), val evaluates to 0 and val - 1 underflows toUINT_MAX. Indmatest_func(), this setssrc->cnttoUINT_MAX, which wraps around the (src->cnt+dst->cnt) >= 255 check and causesdmatest_alloc_test_data()to pass 0 tokcalloc()and dereferenceZERO_SIZE_PTR.
Quoted 8 lines
Return 0 from
min_odd()when the minimum value is 0, and abortdmatest_func()ifsrc->cntis 0.Fixes 8be9e32b310c ("dmatest: adjust invalid module parameters for number of source buffers")Signed-off-by Lee Jones <[email protected]>---
Quoted 33 lines
v1 => v2: No changes
drivers/dma/dmatest.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/dma/dmatest.c +6
-1@@ -457,6 +457,9 @@ static unsigned int min_odd(unsigned int x, unsigned int y) {unsigned int val =min (x, y); +if (!val) +return 0 ; +return val %2 ? val : val -1 ; }@@ -650,6 +653,9 @@ static int dmatest_func(void *data) }else goto err_thread_type; +if (!src->cnt) + goto err_free_coefs; +/* Check if buffer count fits into map count variable (u8) */ if ((src->cnt + dst->cnt) >=255 ) { pr_err("too many buffers (%d of 255 supported)\n", --2.56.0.679.gc527c65306-goog