qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 08/18] usb-linux: fix device path aka physical p


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH 08/18] usb-linux: fix device path aka physical port handling
Date: Tue, 17 May 2011 18:38:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Looks like you haven't updated this one for the last round of review,
yet.

Gerd Hoffmann <address@hidden> writes:

> The device path isn't just a number.  It specifies the physical port
> the device is connected to and in case the device is connected via
> usb hub you'll have two numbers there, like this: "5.1".  The first
> specifies the root port where the hub is plugged into, the second
> specifies the port number of the hub where the device is plugged in.
> With multiple hubs chained the string can become longer.
>
> This patch renames devpath to port and makes it a string.   It also
> adapts the sysfs parsing code accordingly.  The "info usbhost" monitor
> command now prints bus number, (os-assigned) device address and physical
> port for each device.

Missing here: document the fix for roots, see [*] below.

> Signed-off-by: Gerd Hoffmann <address@hidden>
> ---
>  usb-linux.c |   38 ++++++++++++++++++++------------------
>  1 files changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/usb-linux.c b/usb-linux.c
> index 84d3a8b..2fa3591 100644
> --- a/usb-linux.c
> +++ b/usb-linux.c
> @@ -54,7 +54,7 @@ struct usb_ctrltransfer {
>      void *data;
>  };
>  
> -typedef int USBScanFunc(void *opaque, int bus_num, int addr, int devpath,
> +typedef int USBScanFunc(void *opaque, int bus_num, int addr, char *port,
>                          int class_id, int vendor_id, int product_id,
>                          const char *product_name, int speed);
>  
> @@ -71,6 +71,7 @@ typedef int USBScanFunc(void *opaque, int bus_num, int 
> addr, int devpath,
>  #define USBPROCBUS_PATH "/proc/bus/usb"
>  #define PRODUCT_NAME_SZ 32
>  #define MAX_ENDPOINTS 15
> +#define MAX_PORTLEN 8

Please change this to 16 to match the kernel.

>  #define USBDEVBUS_PATH "/dev/bus/usb"
>  #define USBSYSBUS_PATH "/sys/bus/usb"
>  
> @@ -123,7 +124,7 @@ typedef struct USBHostDevice {
>      /* Host side address */
>      int bus_num;
>      int addr;
> -    int devpath;
> +    char port[MAX_PORTLEN];
>      struct USBAutoFilter match;
>  
>      QTAILQ_ENTRY(USBHostDevice) next;
> @@ -836,7 +837,7 @@ static int usb_linux_get_configuration(USBHostDevice *s)
>          char device_name[32], line[1024];
>          int configuration;
>  
> -        sprintf(device_name, "%d-%d", s->bus_num, s->devpath);
> +        sprintf(device_name, "%d-%s", s->bus_num, s->port);
>  
>          if (!usb_host_read_file(line, sizeof(line), "bConfigurationValue",
>                                  device_name)) {
> @@ -882,7 +883,7 @@ static uint8_t usb_linux_get_alt_setting(USBHostDevice *s,
>          char device_name[64], line[1024];
>          int alt_setting;
>  
> -        sprintf(device_name, "%d-%d:%d.%d", s->bus_num, s->devpath,
> +        sprintf(device_name, "%d-%s:%d.%d", s->bus_num, s->port,
>                  (int)configuration, (int)interface);
>  
>          if (!usb_host_read_file(line, sizeof(line), "bAlternateSetting",
> @@ -1001,7 +1002,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
>  }
>  
>  static int usb_host_open(USBHostDevice *dev, int bus_num,
> -                         int addr, int devpath, const char *prod_name)
> +                         int addr, char *port, const char *prod_name)
>  {
>      int fd = -1, ret;
>      struct usbdevfs_connectinfo ci;
> @@ -1027,7 +1028,7 @@ static int usb_host_open(USBHostDevice *dev, int 
> bus_num,
>  
>      dev->bus_num = bus_num;
>      dev->addr = addr;
> -    dev->devpath = devpath;
> +    strcpy(dev->port, port);
>      dev->fd = fd;
>  
>      /* read the device description */
> @@ -1401,8 +1402,9 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc 
> *func)
>  {
>      DIR *dir = NULL;
>      char line[1024];
> -    int bus_num, addr, devpath, speed, class_id, product_id, vendor_id;
> +    int bus_num, addr, speed, class_id, product_id, vendor_id;
>      int ret = 0;
> +    char port[MAX_PORTLEN];
>      char product_name[512];
>      struct dirent *de;
>  
> @@ -1418,8 +1420,8 @@ static int usb_host_scan_sys(void *opaque, USBScanFunc 
> *func)
>              if (!strncmp(de->d_name, "usb", 3)) {
>                  tmpstr += 3;
>              }

You wrote "I think this can be zapped now, the new sscanf will fail on
them and skip the entries anyway."  What about it?

> -            if (sscanf(tmpstr, "%d-%d", &bus_num, &devpath) < 1) {
> -                goto the_end;
> +            if (sscanf(tmpstr, "%d-%7[0-9.]", &bus_num, port) < 2) {
> +                continue;
>              }
>  
>              if (!usb_host_read_file(line, sizeof(line), "devnum", 
> de->d_name)) {

[*] Undocumented bug fix here.  Quoting our conversation:

    > The old sscanf() succeeds if at least one item is assigned, i.e. tmpstr
    > starts with an integer.  I suspect this is broken for roots.  Consider
    > d_name "usb1": tmpstr is "1", sscan() returns 1, and devpath remains
    > uninitialized.  It's passed to the func() callback.  Bug?  If yes, the
    > commit message should mention it.

    Indeed.

    > The new sscan() succeeds only if both items are assigned, i.e. tmpstr
    > starts with an integer, '-', and up to 7 of [0-9.].  Unlike the old one,
    > it fails for roots.  Intentional?

    Yes, now the roots are skipped.  You can't assign them anyway, so it
    is pretty pointless to loom at them and to list them in "info
    usbhost".

Were roots ever listed in "info usbhost"?

[...]



reply via email to

[Prev in Thread] Current Thread [Next in Thread]