Commit ebb657ba authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: ni_mio_common: clarify the cmd->start_arg validation and use

Clarify the cmd->start_arg validation in Step 3 of the (*do_cmdtest)
functions.

For a TRIG_INT source, the cmd->start_arg is actually the valid
trig_num that is used by the async (*inttrig) callbacks.

Refactor the (*inttrig) functions so that the cmd->start_arg is used
to check the trig_num instead of the open coded values.

For aesthetics, refactor the (*do_cmd) functions to use if/else instead
of the switch to handle the cmd->start_src.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7d8b7b4d
...@@ -2080,7 +2080,7 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -2080,7 +2080,7 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
const struct ni_board_struct *board = comedi_board(dev); const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private; struct ni_private *devpriv = dev->private;
int err = 0; int err = 0;
int tmp; unsigned int tmp;
unsigned int sources; unsigned int sources;
/* Step 1 : check if triggers are trivially valid */ /* Step 1 : check if triggers are trivially valid */
...@@ -2119,17 +2119,19 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -2119,17 +2119,19 @@ static int ni_ai_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
/* Step 3: check if arguments are trivially valid */ /* Step 3: check if arguments are trivially valid */
if (cmd->start_src == TRIG_EXT) { switch (cmd->start_src) {
/* external trigger */ case TRIG_NOW:
unsigned int tmp = CR_CHAN(cmd->start_arg); case TRIG_INT:
err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
break;
case TRIG_EXT:
tmp = CR_CHAN(cmd->start_arg);
if (tmp > 16) if (tmp > 16)
tmp = 16; tmp = 16;
tmp |= (cmd->start_arg & (CR_INVERT | CR_EDGE)); tmp |= (cmd->start_arg & (CR_INVERT | CR_EDGE));
err |= cfc_check_trigger_arg_is(&cmd->start_arg, tmp); err |= cfc_check_trigger_arg_is(&cmd->start_arg, tmp);
} else { break;
/* true for both TRIG_NOW and TRIG_INT */
err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
} }
if (cmd->scan_begin_src == TRIG_TIMER) { if (cmd->scan_begin_src == TRIG_TIMER) {
...@@ -2510,30 +2512,28 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -2510,30 +2512,28 @@ static int ni_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
} }
#endif #endif
switch (cmd->start_src) { if (cmd->start_src == TRIG_NOW) {
case TRIG_NOW:
/* AI_START1_Pulse */ /* AI_START1_Pulse */
devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2, devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2,
AI_Command_2_Register); AI_Command_2_Register);
s->async->inttrig = NULL; s->async->inttrig = NULL;
break; } else if (cmd->start_src == TRIG_EXT) {
case TRIG_EXT:
s->async->inttrig = NULL; s->async->inttrig = NULL;
break; } else { /* TRIG_INT */
case TRIG_INT: s->async->inttrig = ni_ai_inttrig;
s->async->inttrig = &ni_ai_inttrig;
break;
} }
return 0; return 0;
} }
static int ni_ai_inttrig(struct comedi_device *dev, struct comedi_subdevice *s, static int ni_ai_inttrig(struct comedi_device *dev,
unsigned int trignum) struct comedi_subdevice *s,
unsigned int trig_num)
{ {
struct ni_private *devpriv = dev->private; struct ni_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd;
if (trignum != 0) if (trig_num != cmd->start_arg)
return -EINVAL; return -EINVAL;
devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2, devpriv->stc_writew(dev, AI_START1_Pulse | devpriv->ai_cmd2,
...@@ -2946,17 +2946,19 @@ static int ni_ao_insn_config(struct comedi_device *dev, ...@@ -2946,17 +2946,19 @@ static int ni_ao_insn_config(struct comedi_device *dev,
return -EINVAL; return -EINVAL;
} }
static int ni_ao_inttrig(struct comedi_device *dev, struct comedi_subdevice *s, static int ni_ao_inttrig(struct comedi_device *dev,
unsigned int trignum) struct comedi_subdevice *s,
unsigned int trig_num)
{ {
const struct ni_board_struct *board __maybe_unused = comedi_board(dev); const struct ni_board_struct *board __maybe_unused = comedi_board(dev);
struct ni_private *devpriv = dev->private; struct ni_private *devpriv = dev->private;
struct comedi_cmd *cmd = &s->async->cmd;
int ret; int ret;
int interrupt_b_bits; int interrupt_b_bits;
int i; int i;
static const int timeout = 1000; static const int timeout = 1000;
if (trignum != 0) if (trig_num != cmd->start_arg)
return -EINVAL; return -EINVAL;
/* Null trig at beginning prevent ao start trigger from executing more than /* Null trig at beginning prevent ao start trigger from executing more than
...@@ -3217,7 +3219,7 @@ static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -3217,7 +3219,7 @@ static int ni_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
AO_BC_TC_Interrupt_Enable, 1); AO_BC_TC_Interrupt_Enable, 1);
} }
s->async->inttrig = &ni_ao_inttrig; s->async->inttrig = ni_ao_inttrig;
return 0; return 0;
} }
...@@ -3228,7 +3230,7 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -3228,7 +3230,7 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
const struct ni_board_struct *board = comedi_board(dev); const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private; struct ni_private *devpriv = dev->private;
int err = 0; int err = 0;
int tmp; unsigned int tmp;
/* Step 1 : check if triggers are trivially valid */ /* Step 1 : check if triggers are trivially valid */
...@@ -3258,17 +3260,18 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s, ...@@ -3258,17 +3260,18 @@ static int ni_ao_cmdtest(struct comedi_device *dev, struct comedi_subdevice *s,
/* Step 3: check if arguments are trivially valid */ /* Step 3: check if arguments are trivially valid */
if (cmd->start_src == TRIG_EXT) { switch (cmd->start_src) {
/* external trigger */ case TRIG_INT:
unsigned int tmp = CR_CHAN(cmd->start_arg); err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
break;
case TRIG_EXT:
tmp = CR_CHAN(cmd->start_arg);
if (tmp > 18) if (tmp > 18)
tmp = 18; tmp = 18;
tmp |= (cmd->start_arg & (CR_INVERT | CR_EDGE)); tmp |= (cmd->start_arg & (CR_INVERT | CR_EDGE));
err |= cfc_check_trigger_arg_is(&cmd->start_arg, tmp); err |= cfc_check_trigger_arg_is(&cmd->start_arg, tmp);
} else { break;
/* true for both TRIG_NOW and TRIG_INT */
err |= cfc_check_trigger_arg_is(&cmd->start_arg, 0);
} }
if (cmd->scan_begin_src == TRIG_TIMER) { if (cmd->scan_begin_src == TRIG_TIMER) {
...@@ -3537,21 +3540,28 @@ static int ni_cdio_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -3537,21 +3540,28 @@ static int ni_cdio_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
retval = ni_request_cdo_mite_channel(dev); retval = ni_request_cdo_mite_channel(dev);
if (retval < 0) if (retval < 0)
return retval; return retval;
s->async->inttrig = &ni_cdo_inttrig;
s->async->inttrig = ni_cdo_inttrig;
return 0; return 0;
} }
static int ni_cdo_inttrig(struct comedi_device *dev, struct comedi_subdevice *s, static int ni_cdo_inttrig(struct comedi_device *dev,
unsigned int trignum) struct comedi_subdevice *s,
unsigned int trig_num)
{ {
#ifdef PCIDMA #ifdef PCIDMA
struct ni_private *devpriv = dev->private; struct ni_private *devpriv = dev->private;
unsigned long flags; unsigned long flags;
#endif #endif
struct comedi_cmd *cmd = &s->async->cmd;
int retval = 0; int retval = 0;
unsigned i; unsigned i;
const unsigned timeout = 1000; const unsigned timeout = 1000;
if (trig_num != cmd->start_arg)
return -EINVAL;
s->async->inttrig = NULL; s->async->inttrig = NULL;
/* read alloc the entire buffer */ /* read alloc the entire buffer */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment