On 30/10/18 15:34, Hartley Sweeten wrote:
On Tuesday, October 30, 2018 7:17 AM, Ian Abbott wrote:
The `insn_read` handler for the EEPROM subdevice (`eeprom_insn_read()`) currently
ignores `insn->n` (the number of samples to be read) and assumes a single sample is
to be read. But `insn->n` could be 0, meaning no samples should be read, in which
case `data[0]` ought not to be written. (The comedi core at least ensures that
`data[0]` exists, but we should not rely on that.)
Follow the usual Comedi guidelines and interpret `insn->n` as the number of samples
to be read, but only read the EEPROM location once and make `insn->n` copies, as we
don't expect the contents of the EEPROM location to change between readings.
Signed-off-by: Ian Abbott <abbotti@xxxxxxxxx>
---
drivers/staging/comedi/drivers/cb_pcidas64.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/comedi/drivers/cb_pcidas64.c b/drivers/staging/comedi/drivers/cb_pcidas64.c
index 44e5aaf8bae5..e1774e09a320 100644
--- a/drivers/staging/comedi/drivers/cb_pcidas64.c
+++ b/drivers/staging/comedi/drivers/cb_pcidas64.c
@@ -3768,9 +3768,17 @@ static int eeprom_read_insn(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) {
- data[0] = read_eeprom(dev, CR_CHAN(insn->chanspec));
+ unsigned int val;
+ unsigned int i;
- return 1;
+ if (insn->n) {
+ /* No point reading the same EEPROM location more than once. */
+ val = read_eeprom(dev, CR_CHAN(insn->chanspec));
+ for (i = 0; i < insn->n; i++)
+ data[i] = val;
+ }
+
+ return insn->n;
}
Hi Ian,
I realize it's not the "normal" Comedi use, but with the EEPROM I would think that if the user
wanted to read more than one sample they would expect to read a block of data from the
EEPROM.
Maybe the EEPROM read should be something like:
+ if (insn->n) {
+ unsigned int address = CR_CHAN(insn->chanspec);
+ for (i = 0; i < insn->n; i++) {
+ val = read_eeprom(dev, address);
+ data[i] = val;
+ address++;
+ if (address >= s->n_chan)
+ address = 0;
+ }
+ }
Regards,
Hartley
I'd rather keep it consistent and use the "normal" Comedi meaning. We
already have some insn_write handlers for EEPROM that just write the
final sample from the data (data[insn->n - 1]) to the location specified
by insn->chanspec (see labpc_eeprom_insn_write() in
.../comedi/drivers/ni_labpc_common.c), so it would be inconsistent with
that.
--
-=( Ian Abbott <abbotti@xxxxxxxxx> || Web: www.mev.co.uk )=-
-=( MEV Ltd. is a company registered in England & Wales. )=-
-=( Registered number: 02862268. Registered address: )=-
-=( 15 West Park Road, Bramhall, STOCKPORT, SK7 3JZ, UK. )=-
_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel