Merge git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6
[safe/jmp/linux-2.6] / drivers / staging / usbip / stub_rx.c
index 36ce898..5972ae7 100644 (file)
  * USA.
  */
 
+#include <linux/slab.h>
+
 #include "usbip_common.h"
 #include "stub.h"
-#include "../../usb/core/hcd.h"
+#include <linux/usb/hcd.h>
 
 
 static int is_clear_halt_cmd(struct urb *urb)
@@ -65,8 +67,8 @@ static int is_reset_device_cmd(struct urb *urb)
 
        if ((req->bRequest == USB_REQ_SET_FEATURE) &&
                        (req->bRequestType == USB_RT_PORT) &&
-                       (value = USB_PORT_FEAT_RESET)) {
-               dbg_stub_rx("reset_device_cmd, port %u\n", index);
+                       (value == USB_PORT_FEAT_RESET)) {
+               usbip_dbg_stub_rx("reset_device_cmd, port %u\n", index);
                return 1;
        } else
                return 0;
@@ -99,11 +101,11 @@ static int tweak_clear_halt_cmd(struct urb *urb)
 
        ret = usb_clear_halt(urb->dev, target_pipe);
        if (ret < 0)
-               uinfo("clear_halt error: devnum %d endp %d, %d\n",
-                               urb->dev->devnum, target_endp, ret);
+               usbip_uinfo("clear_halt error: devnum %d endp %d, %d\n",
+                                       urb->dev->devnum, target_endp, ret);
        else
-               uinfo("clear_halt done: devnum %d endp %d\n",
-                               urb->dev->devnum, target_endp);
+               usbip_uinfo("clear_halt done: devnum %d endp %d\n",
+                                       urb->dev->devnum, target_endp);
 
        return ret;
 }
@@ -119,14 +121,15 @@ static int tweak_set_interface_cmd(struct urb *urb)
        alternate = le16_to_cpu(req->wValue);
        interface = le16_to_cpu(req->wIndex);
 
-       dbg_stub_rx("set_interface: inf %u alt %u\n", interface, alternate);
+       usbip_dbg_stub_rx("set_interface: inf %u alt %u\n", interface,
+                                                               alternate);
 
        ret = usb_set_interface(urb->dev, interface, alternate);
        if (ret < 0)
-               uinfo("set_interface error: inf %u alt %u, %d\n",
-                               interface, alternate, ret);
+               usbip_uinfo("set_interface error: inf %u alt %u, %d\n",
+                                       interface, alternate, ret);
        else
-               uinfo("set_interface done: inf %u alt %u\n",
+               usbip_uinfo("set_interface done: inf %u alt %u\n",
                                                        interface,
                                                        alternate);
 
@@ -157,8 +160,9 @@ static int tweak_set_configuration_cmd(struct urb *urb)
         * A user may need to set a special configuration value before
         * exporting the device.
         */
-       uinfo("set_configuration (%d) to %s\n", config, urb->dev->dev.bus_id);
-       uinfo("but, skip!\n");
+       usbip_uinfo("set_configuration (%d) to %s\n", config,
+                                               dev_name(&urb->dev->dev));
+       usbip_uinfo("but, skip!\n");
 
        return 0;
        /* return usb_driver_set_configuration(urb->dev, config); */
@@ -175,7 +179,8 @@ static int tweak_reset_device_cmd(struct urb *urb)
        value = le16_to_cpu(req->wValue);
        index = le16_to_cpu(req->wIndex);
 
-       uinfo("reset_device (port %d) to %s\n", index, urb->dev->dev.bus_id);
+       usbip_uinfo("reset_device (port %d) to %s\n", index,
+                                               dev_name(&urb->dev->dev));
 
        /* all interfaces should be owned by usbip driver, so just reset it.  */
        ret = usb_lock_device_for_reset(urb->dev, NULL);
@@ -220,7 +225,7 @@ static void tweak_special_requests(struct urb *urb)
        else if (is_reset_device_cmd(urb))
                tweak_reset_device_cmd(urb);
        else
-               dbg_stub_rx("no need to tweak\n");
+               usbip_dbg_stub_rx("no need to tweak\n");
 }
 
 /*
@@ -234,8 +239,6 @@ static void tweak_special_requests(struct urb *urb)
 static int stub_recv_cmd_unlink(struct stub_device *sdev,
                                                struct usbip_header *pdu)
 {
-       struct list_head *listhead = &sdev->priv_init;
-       struct list_head *ptr;
        unsigned long flags;
 
        struct stub_priv *priv;
@@ -243,8 +246,7 @@ static int stub_recv_cmd_unlink(struct stub_device *sdev,
 
        spin_lock_irqsave(&sdev->priv_lock, flags);
 
-       for (ptr = listhead->next; ptr != listhead; ptr = ptr->next) {
-               priv = list_entry(ptr, struct stub_priv, list);
+       list_for_each_entry(priv, &sdev->priv_init, list) {
                if (priv->seqnum == pdu->u.cmd_unlink.seqnum) {
                        int ret;
 
@@ -295,7 +297,8 @@ static int stub_recv_cmd_unlink(struct stub_device *sdev,
                }
        }
 
-       dbg_stub_rx("seqnum %d is not pending\n", pdu->u.cmd_unlink.seqnum);
+       usbip_dbg_stub_rx("seqnum %d is not pending\n",
+                                               pdu->u.cmd_unlink.seqnum);
 
        /*
         * The urb of the unlink target is not found in priv_init queue. It was
@@ -337,7 +340,7 @@ static struct stub_priv *stub_priv_alloc(struct stub_device *sdev,
 
        spin_lock_irqsave(&sdev->priv_lock, flags);
 
-       priv = kmem_cache_alloc(stub_priv_cache, GFP_ATOMIC);
+       priv = kmem_cache_zalloc(stub_priv_cache, GFP_ATOMIC);
        if (!priv) {
                dev_err(&sdev->interface->dev, "alloc stub_priv\n");
                spin_unlock_irqrestore(&sdev->priv_lock, flags);
@@ -345,8 +348,6 @@ static struct stub_priv *stub_priv_alloc(struct stub_device *sdev,
                return NULL;
        }
 
-       memset(priv, 0, sizeof(struct stub_priv));
-
        priv->seqnum = pdu->base.seqnum;
        priv->sdev = sdev;
 
@@ -388,7 +389,7 @@ static struct usb_host_endpoint *get_ep_from_epnum(struct usb_device *udev,
                        epnum = (ep->desc.bEndpointAddress & 0x7f);
 
                        if (epnum == epnum0) {
-                               /* uinfo("found epnum %d\n", epnum0); */
+                               /* usbip_uinfo("found epnum %d\n", epnum0);*/
                                found = 1;
                                break;
                        }
