From 6a760394d7eb70a810bf472289473f915eb6da0d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 17 Apr 2014 10:08:03 -0700 Subject: [PATCH] staging: comedi: ni_tiocmd: clarify the cmd->start_arg validation and use This driver supportes cmd->start_src sources of TRIG_NOW, TRIG_INT, TRIG_OTHER, and TRIG_EXT. Refactor the (*do_cmdtest) to clarify the trivial validation of the cmd->start_arg. For a TRIG_INT source, the cmd->start_arg is actually the valid trig_num that is passed to the async (*inttrig) callback. Refactor the (*inttrig) function so that the cmd->start_arg is used to check the trig_num instead of the open coded value. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/ni_tiocmd.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_tiocmd.c b/drivers/staging/comedi/drivers/ni_tiocmd.c index 7d64f8892f08..b9d23db4004b 100644 --- a/drivers/staging/comedi/drivers/ni_tiocmd.c +++ b/drivers/staging/comedi/drivers/ni_tiocmd.c @@ -89,14 +89,16 @@ static void ni_tio_configure_dma(struct ni_gpct *counter, short enable, static int ni_tio_input_inttrig(struct comedi_device *dev, struct comedi_subdevice *s, - unsigned int trignum) + unsigned int trig_num) { + struct ni_gpct *counter = s->private; + struct comedi_cmd *cmd = &s->async->cmd; unsigned long flags; int retval = 0; - struct ni_gpct *counter = s->private; BUG_ON(counter == NULL); - if (trignum != 0) + + if (trig_num != cmd->start_src) return -EINVAL; spin_lock_irqsave(&counter->lock, flags); @@ -271,8 +273,16 @@ int ni_tio_cmdtest(struct comedi_device *dev, /* Step 3: check if arguments are trivially valid */ - if (cmd->start_src != TRIG_EXT) + switch (cmd->start_src) { + case TRIG_NOW: + case TRIG_INT: + case TRIG_OTHER: err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0); + break; + case TRIG_EXT: + /* start_arg is the start_trigger passed to ni_tio_arm() */ + break; + } if (cmd->scan_begin_src != TRIG_EXT) err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, 0); -- 2.20.1