summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi
diff options
context:
space:
mode:
authorIan Abbott2019-03-27 16:15:15 +0100
committerGreg Kroah-Hartman2019-03-29 17:10:18 +0100
commit5c724e197eb57336696a0a573b199a273db9466b (patch)
treef7f1fc27d9b33bd1ba8004e62869a9f0aca62ec6 /drivers/staging/comedi
parentstaging: pi433: Fix rf69_set_tx_cfg() logic (diff)
downloadkernel-qcow2-linux-5c724e197eb57336696a0a573b199a273db9466b.tar.gz
kernel-qcow2-linux-5c724e197eb57336696a0a573b199a273db9466b.tar.xz
kernel-qcow2-linux-5c724e197eb57336696a0a573b199a273db9466b.zip
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: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi')
-rw-r--r--drivers/staging/comedi/drivers/ni_tio.c14
1 files 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);