@@ -501,13 +502,13 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
        }
 
        /* set priv->urb->setup_packet */
-       priv->urb->setup_packet = kzalloc(8, GFP_KERNEL);
+       priv->urb->setup_packet = kmemdup(&pdu->u.cmd_submit.setup, 8,
+                                         GFP_KERNEL);
        if (!priv->urb->setup_packet) {
                dev_err(&sdev->interface->dev, "allocate setup_packet\n");
                usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC);
                return;
        }
-       memcpy(priv->urb->setup_packet, &pdu->u.cmd_submit.setup, 8);
 
        /* set other members from the base header of pdu */
        priv->urb->context                = (void *) priv;
@@ -531,7 +532,8 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
        ret = usb_submit_urb(priv->urb, GFP_KERNEL);
 
        if (ret == 0)
-               dbg_stub_rx("submit urb ok, seqnum %u\n", pdu->base.seqnum);
+               usbip_dbg_stub_rx("submit urb ok, seqnum %u\n",
+                                                       pdu->base.seqnum);
        else {
                dev_err(&sdev->interface->dev, "submit_urb error, %d\n", ret);
                usbip_dump_header(pdu);
@@ -544,7 +546,7 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,
                usbip_event_add(ud, SDEV_EVENT_ERROR_SUBMIT);
        }
 
-       dbg_stub_rx("Leave\n");
+       usbip_dbg_stub_rx("Leave\n");
        return;
 }
 
@@ -556,7 +558,7 @@ static void stub_rx_pdu(struct usbip_device *ud)
        struct stub_device *sdev = container_of(ud, struct stub_device, ud);
        struct device *dev = &sdev->interface->dev;
 
-       dbg_stub_rx("Enter\n");
+       usbip_dbg_stub_rx("Enter\n");
 
        memset(&pdu, 0, sizeof(pdu));
 
@@ -570,7 +572,7 @@ static void stub_rx_pdu(struct usbip_device *ud)
 
        usbip_header_correct_endian(&pdu, 0);
 
-       if (dbg_flag_stub_rx)
+       if (usbip_dbg_flag_stub_rx)
                usbip_dump_header(&pdu);
 
        if (!valid_request(sdev, &pdu)) {
@@ -603,11 +605,11 @@ void stub_rx_loop(struct usbip_task *ut)
 
        while (1) {
                if (signal_pending(current)) {
-                       dbg_stub_rx("signal caught!\n");
+                       usbip_dbg_stub_rx("signal caught!\n");
                        break;
                }
 
-               if (usbip_event_happend(ud))
+               if (usbip_event_happened(ud))
                        break;
 
                stub_rx_pdu(ud);