Re: [PATCH] Staging: comedi: Add DMA preparation before mite_dma_arm().

From: Ian Abbott
Date: Thu Apr 03 2025 - 13:47:47 EST


On 2025-04-03 17:35, Wentao Liang wrote:
The ni_tio_input_inttrig() calls mite_dma_arm() without calling
mite_prep_dma() first. A proper implementation can be found in
ni_cdo_inttrig() in ni_mio_common.c.

Add mite_prep_dma() before mite_dma_arm().

Fixes: cb7859a90af1 ("Staging: comedi: add National Instruments infrastructure")
Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
---
drivers/comedi/drivers/ni_tiocmd.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/comedi/drivers/ni_tiocmd.c b/drivers/comedi/drivers/ni_tiocmd.c
index ab6d9e8269f3..b943836ccf1a 100644
--- a/drivers/comedi/drivers/ni_tiocmd.c
+++ b/drivers/comedi/drivers/ni_tiocmd.c
@@ -84,9 +84,10 @@ static int ni_tio_input_inttrig(struct comedi_device *dev,
return -EINVAL;
spin_lock_irqsave(&counter->lock, flags);
- if (counter->mite_chan)
+ if (counter->mite_chan) {
+ mite_prep_dma(counter->mite_chan, 32, 32);
mite_dma_arm(counter->mite_chan);
- else
+ } else
ret = -EIO;
spin_unlock_irqrestore(&counter->lock, flags);
if (ret < 0)

mite_prep_dma() will get called by ni_tio_input_cmd() at some arbitrary time before ni_tio_input_inttrig() is called. (ni_tio_input_cmd() sets up the software trigger function pointer that is called during processing of a subsequent INSN_INTTRIG comedi instruction from user-space. Also, the last two parameters of mite_prep_dma() are not always 32 and 32 - it depends on the hardware, as can be seen in the switch statement in ni_tio_input_cmd().

--
-=( Ian Abbott <abbotti@xxxxxxxxx> || MEV Ltd. is a company )=-
-=( registered in England & Wales. Regd. number: 02862268. )=-
-=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=-
-=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-