Staging: USB-IP code cleanup

This includes fixes for all of the legit checkpatch.pl errors and
warnings.  I have also included several of the suggestions from the
linux-kernel mailing list when the USB-IP code was first added.

Signed-off-by: Brian G. Merrell <bgmerrell@novell.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
index f69ca34..114db8b 100644
--- a/drivers/staging/usbip/vhci_hcd.c
+++ b/drivers/staging/usbip/vhci_hcd.c
@@ -115,7 +115,7 @@
 {
 	unsigned long	flags;
 
-	dbg_vhci_rh("rh_port_connect %d\n", rhport);
+	usbip_dbg_vhci_rh("rh_port_connect %d\n", rhport);
 
 	spin_lock_irqsave(&the_controller->lock, flags);
 
@@ -148,7 +148,7 @@
 {
 	unsigned long flags;
 
-	dbg_vhci_rh("rh_port_disconnect %d\n", rhport);
+	usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport);
 
 	spin_lock_irqsave(&the_controller->lock, flags);
 	/* stop_activity(dum, driver); */
@@ -215,7 +215,7 @@
 
 	spin_lock_irqsave(&vhci->lock, flags);
 	if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
-		dbg_vhci_rh("hw accessible flag in on?\n");
+		usbip_dbg_vhci_rh("hw accessible flag in on?\n");
 		goto done;
 	}
 
@@ -223,14 +223,14 @@
 	for (rhport = 0; rhport < VHCI_NPORTS; rhport++) {
 		if ((vhci->port_status[rhport] & PORT_C_MASK)) {
 			/* The status of a port has been changed, */
-			dbg_vhci_rh("port %d is changed\n", rhport);
+			usbip_dbg_vhci_rh("port %d is changed\n", rhport);
 
 			*event_bits |= 1 << (rhport + 1);
 			changed = 1;
 		}
 	}
 
-	uinfo("changed %d\n", changed);
+	usbip_uinfo("changed %d\n", changed);
 
 	if (hcd->state == HC_STATE_SUSPENDED)
 		usb_hcd_resume_root_hub(hcd);
@@ -275,10 +275,11 @@
 	 * NOTE:
 	 * wIndex shows the port number and begins from 1.
 	 */
-	dbg_vhci_rh("typeReq %x wValue %x wIndex %x\n", typeReq, wValue,
+	usbip_dbg_vhci_rh("typeReq %x wValue %x wIndex %x\n", typeReq, wValue,
 								wIndex);
 	if (wIndex > VHCI_NPORTS)
-		printk(KERN_ERR "%s: invalid port number %d\n", __func__, wIndex);
+		printk(KERN_ERR "%s: invalid port number %d\n", __func__,
+								wIndex);
 	rhport = ((__u8)(wIndex & 0x00ff)) - 1;
 
 	dum = hcd_to_vhci(hcd);
@@ -286,7 +287,7 @@
 	spin_lock_irqsave(&dum->lock, flags);
 
 	/* store old status and compare now and old later */
-	if (dbg_flag_vhci_rh) {
+	if (usbip_dbg_flag_vhci_rh) {
 		int i = 0;
 		for (i = 0; i < VHCI_NPORTS; i++)
 			prev_port_status[i] = dum->port_status[i];
@@ -294,7 +295,7 @@
 
 	switch (typeReq) {
 	case ClearHubFeature:
-		dbg_vhci_rh(" ClearHubFeature\n");
+		usbip_dbg_vhci_rh(" ClearHubFeature\n");
 		break;
 	case ClearPortFeature:
 		switch (wValue) {
@@ -307,15 +308,16 @@
 			}
 			break;
 		case USB_PORT_FEAT_POWER:
-			dbg_vhci_rh(" ClearPortFeature: USB_PORT_FEAT_POWER\n");
+			usbip_dbg_vhci_rh(" ClearPortFeature: "
+						"USB_PORT_FEAT_POWER\n");
 			dum->port_status[rhport] = 0;
 			/* dum->address = 0; */
 			/* dum->hdev = 0; */
 			dum->resuming = 0;
 			break;
 		case USB_PORT_FEAT_C_RESET:
-			dbg_vhci_rh(" ClearPortFeature: "
-					"USB_PORT_FEAT_C_RESET\n");
+			usbip_dbg_vhci_rh(" ClearPortFeature: "
+						"USB_PORT_FEAT_C_RESET\n");
 			switch (dum->vdev[rhport].speed) {
 			case USB_SPEED_HIGH:
 				dum->port_status[rhport] |=
@@ -329,20 +331,21 @@
 				break;
 			}
 		default:
-			dbg_vhci_rh(" ClearPortFeature: default %x\n", wValue);
+			usbip_dbg_vhci_rh(" ClearPortFeature: default %x\n",
+								wValue);
 			dum->port_status[rhport] &= ~(1 << wValue);
 		}
 		break;
 	case GetHubDescriptor:
-		dbg_vhci_rh(" GetHubDescriptor\n");
+		usbip_dbg_vhci_rh(" GetHubDescriptor\n");
 		hub_descriptor((struct usb_hub_descriptor *) buf);
 		break;
 	case GetHubStatus:
-		dbg_vhci_rh(" GetHubStatus\n");
+		usbip_dbg_vhci_rh(" GetHubStatus\n");
 		*(__le32 *) buf = __constant_cpu_to_le32(0);
 		break;
 	case GetPortStatus:
-		dbg_vhci_rh(" GetPortStatus port %x\n", wIndex);
+		usbip_dbg_vhci_rh(" GetPortStatus port %x\n", wIndex);
 		if (wIndex > VHCI_NPORTS || wIndex < 1) {
 			printk(KERN_ERR "%s: invalid port number %d\n",
 			       __func__, wIndex);
@@ -379,7 +382,8 @@
 
 			if (dum->vdev[rhport].ud.status ==
 							VDEV_ST_NOTASSIGNED) {
-				dbg_vhci_rh(" enable rhport %d (status %u)\n",
+				usbip_dbg_vhci_rh(" enable rhport %d "
+						"(status %u)\n",
 						rhport,
 						dum->vdev[rhport].ud.status);
 				dum->port_status[rhport] |=
@@ -415,17 +419,17 @@
 		((u16 *) buf)[1] =
 				cpu_to_le16(dum->port_status[rhport] >> 16);
 
-		dbg_vhci_rh(" GetPortStatus bye %x %x\n", ((u16 *)buf)[0],
+		usbip_dbg_vhci_rh(" GetPortStatus bye %x %x\n", ((u16 *)buf)[0],
 							((u16 *)buf)[1]);
 		break;
 	case SetHubFeature:
-		dbg_vhci_rh(" SetHubFeature\n");
+		usbip_dbg_vhci_rh(" SetHubFeature\n");
 		retval = -EPIPE;
 		break;
 	case SetPortFeature:
 		switch (wValue) {
 		case USB_PORT_FEAT_SUSPEND:
-			dbg_vhci_rh(" SetPortFeature: "
+			usbip_dbg_vhci_rh(" SetPortFeature: "
 					"USB_PORT_FEAT_SUSPEND\n");
 			printk(KERN_ERR "%s: not yet\n", __func__);
 #if 0
@@ -439,7 +443,8 @@
 #endif
 			break;
 		case USB_PORT_FEAT_RESET:
-			dbg_vhci_rh(" SetPortFeature: USB_PORT_FEAT_RESET\n");
+			usbip_dbg_vhci_rh(" SetPortFeature: "
+						"USB_PORT_FEAT_RESET\n");
 			/* if it's already running, disconnect first */
 			if (dum->port_status[rhport] & USB_PORT_STAT_ENABLE) {
 				dum->port_status[rhport] &=
@@ -460,7 +465,8 @@
 
 			/* FALLTHROUGH */
 		default:
-			dbg_vhci_rh(" SetPortFeature: default %d\n", wValue);
+			usbip_dbg_vhci_rh(" SetPortFeature: default %d\n",
+								wValue);
 			dum->port_status[rhport] |= (1 << wValue);
 		}
 		break;
@@ -475,12 +481,12 @@
 		retval = -EPIPE;
 	}
 
-	if (dbg_flag_vhci_rh) {
+	if (usbip_dbg_flag_vhci_rh) {
 		printk(KERN_DEBUG "port %d\n", rhport);
 		dump_port_status(prev_port_status[rhport]);
 		dump_port_status(dum->port_status[rhport]);
 	}
-	dbg_vhci_rh(" bye\n");
+	usbip_dbg_vhci_rh(" bye\n");
 
 	spin_unlock_irqrestore(&dum->lock, flags);
 
@@ -517,9 +523,10 @@
 		return;
 	}
 
+	priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC);
+
 	spin_lock_irqsave(&vdev->priv_lock, flag);
 
-	priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC);
 	if (!priv) {
 		dev_err(&urb->dev->dev, "malloc vhci_priv\n");
 		spin_unlock_irqrestore(&vdev->priv_lock, flag);
@@ -529,7 +536,7 @@
 
 	priv->seqnum = atomic_inc_return(&the_controller->seqnum);
 	if (priv->seqnum == 0xffff)
-		uinfo("seqnum max\n");
+		usbip_uinfo("seqnum max\n");
 
 	priv->vdev = vdev;
 	priv->urb = urb;
@@ -550,7 +557,7 @@
 	int ret = 0;
 	unsigned long flags;
 
-	dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n",
+	usbip_dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n",
 		    hcd, urb, mem_flags);
 
 	/* patch to usb_sg_init() is in 2.5.60 */
@@ -558,13 +565,6 @@
 
 	spin_lock_irqsave(&the_controller->lock, flags);
 
-	/* check HC is active or not */
-	if (!HC_IS_RUNNING(hcd->state)) {
-		dev_err(dev, "HC is not running\n");
-		spin_unlock_irqrestore(&the_controller->lock, flags);
-		return -ENODEV;
-	}
-
 	if (urb->status != -EINPROGRESS) {
 		dev_err(dev, "URB already unlinked!, status %d\n", urb->status);
 		spin_unlock_irqrestore(&the_controller->lock, flags);
@@ -576,7 +576,7 @@
 		goto no_need_unlink;
 
 	/*
-	 * The enumelation process is as follows;
+	 * The enumeration process is as follows;
 	 *
 	 *  1. Get_Descriptor request to DevAddrs(0) EndPoint(0)
 	 *     to get max packet length of default pipe
@@ -620,7 +620,7 @@
 
 		case USB_REQ_GET_DESCRIPTOR:
 			if (ctrlreq->wValue == (USB_DT_DEVICE << 8))
-				dbg_vhci_hc("Not yet?: "
+				usbip_dbg_vhci_hc("Not yet?: "
 						"Get_Descriptor to device 0 "
 						"(get max pipe size)\n");
 
@@ -708,7 +708,7 @@
 	struct vhci_priv *priv;
 	struct vhci_device *vdev;
 
-	uinfo("vhci_hcd: dequeue a urb %p\n", urb);
+	usbip_uinfo("vhci_hcd: dequeue a urb %p\n", urb);
 
 
 	spin_lock_irqsave(&the_controller->lock, flags);
@@ -726,7 +726,7 @@
 		ret = usb_hcd_check_unlink_urb(hcd, urb, status);
 		if (ret) {
 			spin_unlock_irqrestore(&the_controller->lock, flags);
-			return 0;
+			return ret;
 		}
 	}
 
@@ -739,13 +739,29 @@
 
 		spin_lock_irqsave(&vdev->priv_lock, flags2);
 
-		uinfo("vhci_hcd: device %p seems to be disconnected\n", vdev);
+		usbip_uinfo("vhci_hcd: device %p seems to be disconnected\n",
+									vdev);
 		list_del(&priv->list);
 		kfree(priv);
 		urb->hcpriv = NULL;
 
 		spin_unlock_irqrestore(&vdev->priv_lock, flags2);
 
+		/*
+		 * If tcp connection is alive, we have sent CMD_UNLINK.
+		 * vhci_rx will receive RET_UNLINK and give back the URB.
+		 * Otherwise, we give back it here.
+		 */
+		usbip_uinfo("vhci_hcd: vhci_urb_dequeue() gives back urb %p\n",
+									urb);
+
+		usb_hcd_unlink_urb_from_ep(hcd, urb);
+
+		spin_unlock_irqrestore(&the_controller->lock, flags);
+		usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
+								urb->status);
+		spin_lock_irqsave(&the_controller->lock, flags);
+
 	} else {
 		/* tcp connection is alive */
 		unsigned long flags2;
@@ -756,7 +772,7 @@
 		/* setup CMD_UNLINK pdu */
 		unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC);
 		if (!unlink) {
-			uerr("malloc vhci_unlink\n");
+			usbip_uerr("malloc vhci_unlink\n");
 			spin_unlock_irqrestore(&vdev->priv_lock, flags2);
 			spin_unlock_irqrestore(&the_controller->lock, flags);
 			usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);
@@ -765,11 +781,11 @@
 
 		unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
 		if (unlink->seqnum == 0xffff)
-			uinfo("seqnum max\n");
+			usbip_uinfo("seqnum max\n");
 
 		unlink->unlink_seqnum = priv->seqnum;
 
-		uinfo("vhci_hcd: device %p seems to be still connected\n",
+		usbip_uinfo("vhci_hcd: device %p seems to be still connected\n",
 									vdev);
 
 		/* send cmd_unlink and try to cancel the pending URB in the
@@ -781,14 +797,10 @@
 	}
 
 
-	/*
-	 * If tcp connection is alive, we have sent CMD_UNLINK.
-	 * vhci_rx will receive RET_UNLINK and give back the URB.
-	 * Otherwise, we give back it here.
-	 */
 	if (!vdev->ud.tcp_socket) {
 		/* tcp connection is closed */
-		uinfo("vhci_hcd: vhci_urb_dequeue() gives back urb %p\n", urb);
+		usbip_uinfo("vhci_hcd: vhci_urb_dequeue() gives back urb %p\n",
+									urb);
 
 		usb_hcd_unlink_urb_from_ep(hcd, urb);
 
@@ -800,7 +812,7 @@
 
 	spin_unlock_irqrestore(&the_controller->lock, flags);
 
-	dbg_vhci_hc("leave\n");
+	usbip_dbg_vhci_hc("leave\n");
 	return 0;
 }
 
@@ -835,19 +847,19 @@
 
 	/* need this? see stub_dev.c */
 	if (ud->tcp_socket) {
-		udbg("shutdown tcp_socket %p\n", ud->tcp_socket);
+		usbip_udbg("shutdown tcp_socket %p\n", ud->tcp_socket);
 		kernel_sock_shutdown(ud->tcp_socket, SHUT_RDWR);
 	}
 
 	usbip_stop_threads(&vdev->ud);
-	uinfo("stop threads\n");
+	usbip_uinfo("stop threads\n");
 
 	/* active connection is closed */
 	if (vdev->ud.tcp_socket != NULL) {
 		sock_release(vdev->ud.tcp_socket);
 		vdev->ud.tcp_socket = NULL;
 	}
-	uinfo("release socket\n");
+	usbip_uinfo("release socket\n");
 
 	vhci_device_unlink_cleanup(vdev);
 
@@ -873,7 +885,7 @@
 	 */
 	rh_port_disconnect(vdev->rhport);
 
-	uinfo("disconnect device\n");
+	usbip_uinfo("disconnect device\n");
 }
 
 
@@ -939,7 +951,7 @@
 	int rhport;
 	int err = 0;
 
-	dbg_vhci_hc("enter vhci_start\n");
+	usbip_dbg_vhci_hc("enter vhci_start\n");
 
 
 	/* initialize private data of usb_hcd */
@@ -963,7 +975,7 @@
 	/* vhci_hcd is now ready to be controlled through sysfs */
 	err = sysfs_create_group(&vhci_dev(vhci)->kobj, &dev_attr_group);
 	if (err) {
-		uerr("create sysfs files\n");
+		usbip_uerr("create sysfs files\n");
 		return err;
 	}
 
@@ -975,7 +987,7 @@
 	struct vhci_hcd *vhci = hcd_to_vhci(hcd);
 	int rhport = 0;
 
-	dbg_vhci_hc("stop VHCI controller\n");
+	usbip_dbg_vhci_hc("stop VHCI controller\n");
 
 
 	/* 1. remove the userland interface of vhci_hcd */
@@ -990,14 +1002,14 @@
 	}
 
 
-	uinfo("vhci_stop done\n");
+	usbip_uinfo("vhci_stop done\n");
 }
 
 /*----------------------------------------------------------------------*/
 
 static int vhci_get_frame_number(struct usb_hcd *hcd)
 {
-	uerr("Not yet implemented\n");
+	usbip_uerr("Not yet implemented\n");
 	return 0;
 }
 
@@ -1077,9 +1089,9 @@
 	struct usb_hcd		*hcd;
 	int			ret;
 
-	uinfo("proving...\n");
+	usbip_uinfo("proving...\n");
 
-	dbg_vhci_hc("name %s id %d\n", pdev->name, pdev->id);
+	usbip_dbg_vhci_hc("name %s id %d\n", pdev->name, pdev->id);
 
 	/* will be removed */
 	if (pdev->dev.dma_mask) {
@@ -1093,7 +1105,7 @@
 	 */
 	hcd = usb_create_hcd(&vhci_hc_driver, &pdev->dev, dev_name(&pdev->dev));
 	if (!hcd) {
-		uerr("create hcd failed\n");
+		usbip_uerr("create hcd failed\n");
 		return -ENOMEM;
 	}
 
@@ -1107,14 +1119,14 @@
 	 */
 	ret = usb_add_hcd(hcd, 0, 0);
 	if (ret != 0) {
-		uerr("usb_add_hcd failed %d\n", ret);
+		usbip_uerr("usb_add_hcd failed %d\n", ret);
 		usb_put_hcd(hcd);
 		the_controller = NULL;
 		return ret;
 	}
 
 
-	dbg_vhci_hc("bye\n");
+	usbip_dbg_vhci_hc("bye\n");
 	return 0;
 }
 
@@ -1166,11 +1178,11 @@
 	spin_unlock(&the_controller->lock);
 
 	if (connected > 0) {
-		uinfo("We have %d active connection%s. Do not suspend.\n",
+		usbip_uinfo("We have %d active connection%s. Do not suspend.\n",
 				connected, (connected == 1 ? "" : "s"));
 		ret =  -EBUSY;
 	} else {
-		uinfo("suspend vhci_hcd");
+		usbip_uinfo("suspend vhci_hcd");
 		clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
 	}
 
@@ -1235,7 +1247,7 @@
 {
 	int ret;
 
-	dbg_vhci_hc("enter\n");
+	usbip_dbg_vhci_hc("enter\n");
 	if (usb_disabled())
 		return -ENODEV;
 
@@ -1250,7 +1262,7 @@
 	if (ret < 0)
 		goto err_platform_device_register;
 
-	dbg_vhci_hc("bye\n");
+	usbip_dbg_vhci_hc("bye\n");
 	return ret;
 
 	/* error occurred */
@@ -1258,18 +1270,18 @@
 	platform_driver_unregister(&vhci_driver);
 
 err_driver_register:
-	dbg_vhci_hc("bye\n");
+	usbip_dbg_vhci_hc("bye\n");
 	return ret;
 }
 module_init(vhci_init);
 
 static void __exit vhci_cleanup(void)
 {
-	dbg_vhci_hc("enter\n");
+	usbip_dbg_vhci_hc("enter\n");
 
 	platform_device_unregister(&the_pdev);
 	platform_driver_unregister(&vhci_driver);
 
-	dbg_vhci_hc("bye\n");
+	usbip_dbg_vhci_hc("bye\n");
 }
 module_exit(vhci_cleanup);