Commit 48735862 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: iforce - use DMA-safe buffer when getting IDs from USB

When working with USB devices we need to use DMA-safe buffers,
and iforce->edata is not one. Let's rework the code to allocate
temporary buffer (iforce_get_id() is called only during initialization
so there is no reason to have permanent buffer) and use it. While at it,
let's utilize usb_control_msg() API which simplifies code.
Tested-by: default avatarTim Schumacher <timschumi@gmx.de>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 4f99de6d
...@@ -29,8 +29,7 @@ struct iforce_usb { ...@@ -29,8 +29,7 @@ struct iforce_usb {
struct usb_device *usbdev; struct usb_device *usbdev;
struct usb_interface *intf; struct usb_interface *intf;
struct urb *irq, *out, *ctrl; struct urb *irq, *out;
struct usb_ctrlrequest cr;
}; };
static void __iforce_usb_xmit(struct iforce *iforce) static void __iforce_usb_xmit(struct iforce *iforce)
...@@ -92,30 +91,32 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) ...@@ -92,30 +91,32 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet)
{ {
struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb,
iforce); iforce);
u8 *buf;
int status; int status;
iforce_usb->cr.bRequest = packet[0]; buf = kmalloc(IFORCE_MAX_LENGTH, GFP_KERNEL);
iforce_usb->ctrl->dev = iforce_usb->usbdev; if (!buf)
return -ENOMEM;
status = usb_submit_urb(iforce_usb->ctrl, GFP_KERNEL);
if (status) { status = usb_control_msg(iforce_usb->usbdev,
usb_rcvctrlpipe(iforce_usb->usbdev, 0),
packet[0],
USB_TYPE_VENDOR | USB_DIR_IN |
USB_RECIP_INTERFACE,
0, 0, buf, IFORCE_MAX_LENGTH, HZ);
if (status < 0) {
dev_err(&iforce_usb->intf->dev, dev_err(&iforce_usb->intf->dev,
"usb_submit_urb failed %d\n", status); "usb_submit_urb failed: %d\n", status);
return -EIO; } else if (buf[0] != packet[0]) {
} status = -EIO;
} else {
wait_event_interruptible_timeout(iforce->wait, iforce->ecmd = 0xff00 | status;
iforce_usb->ctrl->status != -EINPROGRESS, HZ); memcpy(iforce->edata, buf, status);
status = 0;
if (iforce_usb->ctrl->status) {
dev_dbg(&iforce_usb->intf->dev,
"iforce->ctrl->status = %d\n",
iforce_usb->ctrl->status);
usb_unlink_urb(iforce_usb->ctrl);
return -EIO;
} }
return -(iforce->edata[0] != packet[0]); kfree(buf);
return status;
} }
static int iforce_usb_start_io(struct iforce *iforce) static int iforce_usb_start_io(struct iforce *iforce)
...@@ -136,7 +137,6 @@ static void iforce_usb_stop_io(struct iforce *iforce) ...@@ -136,7 +137,6 @@ static void iforce_usb_stop_io(struct iforce *iforce)
usb_kill_urb(iforce_usb->irq); usb_kill_urb(iforce_usb->irq);
usb_kill_urb(iforce_usb->out); usb_kill_urb(iforce_usb->out);
usb_kill_urb(iforce_usb->ctrl);
} }
static const struct iforce_xport_ops iforce_usb_xport_ops = { static const struct iforce_xport_ops iforce_usb_xport_ops = {
...@@ -197,18 +197,6 @@ static void iforce_usb_out(struct urb *urb) ...@@ -197,18 +197,6 @@ static void iforce_usb_out(struct urb *urb)
wake_up(&iforce->wait); wake_up(&iforce->wait);
} }
static void iforce_usb_ctrl(struct urb *urb)
{
struct iforce_usb *iforce_usb = urb->context;
struct iforce *iforce = &iforce_usb->iforce;
if (urb->status)
return;
iforce->ecmd = 0xff00 | urb->actual_length;
wake_up(&iforce->wait);
}
static int iforce_usb_probe(struct usb_interface *intf, static int iforce_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id) const struct usb_device_id *id)
{ {
...@@ -236,9 +224,6 @@ static int iforce_usb_probe(struct usb_interface *intf, ...@@ -236,9 +224,6 @@ static int iforce_usb_probe(struct usb_interface *intf,
if (!(iforce_usb->out = usb_alloc_urb(0, GFP_KERNEL))) if (!(iforce_usb->out = usb_alloc_urb(0, GFP_KERNEL)))
goto fail; goto fail;
if (!(iforce_usb->ctrl = usb_alloc_urb(0, GFP_KERNEL)))
goto fail;
iforce = &iforce_usb->iforce; iforce = &iforce_usb->iforce;
iforce->xport_ops = &iforce_usb_xport_ops; iforce->xport_ops = &iforce_usb_xport_ops;
...@@ -247,19 +232,12 @@ static int iforce_usb_probe(struct usb_interface *intf, ...@@ -247,19 +232,12 @@ static int iforce_usb_probe(struct usb_interface *intf,
iforce_usb->usbdev = dev; iforce_usb->usbdev = dev;
iforce_usb->intf = intf; iforce_usb->intf = intf;
iforce_usb->cr.bRequestType = USB_TYPE_VENDOR | USB_DIR_IN | USB_RECIP_INTERFACE;
iforce_usb->cr.wIndex = 0;
iforce_usb->cr.wLength = cpu_to_le16(16);
usb_fill_int_urb(iforce_usb->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress), usb_fill_int_urb(iforce_usb->irq, dev, usb_rcvintpipe(dev, epirq->bEndpointAddress),
iforce->data, 16, iforce_usb_irq, iforce_usb, epirq->bInterval); iforce->data, 16, iforce_usb_irq, iforce_usb, epirq->bInterval);
usb_fill_int_urb(iforce_usb->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress), usb_fill_int_urb(iforce_usb->out, dev, usb_sndintpipe(dev, epout->bEndpointAddress),
iforce_usb + 1, 32, iforce_usb_out, iforce_usb, epout->bInterval); iforce_usb + 1, 32, iforce_usb_out, iforce_usb, epout->bInterval);
usb_fill_control_urb(iforce_usb->ctrl, dev, usb_rcvctrlpipe(dev, 0),
(void*) &iforce_usb->cr, iforce->edata, 16, iforce_usb_ctrl, iforce_usb);
err = iforce_init_device(&intf->dev, BUS_USB, iforce); err = iforce_init_device(&intf->dev, BUS_USB, iforce);
if (err) if (err)
goto fail; goto fail;
...@@ -271,7 +249,6 @@ static int iforce_usb_probe(struct usb_interface *intf, ...@@ -271,7 +249,6 @@ static int iforce_usb_probe(struct usb_interface *intf,
if (iforce_usb) { if (iforce_usb) {
usb_free_urb(iforce_usb->irq); usb_free_urb(iforce_usb->irq);
usb_free_urb(iforce_usb->out); usb_free_urb(iforce_usb->out);
usb_free_urb(iforce_usb->ctrl);
kfree(iforce_usb); kfree(iforce_usb);
} }
...@@ -288,7 +265,6 @@ static void iforce_usb_disconnect(struct usb_interface *intf) ...@@ -288,7 +265,6 @@ static void iforce_usb_disconnect(struct usb_interface *intf)
usb_free_urb(iforce_usb->irq); usb_free_urb(iforce_usb->irq);
usb_free_urb(iforce_usb->out); usb_free_urb(iforce_usb->out);
usb_free_urb(iforce_usb->ctrl);
kfree(iforce_usb); kfree(iforce_usb);
} }
......
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