Skip to content

Commit b6bc224

Browse files
bigguinessgregkh
authored andcommitted
staging: comedi: adl_pci9111: use comedi_async 'scans_done' to detect EOA
The comedi core now counts the number of samples added to the async buffer and detects the end-of-scan and increments the comedi_async 'scans_done' counter. Remove the private data member 'stop_counter' and use the 'scans_done' member to detect the end-of-acquisition. This fixes a possible interger overflow when calculating the value of the 'stop_counter' and removes the need to accumulate the 'total' number of samples added to the async buffer in pci9111_handle_fifo_half_full(). Signed-off-by: H Hartley Sweeten <[email protected]> Reviewed-by: Ian Abbott <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f6266a4 commit b6bc224

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

drivers/staging/comedi/drivers/adl_pci9111.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ static const struct comedi_lrange pci9111_ai_range = {
133133
struct pci9111_private_data {
134134
unsigned long lcr_io_base;
135135

136-
int stop_counter;
137-
138136
unsigned int scan_delay;
139137
unsigned int chunk_counter;
140138
unsigned int chunk_num_samples;
@@ -404,12 +402,6 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
404402
outb(CR_RANGE(cmd->chanlist[0]) & PCI9111_AI_RANGE_MASK,
405403
dev->iobase + PCI9111_AI_RANGE_STAT_REG);
406404

407-
/* Set counter */
408-
if (cmd->stop_src == TRIG_COUNT)
409-
dev_private->stop_counter = cmd->stop_arg * cmd->chanlist_len;
410-
else /* TRIG_NONE */
411-
dev_private->stop_counter = 0;
412-
413405
/* Set timer pacer */
414406
dev_private->scan_delay = 0;
415407
if (cmd->convert_src == TRIG_TIMER) {
@@ -435,7 +427,6 @@ static int pci9111_ai_do_cmd(struct comedi_device *dev,
435427
}
436428
outb(trig, dev->iobase + PCI9111_AI_TRIG_CTRL_REG);
437429

438-
dev_private->stop_counter *= (1 + dev_private->scan_delay);
439430
dev_private->chunk_counter = 0;
440431
dev_private->chunk_num_samples = cmd->chanlist_len *
441432
(1 + dev_private->scan_delay);
@@ -464,21 +455,14 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
464455
{
465456
struct pci9111_private_data *devpriv = dev->private;
466457
struct comedi_cmd *cmd = &s->async->cmd;
467-
unsigned int total = 0;
468458
unsigned int samples;
469459

470-
if (cmd->stop_src == TRIG_COUNT &&
471-
PCI9111_FIFO_HALF_SIZE > devpriv->stop_counter)
472-
samples = devpriv->stop_counter;
473-
else
474-
samples = PCI9111_FIFO_HALF_SIZE;
475-
460+
samples = comedi_nsamples_left(s, PCI9111_FIFO_HALF_SIZE);
476461
insw(dev->iobase + PCI9111_AI_FIFO_REG,
477462
devpriv->ai_bounce_buffer, samples);
478463

479464
if (devpriv->scan_delay < 1) {
480-
total = comedi_buf_write_samples(s, devpriv->ai_bounce_buffer,
481-
samples);
465+
comedi_buf_write_samples(s, devpriv->ai_bounce_buffer, samples);
482466
} else {
483467
unsigned int pos = 0;
484468
unsigned int to_read;
@@ -491,7 +475,7 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
491475
if (to_read > samples - pos)
492476
to_read = samples - pos;
493477

494-
total += comedi_buf_write_samples(s,
478+
comedi_buf_write_samples(s,
495479
devpriv->ai_bounce_buffer + pos,
496480
to_read);
497481
} else {
@@ -500,8 +484,6 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
500484

501485
if (to_read > samples - pos)
502486
to_read = samples - pos;
503-
504-
total += comedi_samples_to_bytes(s, to_read);
505487
}
506488

507489
pos += to_read;
@@ -512,8 +494,6 @@ static void pci9111_handle_fifo_half_full(struct comedi_device *dev,
512494
devpriv->chunk_counter = 0;
513495
}
514496
}
515-
516-
devpriv->stop_counter -= comedi_bytes_to_samples(s, total);
517497
}
518498

519499
static irqreturn_t pci9111_interrupt(int irq, void *p_device)
@@ -570,7 +550,7 @@ static irqreturn_t pci9111_interrupt(int irq, void *p_device)
570550
pci9111_handle_fifo_half_full(dev, s);
571551
}
572552

573-
if (cmd->stop_src == TRIG_COUNT && dev_private->stop_counter == 0)
553+
if (cmd->stop_src == TRIG_COUNT && async->scans_done >= cmd->stop_arg)
574554
async->events |= COMEDI_CB_EOA;
575555

576556
outb(0, dev->iobase + PCI9111_INT_CLR_REG);

0 commit comments

Comments
 (0)