usbip: vhci-hcd: Clean up the code by adding a new macro
authorYuyang Du <yuyang.du@intel.com>
Thu, 8 Jun 2017 05:04:13 +0000 (13:04 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 13 Jun 2017 08:51:10 +0000 (10:51 +0200)
Each vhci has 2*VHCI_HC_PORTS ports, in which VHCI_HC_PORTS
ports are HighSpeed (or below), and VHCI_HC_PORTS are SuperSpeed.
This new macro VHCI_PORTS reflects this configuration.

Signed-off-by: Yuyang Du <yuyang.du@intel.com>
Acked-by: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/usbip/vhci.h
drivers/usb/usbip/vhci_sysfs.c

index db28eb531e8cc068fd7b87587b0eaa0e1dbb9f22..5cfb59e98e4464b6d78bc5c5eb1195bc61e7c722 100644 (file)
@@ -84,6 +84,9 @@ enum hub_speed {
 #define VHCI_HC_PORTS 8
 #endif
 
+/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
+#define VHCI_PORTS     (VHCI_HC_PORTS*2)
+
 #ifdef CONFIG_USBIP_VHCI_NR_HCS
 #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
 #else
@@ -145,7 +148,7 @@ static inline __u32 port_to_rhport(__u32 port)
 
 static inline int port_to_pdev_nr(__u32 port)
 {
-       return port / (VHCI_HC_PORTS * 2);
+       return port / VHCI_PORTS;
 }
 
 static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
index 3ad68ff4da2d69d61107355544dbd5953f52bba0..5778b640ba9cb46918e7ce6d33288f699cbb6e39 100644 (file)
@@ -92,7 +92,7 @@ static ssize_t status_show_vhci(int pdev_nr, char *out)
 
                spin_lock(&vdev->ud.lock);
                port_show_vhci(&out, HUB_SPEED_HIGH,
-                              pdev_nr * VHCI_HC_PORTS * 2 + i, vdev);
+                              pdev_nr * VHCI_PORTS + i, vdev);
                spin_unlock(&vdev->ud.lock);
        }
 
@@ -101,7 +101,7 @@ static ssize_t status_show_vhci(int pdev_nr, char *out)
 
                spin_lock(&vdev->ud.lock);
                port_show_vhci(&out, HUB_SPEED_SUPER,
-                              pdev_nr * VHCI_HC_PORTS * 2 + VHCI_HC_PORTS + i, vdev);
+                              pdev_nr * VHCI_PORTS + VHCI_HC_PORTS + i, vdev);
                spin_unlock(&vdev->ud.lock);
        }
 
@@ -117,7 +117,7 @@ static ssize_t status_show_not_ready(int pdev_nr, char *out)
 
        for (i = 0; i < VHCI_HC_PORTS; i++) {
                out += sprintf(out, "hs  %04u %03u ",
-                                   (pdev_nr * VHCI_HC_PORTS * 2) + i,
+                                   (pdev_nr * VHCI_PORTS) + i,
                                    VDEV_ST_NOTASSIGNED);
                out += sprintf(out, "000 00000000 0000000000000000 0-0");
                out += sprintf(out, "\n");
@@ -125,7 +125,7 @@ static ssize_t status_show_not_ready(int pdev_nr, char *out)
 
        for (i = 0; i < VHCI_HC_PORTS; i++) {
                out += sprintf(out, "ss  %04u %03u ",
-                                   (pdev_nr * VHCI_HC_PORTS * 2) + VHCI_HC_PORTS + i,
+                                   (pdev_nr * VHCI_PORTS) + VHCI_HC_PORTS + i,
                                    VDEV_ST_NOTASSIGNED);
                out += sprintf(out, "000 00000000 0000000000000000 0-0");
                out += sprintf(out, "\n");
@@ -176,7 +176,7 @@ static ssize_t nports_show(struct device *dev, struct device_attribute *attr,
        /*
         * Half the ports are for SPEED_HIGH and half for SPEED_SUPER, thus the * 2.
         */
-       out += sprintf(out, "%d\n", VHCI_HC_PORTS * vhci_num_controllers * 2);
+       out += sprintf(out, "%d\n", VHCI_PORTS * vhci_num_controllers);
        return out - s;
 }
 static DEVICE_ATTR_RO(nports);