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: Ian Abbott <abbotti@xxxxxxxxx> --- drivers/staging/comedi/drivers/ni_tio.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_tio.c b/drivers/staging/comedi/drivers/ni_tio.c index 048cb35723ad..943c5177cbea 100644 --- a/drivers/staging/comedi/drivers/ni_tio.c +++ b/drivers/staging/comedi/drivers/ni_tio.c @@ -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); -- 2.20.1 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel