Commit de0a1e97 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: usbduxsigma: generalize the usb_submit_urb functions

Generalize a helper function to replace usbduxsub_submit_{In,Out}URBs().

In the callers, set the 'a[io]_cmd_running' flag after the urbs have been
successfully submitted. This removes the need to clear the flag if the
submit fails.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 91fe97f3
...@@ -611,38 +611,30 @@ static int usbduxsigma_firmware_upload(struct comedi_device *dev, ...@@ -611,38 +611,30 @@ static int usbduxsigma_firmware_upload(struct comedi_device *dev,
return ret; return ret;
} }
static int usbduxsub_submit_InURBs(struct usbduxsub *usbduxsub) static int usbduxsigma_submit_urbs(struct comedi_device *dev,
struct urb **urbs, int num_urbs,
int input_urb)
{ {
int i, errFlag; struct usbduxsub *devpriv = dev->private;
struct urb *urb;
int ret;
int i;
/* Submit all URBs and start the transfer on the bus */ /* Submit all URBs and start the transfer on the bus */
for (i = 0; i < usbduxsub->numOfInBuffers; i++) { for (i = 0; i < num_urbs; i++) {
/* in case of a resubmission after an unlink... */ urb = urbs[i];
usbduxsub->urbIn[i]->interval = usbduxsub->ai_interval;
usbduxsub->urbIn[i]->context = usbduxsub->comedidev;
usbduxsub->urbIn[i]->dev = usbduxsub->usbdev;
usbduxsub->urbIn[i]->status = 0;
usbduxsub->urbIn[i]->transfer_flags = URB_ISO_ASAP;
errFlag = usb_submit_urb(usbduxsub->urbIn[i], GFP_ATOMIC);
if (errFlag)
return errFlag;
}
return 0;
}
static int usbduxsub_submit_OutURBs(struct usbduxsub *usbduxsub)
{
int i, errFlag;
for (i = 0; i < usbduxsub->numOfOutBuffers; i++) {
/* in case of a resubmission after an unlink... */ /* in case of a resubmission after an unlink... */
usbduxsub->urbOut[i]->context = usbduxsub->comedidev; if (input_urb)
usbduxsub->urbOut[i]->dev = usbduxsub->usbdev; urb->interval = devpriv->ai_interval;
usbduxsub->urbOut[i]->status = 0; urb->context = dev;
usbduxsub->urbOut[i]->transfer_flags = URB_ISO_ASAP; urb->dev = devpriv->usbdev;
errFlag = usb_submit_urb(usbduxsub->urbOut[i], GFP_ATOMIC); urb->status = 0;
if (errFlag) urb->transfer_flags = URB_ISO_ASAP;
return errFlag;
ret = usb_submit_urb(urb, GFP_ATOMIC);
if (ret)
return ret;
} }
return 0; return 0;
} }
...@@ -842,17 +834,15 @@ static int usbdux_ai_inttrig(struct comedi_device *dev, ...@@ -842,17 +834,15 @@ static int usbdux_ai_inttrig(struct comedi_device *dev,
up(&this_usbduxsub->sem); up(&this_usbduxsub->sem);
return -EINVAL; return -EINVAL;
} }
if (!(this_usbduxsub->ai_cmd_running)) { if (!this_usbduxsub->ai_cmd_running) {
this_usbduxsub->ai_cmd_running = 1; ret = usbduxsigma_submit_urbs(dev, this_usbduxsub->urbIn,
ret = usbduxsub_submit_InURBs(this_usbduxsub); this_usbduxsub->numOfInBuffers,
1);
if (ret < 0) { if (ret < 0) {
dev_err(&this_usbduxsub->interface->dev,
"comedi%d: usbdux_ai_inttrig: "
"urbSubmit: err=%d\n", dev->minor, ret);
this_usbduxsub->ai_cmd_running = 0;
up(&this_usbduxsub->sem); up(&this_usbduxsub->sem);
return ret; return ret;
} }
this_usbduxsub->ai_cmd_running = 1;
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { } else {
dev_err(&this_usbduxsub->interface->dev, dev_err(&this_usbduxsub->interface->dev,
...@@ -964,14 +954,14 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -964,14 +954,14 @@ static int usbdux_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
if (cmd->start_src == TRIG_NOW) { if (cmd->start_src == TRIG_NOW) {
/* enable this acquisition operation */ /* enable this acquisition operation */
this_usbduxsub->ai_cmd_running = 1; ret = usbduxsigma_submit_urbs(dev, this_usbduxsub->urbIn,
ret = usbduxsub_submit_InURBs(this_usbduxsub); this_usbduxsub->numOfInBuffers,
1);
if (ret < 0) { if (ret < 0) {
this_usbduxsub->ai_cmd_running = 0;
/* fixme: unlink here?? */
up(&this_usbduxsub->sem); up(&this_usbduxsub->sem);
return ret; return ret;
} }
this_usbduxsub->ai_cmd_running = 1;
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { } else {
/* TRIG_INT */ /* TRIG_INT */
...@@ -1224,15 +1214,12 @@ static int usbdux_ao_inttrig(struct comedi_device *dev, ...@@ -1224,15 +1214,12 @@ static int usbdux_ao_inttrig(struct comedi_device *dev,
goto out; goto out;
} }
if (!(this_usbduxsub->ao_cmd_running)) { if (!(this_usbduxsub->ao_cmd_running)) {
this_usbduxsub->ao_cmd_running = 1; ret = usbduxsigma_submit_urbs(dev, this_usbduxsub->urbOut,
ret = usbduxsub_submit_OutURBs(this_usbduxsub); this_usbduxsub->numOfOutBuffers,
if (ret < 0) { 0);
dev_err(&this_usbduxsub->interface->dev, if (ret < 0)
"comedi%d: usbdux_ao_inttrig: submitURB: "
"err=%d\n", dev->minor, ret);
this_usbduxsub->ao_cmd_running = 0;
goto out; goto out;
} this_usbduxsub->ao_cmd_running = 1;
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { } else {
dev_err(&this_usbduxsub->interface->dev, dev_err(&this_usbduxsub->interface->dev,
...@@ -1408,14 +1395,14 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -1408,14 +1395,14 @@ static int usbdux_ao_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
if (cmd->start_src == TRIG_NOW) { if (cmd->start_src == TRIG_NOW) {
/* enable this acquisition operation */ /* enable this acquisition operation */
this_usbduxsub->ao_cmd_running = 1; ret = usbduxsigma_submit_urbs(dev, this_usbduxsub->urbOut,
ret = usbduxsub_submit_OutURBs(this_usbduxsub); this_usbduxsub->numOfOutBuffers,
0);
if (ret < 0) { if (ret < 0) {
this_usbduxsub->ao_cmd_running = 0;
/* fixme: unlink here?? */
up(&this_usbduxsub->sem); up(&this_usbduxsub->sem);
return ret; return ret;
} }
this_usbduxsub->ao_cmd_running = 1;
s->async->inttrig = NULL; s->async->inttrig = NULL;
} else { } else {
/* TRIG_INT */ /* TRIG_INT */
......
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