Hi Krzysztof,
On Tue, Apr 04, 2017 at 04:52:32PM +0200, Krzysztof Opasiak wrote:
>
>
> On 03/31/2017 02:28 AM, Yuyang Du wrote:
> >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-by: Krzysztof Opasiak <[email protected]>
> >Signed-off-by: Yuyang Du <[email protected]>
> >---
> > tools/usb/usbip/libsrc/vhci_driver.c | 32 +++++++++++++++++++++++++++++++-
> > tools/usb/usbip/libsrc/vhci_driver.h | 1 +
> > 2 files changed, 32 insertions(+), 1 deletion(-)
> >
> >diff --git a/tools/usb/usbip/libsrc/vhci_driver.c
> >b/tools/usb/usbip/libsrc/vhci_driver.c
> >index f659c14..ccecd47 100644
> >--- a/tools/usb/usbip/libsrc/vhci_driver.c
> >+++ b/tools/usb/usbip/libsrc/vhci_driver.c
> >@@ -7,6 +7,7 @@
> > #include <limits.h>
> > #include <netdb.h>
> > #include <libudev.h>
> >+#include <dirent.h>
> > #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 ? 1: 0;
>
> The ? operator may be omitted here as according to doc we need to
> return nonzero not 1 exactly.
No, it can't. strcmp() would return negative if not containing "vhci_hcd". E.g.,
strcmp("!@#", "vhci_hcd") ==> -1
strcmp("v", "vhci_hcd") ==> -1
> >+
> >+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), &namelist,
> >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.
> > *
> >@@ -220,9 +248,11 @@ int usbip_vhci_driver_open(void)
> > }
> >
> > vhci_driver->nports = get_nports();
> >-
>
> Seems to be unrelated.
>
> > dbg("available ports: %d", vhci_driver->nports);
> >
> >+ vhci_driver->ncontrollers = get_ncontrollers();
>
> shouldn't we check here if we didn't got error from scandir()?
If scandir() failed, we should have (only) printed errors. But yes, both
get_nports() and get_ncontrollers() should check and fail gracefully.
Thanks,
Yuyang
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html