usb: misc: lvstest: allow specifying port for compliance mode

In some cases when connecting to a test fixture the host port
might not have triggered a connect change. As a result, dev->portnum
does not get updated and an attempt to enable the port for
compliance mode will pass 0 as the port number to the HCD, which is
invalid. Instead allow the user to pass an explicit port number
from the command line to specify the port to act on. Otherwise, if
omitted, the behavior is the same as before.

Change-Id: I2e323c9016915b2d535ac227fd6f3d5846aa4026
Signed-off-by: Jack Pham <jackp@codeaurora.org>
diff --git a/drivers/usb/misc/lvstest.c b/drivers/usb/misc/lvstest.c
index 2020009..934e10f 100644
--- a/drivers/usb/misc/lvstest.c
+++ b/drivers/usb/misc/lvstest.c
@@ -184,10 +184,13 @@
 	struct usb_interface *intf = to_usb_interface(dev);
 	struct usb_device *hdev = interface_to_usbdev(intf);
 	struct lvs_rh *lvs = usb_get_intfdata(intf);
+	int port;
 	int ret;
 
-	ret = lvs_rh_set_port_feature(hdev, lvs->portnum,
-			USB_PORT_FEAT_BH_PORT_RESET);
+	if (kstrtoint(buf, 0, &port) || port < 1 || port > 255)
+		port = lvs->portnum;
+
+	ret = lvs_rh_set_port_feature(hdev, port, USB_PORT_FEAT_BH_PORT_RESET);
 	if (ret < 0) {
 		dev_err(dev, "can't issue warm reset %d\n", ret);
 		return ret;
@@ -299,10 +302,14 @@
 	struct usb_interface *intf = to_usb_interface(dev);
 	struct usb_device *hdev = interface_to_usbdev(intf);
 	struct lvs_rh *lvs = usb_get_intfdata(intf);
+	int port;
 	int ret;
 
+	if (kstrtoint(buf, 0, &port) || port < 1 || port > 255)
+		port = lvs->portnum;
+
 	ret = lvs_rh_set_port_feature(hdev,
-			lvs->portnum | USB_SS_PORT_LS_COMP_MOD << 3,
+			port | (USB_SS_PORT_LS_COMP_MOD << 3),
 			USB_PORT_FEAT_LINK_STATE);
 	if (ret < 0) {
 		dev_err(dev, "can't enable compliance mode %d\n", ret);