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

staging: comedi: vmk80xx: factor out usb buffer allocation

Factor the code that allocates the usb buffers out of vmk80xx_usb_probe().
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 49253d54
...@@ -1172,6 +1172,25 @@ static int vmk80xx_find_usb_endpoints(struct vmk80xx_private *devpriv, ...@@ -1172,6 +1172,25 @@ static int vmk80xx_find_usb_endpoints(struct vmk80xx_private *devpriv,
return 0; return 0;
} }
static int vmk80xx_alloc_usb_buffers(struct vmk80xx_private *devpriv)
{
size_t size;
size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize);
devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL);
if (!devpriv->usb_rx_buf)
return -ENOMEM;
size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
devpriv->usb_tx_buf = kmalloc(size, GFP_KERNEL);
if (!devpriv->usb_tx_buf) {
kfree(devpriv->usb_rx_buf);
return -ENOMEM;
}
return 0;
}
static int vmk80xx_attach_common(struct comedi_device *dev, static int vmk80xx_attach_common(struct comedi_device *dev,
struct vmk80xx_private *devpriv) struct vmk80xx_private *devpriv)
{ {
...@@ -1333,7 +1352,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, ...@@ -1333,7 +1352,6 @@ static int vmk80xx_usb_probe(struct usb_interface *intf,
{ {
const struct vmk80xx_board *boardinfo; const struct vmk80xx_board *boardinfo;
struct vmk80xx_private *devpriv; struct vmk80xx_private *devpriv;
size_t size;
int ret; int ret;
int i; int i;
...@@ -1359,19 +1377,10 @@ static int vmk80xx_usb_probe(struct usb_interface *intf, ...@@ -1359,19 +1377,10 @@ static int vmk80xx_usb_probe(struct usb_interface *intf,
return ret; return ret;
} }
size = le16_to_cpu(devpriv->ep_rx->wMaxPacketSize); ret = vmk80xx_alloc_usb_buffers(devpriv);
devpriv->usb_rx_buf = kmalloc(size, GFP_KERNEL); if (ret) {
if (!devpriv->usb_rx_buf) {
mutex_unlock(&glb_mutex);
return -ENOMEM;
}
size = le16_to_cpu(devpriv->ep_tx->wMaxPacketSize);
devpriv->usb_tx_buf = kmalloc(size, GFP_KERNEL);
if (!devpriv->usb_tx_buf) {
kfree(devpriv->usb_rx_buf);
mutex_unlock(&glb_mutex); mutex_unlock(&glb_mutex);
return -ENOMEM; return ret;
} }
devpriv->usb = interface_to_usbdev(intf); devpriv->usb = interface_to_usbdev(intf);
......
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