Commit 5c724e19 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: ni_tio: Use data[insn->n-1] in ni_tio_insn_write()

The `insn_write` handler for the counter subdevices
(`ni_tio_insn_write()`) writes a single data value `data[0]` to the
channel.  Technically, `insn->n` specifies the number of successive
values from `data[]` to write to the channel, but when there is little
benefit in writing multiple data values, the usual Comedi convention is
to just write the last data value `data[insn->n - 1]`.  Change the
function to follow that convention and use `data[insn->n - 1]` instead
of `data[0]`.  (In practice, `insn->n` would normally be 1 anyway.)

Also follow the usual Comedi convention and return `insn->n` from the
handler to indicate success instead of 0 (although any non-negative
return value will do).
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 81a6e1cc
......@@ -1682,9 +1682,11 @@ int ni_tio_insn_write(struct comedi_device *dev,
unsigned int cidx = counter->counter_index;
unsigned int chip = counter->chip_index;
unsigned int load_reg;
unsigned int load_val;
if (insn->n < 1)
return 0;
load_val = data[insn->n - 1];
switch (channel) {
case 0:
/*
......@@ -1697,7 +1699,7 @@ int ni_tio_insn_write(struct comedi_device *dev,
* load register is already selected.
*/
load_reg = ni_tio_next_load_register(counter);
ni_tio_write(counter, data[0], load_reg);
ni_tio_write(counter, load_val, load_reg);
ni_tio_set_bits_transient(counter, NITIO_CMD_REG(cidx),
0, 0, GI_LOAD);
/* restore load reg */
......@@ -1705,17 +1707,17 @@ int ni_tio_insn_write(struct comedi_device *dev,
load_reg);
break;
case 1:
counter_dev->regs[chip][NITIO_LOADA_REG(cidx)] = data[0];
ni_tio_write(counter, data[0], NITIO_LOADA_REG(cidx));
counter_dev->regs[chip][NITIO_LOADA_REG(cidx)] = load_val;
ni_tio_write(counter, load_val, NITIO_LOADA_REG(cidx));
break;
case 2:
counter_dev->regs[chip][NITIO_LOADB_REG(cidx)] = data[0];
ni_tio_write(counter, data[0], NITIO_LOADB_REG(cidx));
counter_dev->regs[chip][NITIO_LOADB_REG(cidx)] = load_val;
ni_tio_write(counter, load_val, NITIO_LOADB_REG(cidx));
break;
default:
return -EINVAL;
}
return 0;
return insn->n;
}
EXPORT_SYMBOL_GPL(ni_tio_insn_write);
......
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