Re: [PATCH v5 2/4] usb: usbip tool: Add ncontrollers in vhci_driver structure

2017-06-06 Thread Shuah Khan
On 05/22/2017 04:20 AM, Yuyang Du wrote:
> From: Yuyang Du 
> 
> A new field ncontrollers is added to the vhci_driver structure.
> And this field is stored by scanning the vhci_hcd* dirs in the
> platform udev.
> 
> Suggested-and-reviewed-by: Krzysztof Opasiak 
> Signed-off-by: Yuyang Du 

Looks good.

Acked-by: Shuah Khan 

thanks,
-- Shuah

> ---
>  tools/usb/usbip/libsrc/vhci_driver.c | 36 
> 
>  tools/usb/usbip/libsrc/vhci_driver.h |  1 +
>  2 files changed, 37 insertions(+)
> 
> diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
> b/tools/usb/usbip/libsrc/vhci_driver.c
> index 036b62b..f6f3a19 100644
> --- a/tools/usb/usbip/libsrc/vhci_driver.c
> +++ b/tools/usb/usbip/libsrc/vhci_driver.c
> @@ -7,6 +7,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include "sysfs_utils.h"
>  
>  #undef  PROGNAME
> @@ -134,6 +135,33 @@ static int get_nports(void)
>   return (int)strtoul(attr_nports, NULL, 10);
>  }
>  
> +static int vhci_hcd_filter(const struct dirent *dirent)
> +{
> + return strcmp(dirent->d_name, "vhci_hcd") >= 0;
> +}
> +
> +static int get_ncontrollers(void)
> +{
> + struct dirent **namelist;
> + struct udev_device *platform;
> + int n;
> +
> + platform = udev_device_get_parent(vhci_driver->hc_device);
> + if (platform == NULL)
> + return -1;
> +
> + n = scandir(udev_device_get_syspath(platform), , 
> vhci_hcd_filter, NULL);
> + if (n < 0)
> + err("scandir failed");
> + else {
> + for (int i = 0; i < n; i++)
> + free(namelist[i]);
> + free(namelist);
> + }
> +
> + return n;
> +}
> +
>  /*
>   * Read the given port's record.
>   *
> @@ -230,6 +258,14 @@ int usbip_vhci_driver_open(void)
>   goto err;
>   }
>  
> + vhci_driver->ncontrollers = get_ncontrollers();
> + dbg("available controllers: %d", vhci_driver->ncontrollers);
> +
> + if (vhci_driver->ncontrollers <=0) {
> + err("no available usb controllers");
> + goto err;
> + }
> +
>   if (refresh_imported_device_list())
>   goto err;
>  
> diff --git a/tools/usb/usbip/libsrc/vhci_driver.h 
> b/tools/usb/usbip/libsrc/vhci_driver.h
> index fa2316c..33add14 100644
> --- a/tools/usb/usbip/libsrc/vhci_driver.h
> +++ b/tools/usb/usbip/libsrc/vhci_driver.h
> @@ -31,6 +31,7 @@ struct usbip_vhci_driver {
>   /* /sys/devices/platform/vhci_hcd */
>   struct udev_device *hc_device;
>  
> + int ncontrollers;
>   int nports;
>   struct usbip_imported_device idev[MAXNPORT];
>  };
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 2/4] usb: usbip tool: Add ncontrollers in vhci_driver structure

2017-05-22 Thread Yuyang Du
From: Yuyang Du 

A new field ncontrollers is added to the vhci_driver structure.
And this field is stored by scanning the vhci_hcd* dirs in the
platform udev.

Suggested-and-reviewed-by: Krzysztof Opasiak 
Signed-off-by: Yuyang Du 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 36 
 tools/usb/usbip/libsrc/vhci_driver.h |  1 +
 2 files changed, 37 insertions(+)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index 036b62b..f6f3a19 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -7,6 +7,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "sysfs_utils.h"
 
 #undef  PROGNAME
@@ -134,6 +135,33 @@ static int get_nports(void)
return (int)strtoul(attr_nports, NULL, 10);
 }
 
+static int vhci_hcd_filter(const struct dirent *dirent)
+{
+   return strcmp(dirent->d_name, "vhci_hcd") >= 0;
+}
+
+static int get_ncontrollers(void)
+{
+   struct dirent **namelist;
+   struct udev_device *platform;
+   int n;
+
+   platform = udev_device_get_parent(vhci_driver->hc_device);
+   if (platform == NULL)
+   return -1;
+
+   n = scandir(udev_device_get_syspath(platform), , 
vhci_hcd_filter, NULL);
+   if (n < 0)
+   err("scandir failed");
+   else {
+   for (int i = 0; i < n; i++)
+   free(namelist[i]);
+   free(namelist);
+   }
+
+   return n;
+}
+
 /*
  * Read the given port's record.
  *
@@ -230,6 +258,14 @@ int usbip_vhci_driver_open(void)
goto err;
}
 
+   vhci_driver->ncontrollers = get_ncontrollers();
+   dbg("available controllers: %d", vhci_driver->ncontrollers);
+
+   if (vhci_driver->ncontrollers <=0) {
+   err("no available usb controllers");
+   goto err;
+   }
+
if (refresh_imported_device_list())
goto err;
 
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h 
b/tools/usb/usbip/libsrc/vhci_driver.h
index fa2316c..33add14 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -31,6 +31,7 @@ struct usbip_vhci_driver {
/* /sys/devices/platform/vhci_hcd */
struct udev_device *hc_device;
 
+   int ncontrollers;
int nports;
struct usbip_imported_device idev[MAXNPORT];
 };
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html