提交 da903590 编写于 作者: H H Hartley Sweeten 提交者: Greg Kroah-Hartman

staging: comedi: usbdux: tidy up usbdux_usb_probe()

Use a pointer to the struct usbdux_private data being configured
in the probe. Also use a pointer to the struct urb being setup in
the buffer allocations.
Signed-off-by: NH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 b0daed19
...@@ -2296,209 +2296,194 @@ static int usbdux_usb_probe(struct usb_interface *uinterf, ...@@ -2296,209 +2296,194 @@ static int usbdux_usb_probe(struct usb_interface *uinterf,
{ {
struct usb_device *udev = interface_to_usbdev(uinterf); struct usb_device *udev = interface_to_usbdev(uinterf);
struct device *dev = &uinterf->dev; struct device *dev = &uinterf->dev;
struct usbdux_private *devpriv = NULL;
struct urb *urb;
int i; int i;
int index;
down(&start_stop_sem); down(&start_stop_sem);
/* look for a free place in the usbdux array */
index = -1;
for (i = 0; i < NUMUSBDUX; i++) { for (i = 0; i < NUMUSBDUX; i++) {
if (!(usbduxsub[i].probed)) { if (!usbduxsub[i].probed) {
index = i; devpriv = &usbduxsub[i];
break; break;
} }
} }
if (!devpriv) {
/* no more space */
if (index == -1) {
dev_err(dev, "Too many usbdux-devices connected.\n"); dev_err(dev, "Too many usbdux-devices connected.\n");
up(&start_stop_sem); up(&start_stop_sem);
return -EMFILE; return -EMFILE;
} }
sema_init(&(usbduxsub[index].sem), 1); sema_init(&devpriv->sem, 1);
/* save a pointer to the usb device */
usbduxsub[index].usbdev = udev;
/* 2.6: save the interface itself */ devpriv->usbdev = udev;
usbduxsub[index].interface = uinterf; devpriv->interface = uinterf;
/* get the interface number from the interface */ devpriv->ifnum = uinterf->altsetting->desc.bInterfaceNumber;
usbduxsub[index].ifnum = uinterf->altsetting->desc.bInterfaceNumber; usb_set_intfdata(uinterf, devpriv);
/* hand the private data over to the usb subsystem */
/* will be needed for disconnect */
usb_set_intfdata(uinterf, &(usbduxsub[index]));
/* test if it is high speed (USB 2.0) */ devpriv->high_speed = (devpriv->usbdev->speed == USB_SPEED_HIGH);
usbduxsub[index].high_speed =
(usbduxsub[index].usbdev->speed == USB_SPEED_HIGH);
/* create space for the commands of the DA converter */ /* create space for the commands of the DA converter */
usbduxsub[index].dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL); devpriv->dac_commands = kzalloc(NUMOUTCHANNELS, GFP_KERNEL);
if (!usbduxsub[index].dac_commands) { if (!devpriv->dac_commands) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space for the commands going to the usb device */ /* create space for the commands going to the usb device */
usbduxsub[index].dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL); devpriv->dux_commands = kzalloc(SIZEOFDUXBUFFER, GFP_KERNEL);
if (!usbduxsub[index].dux_commands) { if (!devpriv->dux_commands) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space for the in buffer and set it to zero */ /* create space for the in buffer and set it to zero */
usbduxsub[index].in_buffer = kzalloc(SIZEINBUF, GFP_KERNEL); devpriv->in_buffer = kzalloc(SIZEINBUF, GFP_KERNEL);
if (!(usbduxsub[index].in_buffer)) { if (!devpriv->in_buffer) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space of the instruction buffer */ /* create space of the instruction buffer */
usbduxsub[index].insn_buffer = kzalloc(SIZEINSNBUF, GFP_KERNEL); devpriv->insn_buffer = kzalloc(SIZEINSNBUF, GFP_KERNEL);
if (!(usbduxsub[index].insn_buffer)) { if (!devpriv->insn_buffer) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* create space for the outbuffer */ /* create space for the outbuffer */
usbduxsub[index].out_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL); devpriv->out_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
if (!(usbduxsub[index].out_buffer)) { if (!devpriv->out_buffer) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
/* setting to alternate setting 3: enabling iso ep and bulk ep. */ /* setting to alternate setting 3: enabling iso ep and bulk ep. */
i = usb_set_interface(usbduxsub[index].usbdev, i = usb_set_interface(devpriv->usbdev, devpriv->ifnum, 3);
usbduxsub[index].ifnum, 3);
if (i < 0) { if (i < 0) {
dev_err(dev, "comedi_: usbdux%d: " dev_err(dev,
"could not set alternate setting 3 in high speed.\n", "could not set alternate setting 3 in high speed\n");
index); tidy_up(devpriv);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENODEV; return -ENODEV;
} }
if (usbduxsub[index].high_speed) if (devpriv->high_speed)
usbduxsub[index].num_in_buffers = NUMOFINBUFFERSHIGH; devpriv->num_in_buffers = NUMOFINBUFFERSHIGH;
else else
usbduxsub[index].num_in_buffers = NUMOFINBUFFERSFULL; devpriv->num_in_buffers = NUMOFINBUFFERSFULL;
usbduxsub[index].urb_in = devpriv->urb_in = kcalloc(devpriv->num_in_buffers, sizeof(*urb),
kcalloc(usbduxsub[index].num_in_buffers, sizeof(struct urb *), GFP_KERNEL);
GFP_KERNEL); if (!devpriv->urb_in) {
if (!(usbduxsub[index].urb_in)) { tidy_up(devpriv);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
for (i = 0; i < usbduxsub[index].num_in_buffers; i++) { for (i = 0; i < devpriv->num_in_buffers; i++) {
/* one frame: 1ms */ /* one frame: 1ms */
usbduxsub[index].urb_in[i] = usb_alloc_urb(1, GFP_KERNEL); urb = usb_alloc_urb(1, GFP_KERNEL);
if (usbduxsub[index].urb_in[i] == NULL) { if (!urb) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urb_in[i]->dev = usbduxsub[index].usbdev; devpriv->urb_in[i] = urb;
urb->dev = devpriv->usbdev;
/* will be filled later with a pointer to the comedi-device */ /* will be filled later with a pointer to the comedi-device */
/* and ONLY then the urb should be submitted */ /* and ONLY then the urb should be submitted */
usbduxsub[index].urb_in[i]->context = NULL; urb->context = NULL;
usbduxsub[index].urb_in[i]->pipe = urb->pipe = usb_rcvisocpipe(devpriv->usbdev, ISOINEP);
usb_rcvisocpipe(usbduxsub[index].usbdev, ISOINEP); urb->transfer_flags = URB_ISO_ASAP;
usbduxsub[index].urb_in[i]->transfer_flags = URB_ISO_ASAP; urb->transfer_buffer = kzalloc(SIZEINBUF, GFP_KERNEL);
usbduxsub[index].urb_in[i]->transfer_buffer = if (!urb->transfer_buffer) {
kzalloc(SIZEINBUF, GFP_KERNEL); tidy_up(devpriv);
if (!(usbduxsub[index].urb_in[i]->transfer_buffer)) {
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urb_in[i]->complete = usbduxsub_ai_isoc_irq; urb->complete = usbduxsub_ai_isoc_irq;
usbduxsub[index].urb_in[i]->number_of_packets = 1; urb->number_of_packets = 1;
usbduxsub[index].urb_in[i]->transfer_buffer_length = SIZEINBUF; urb->transfer_buffer_length = SIZEINBUF;
usbduxsub[index].urb_in[i]->iso_frame_desc[0].offset = 0; urb->iso_frame_desc[0].offset = 0;
usbduxsub[index].urb_in[i]->iso_frame_desc[0].length = SIZEINBUF; urb->iso_frame_desc[0].length = SIZEINBUF;
} }
/* out */ /* out */
if (usbduxsub[index].high_speed) if (devpriv->high_speed)
usbduxsub[index].num_out_buffers = NUMOFOUTBUFFERSHIGH; devpriv->num_out_buffers = NUMOFOUTBUFFERSHIGH;
else else
usbduxsub[index].num_out_buffers = NUMOFOUTBUFFERSFULL; devpriv->num_out_buffers = NUMOFOUTBUFFERSFULL;
usbduxsub[index].urb_out = devpriv->urb_out = kcalloc(devpriv->num_out_buffers, sizeof(*urb),
kcalloc(usbduxsub[index].num_out_buffers, sizeof(struct urb *), GFP_KERNEL);
GFP_KERNEL); if (!devpriv->urb_out) {
if (!(usbduxsub[index].urb_out)) { tidy_up(devpriv);
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
for (i = 0; i < usbduxsub[index].num_out_buffers; i++) { for (i = 0; i < devpriv->num_out_buffers; i++) {
/* one frame: 1ms */ /* one frame: 1ms */
usbduxsub[index].urb_out[i] = usb_alloc_urb(1, GFP_KERNEL); urb = usb_alloc_urb(1, GFP_KERNEL);
if (usbduxsub[index].urb_out[i] == NULL) { if (!urb) {
tidy_up(&(usbduxsub[index])); tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urb_out[i]->dev = usbduxsub[index].usbdev; devpriv->urb_out[i] = urb;
urb->dev = devpriv->usbdev;
/* will be filled later with a pointer to the comedi-device */ /* will be filled later with a pointer to the comedi-device */
/* and ONLY then the urb should be submitted */ /* and ONLY then the urb should be submitted */
usbduxsub[index].urb_out[i]->context = NULL; urb->context = NULL;
usbduxsub[index].urb_out[i]->pipe = urb->pipe = usb_sndisocpipe(devpriv->usbdev, ISOOUTEP);
usb_sndisocpipe(usbduxsub[index].usbdev, ISOOUTEP); urb->transfer_flags = URB_ISO_ASAP;
usbduxsub[index].urb_out[i]->transfer_flags = URB_ISO_ASAP; urb->transfer_buffer = kzalloc(SIZEOUTBUF, GFP_KERNEL);
usbduxsub[index].urb_out[i]->transfer_buffer = if (!(urb->transfer_buffer)) {
kzalloc(SIZEOUTBUF, GFP_KERNEL); tidy_up(devpriv);
if (!(usbduxsub[index].urb_out[i]->transfer_buffer)) {
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urb_out[i]->complete = usbduxsub_ao_isoc_irq; urb->complete = usbduxsub_ao_isoc_irq;
usbduxsub[index].urb_out[i]->number_of_packets = 1; urb->number_of_packets = 1;
usbduxsub[index].urb_out[i]->transfer_buffer_length = SIZEOUTBUF; urb->transfer_buffer_length = SIZEOUTBUF;
usbduxsub[index].urb_out[i]->iso_frame_desc[0].offset = 0; urb->iso_frame_desc[0].offset = 0;
usbduxsub[index].urb_out[i]->iso_frame_desc[0].length = urb->iso_frame_desc[0].length = SIZEOUTBUF;
SIZEOUTBUF; if (devpriv->high_speed)
if (usbduxsub[index].high_speed) { urb->interval = 8; /* uframes */
/* uframes */ else
usbduxsub[index].urb_out[i]->interval = 8; urb->interval = 1; /* frames */
} else {
/* frames */
usbduxsub[index].urb_out[i]->interval = 1;
}
} }
/* pwm */ /* pwm */
if (usbduxsub[index].high_speed) { if (devpriv->high_speed) {
/* max bulk ep size in high speed */ urb = usb_alloc_urb(0, GFP_KERNEL);
usbduxsub[index].size_pwm_buf = 512; if (!urb) {
usbduxsub[index].urb_pwm = usb_alloc_urb(0, GFP_KERNEL); tidy_up(devpriv);
if (usbduxsub[index].urb_pwm == NULL) {
tidy_up(&(usbduxsub[index]));
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
usbduxsub[index].urb_pwm->transfer_buffer = devpriv->urb_pwm = urb;
kzalloc(usbduxsub[index].size_pwm_buf, GFP_KERNEL);
if (!(usbduxsub[index].urb_pwm->transfer_buffer)) { /* max bulk ep size in high speed */
tidy_up(&(usbduxsub[index])); devpriv->size_pwm_buf = 512;
urb->transfer_buffer = kzalloc(devpriv->size_pwm_buf,
GFP_KERNEL);
if (!urb->transfer_buffer) {
tidy_up(devpriv);
up(&start_stop_sem); up(&start_stop_sem);
return -ENOMEM; return -ENOMEM;
} }
} else { } else {
usbduxsub[index].urb_pwm = NULL; devpriv->urb_pwm = NULL;
usbduxsub[index].size_pwm_buf = 0; devpriv->size_pwm_buf = 0;
} }
usbduxsub[index].ai_cmd_running = 0; devpriv->ai_cmd_running = 0;
usbduxsub[index].ao_cmd_running = 0; devpriv->ao_cmd_running = 0;
usbduxsub[index].pwm_cmd_running = 0; devpriv->pwm_cmd_running = 0;
/* we've reached the bottom of the function */ /* we've reached the bottom of the function */
usbduxsub[index].probed = 1; devpriv->probed = 1;
up(&start_stop_sem); up(&start_stop_sem);
return comedi_usb_auto_config(uinterf, &usbdux_driver, 0); return comedi_usb_auto_config(uinterf, &usbdux_driver, 0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册