All of lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: Chunyan Liu <cyliu@suse.com>, xen-devel@lists.xen.org
Cc: wei.liu2@citrix.com, ian.campbell@citrix.com,
	george.dunlap@eu.citrix.com, Ian.Jackson@eu.citrix.com,
	jfehlig@suse.com, Simon Cao <caobosimon@gmail.com>
Subject: Re: [PATCH V5 3/7] libxl: add pvusb API
Date: Thu, 16 Jul 2015 17:01:29 +0200	[thread overview]
Message-ID: <55A7C749.50207@suse.com> (raw)
In-Reply-To: <1435226838-3067-4-git-send-email-cyliu@suse.com>

On 06/25/2015 12:07 PM, Chunyan Liu wrote:
> Add pvusb APIs, including:
>   - attach/detach (create/destroy) virtual usb controller.
>   - attach/detach usb device
>   - list usb controller and usb devices
>   - some other helper functions
>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> Signed-off-by: Simon Cao <caobosimon@gmail.com>

Sorry, found another error: You changed too many format specifiers
from "%d" to "%x":

...

> +static char *usb_busaddr_to_busid(libxl__gc *gc, int bus, int addr)
> +{
> +    libxl_ctx *ctx = CTX;
> +    struct dirent *de;
> +    DIR *dir;
> +    char *busid = NULL;
> +
> +    assert(bus > 0 && addr > 0);
> +
> +    if (!(dir = opendir(SYSFS_USB_DEV)))
> +        return NULL;
> +
> +    while((de = readdir(dir))) {
> +        char *filename;
> +        void *buf;
> +        int busnum = -1;
> +        int devnum = -1;
> +
> +        if (!de->d_name)
> +            continue;
> +
> +        filename = GCSPRINTF(SYSFS_USB_DEV"/%s/devnum", de->d_name);
> +        if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +            sscanf(buf, "%x", &devnum);

That's a decimal number. Use %d, please.

> +
> +        filename = GCSPRINTF(SYSFS_USB_DEV"/%s/busnum", de->d_name);
> +        if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +            sscanf(buf, "%x", &busnum);

Same here.

> +
> +        if (bus == busnum && addr == devnum) {
> +            busid = libxl__strdup(NOGC, de->d_name);
> +            break;
> +        }
> +    }
> +
> +    closedir(dir);
> +    return busid;
> +}
> +
> +static void usb_busaddr_from_busid(libxl__gc *gc, char *busid,
> +                                   int *bus, int *addr)
> +{
> +    libxl_ctx *ctx = CTX;
> +    char *filename;
> +    void *buf;
> +
> +    assert(busid);
> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/busnum", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +        sscanf(buf, "%x", bus);

And here.

> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/devnum", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +        sscanf(buf, "%x", addr);

And here.

> +}

...

> +
> +/* check if USB device type is assignable */
> +static bool is_usb_assignable(libxl__gc *gc, libxl_device_usb *usb)
> +{
> +    libxl_ctx *ctx = CTX;
> +    int classcode;
> +    char *filename;
> +    void *buf = NULL;
> +    char *busid = NULL;
> +
> +    assert(usb->hostbus > 0 && usb->hostaddr > 0);
> +    busid = usb_busaddr_to_busid(gc, usb->hostbus, usb->hostaddr);
> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/bDeviceClass", busid);
> +    if (libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +        return false;
> +
> +    sscanf(buf, "%x", &classcode);

This one, too.

> +    return classcode != USBHUB_CLASS_CODE;
> +}

...

> +int libxl_device_usb_getinfo(libxl_ctx *ctx, libxl_device_usb *usb,
> +                             libxl_usbinfo *usbinfo)
> +{
> +    GC_INIT(ctx);
> +    char *filename;
> +    char *busid;
> +    void *buf = NULL;
> +    int buflen, rc;
> +
> +    usbinfo->ctrl = usb->ctrl;
> +    usbinfo->port = usb->port;
> +
> +    busid = usb_busaddr_to_busid(gc, usb->hostbus, usb->hostaddr);
> +    if (!busid) {
> +        rc = ERROR_FAIL;
> +        goto out;
> +    }
> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/devnum", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +        sscanf(buf, "%x", &usbinfo->devnum);

Again.

> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/busnum", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +        sscanf(buf, "%x", &usbinfo->busnum);

And here.

> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/idVendor", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +        sscanf(buf, "%x", &usbinfo->idVendor);

This one is correct!

> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/idProduct", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, NULL))
> +        sscanf(buf, "%x", &usbinfo->idProduct);

Correct, too.

> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/manufacturer", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, &buflen) &&
> +        buflen > 0) {
> +        /* replace \n to \0 */
> +        if (((char *)buf)[buflen - 1] == '\n')
> +            ((char *)buf)[buflen - 1] = '\0';
> +        usbinfo->manuf = libxl__strdup(NOGC, buf);
> +   }
> +
> +    filename = GCSPRINTF(SYSFS_USB_DEV"/%s/product", busid);
> +    if (!libxl_read_sysfs_file_contents(ctx, filename, &buf, &buflen) &&
> +        buflen > 0) {
> +        /* replace \n to \0 */
> +        if (((char *)buf)[buflen - 1] == '\n')
> +            ((char *)buf)[buflen - 1] = '\0';
> +        usbinfo->prod = libxl__strdup(NOGC, buf);
> +    }
> +
> +    rc = 0;
> +
> +out:
> +    GC_FREE;
> +    return rc;
> +}


Juergen

  parent reply	other threads:[~2015-07-16 15:01 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25 10:07 [PATCH V5 0/7] xen pvusb toolstack work Chunyan Liu
2015-06-25 10:07 ` [PATCH V5 1/7] libxl: export some functions for pvusb use Chunyan Liu
2015-06-25 10:07 ` [PATCH V5 2/7] libxl_read_file_contents: add new entry to read sysfs file Chunyan Liu
2015-06-25 11:09   ` Ian Jackson
2015-06-26  5:47     ` Chun Yan Liu
2015-06-26  5:48     ` Chun Yan Liu
2015-06-26 13:05       ` Ian Jackson
2015-06-29 10:15         ` Chun Yan Liu
2015-06-29 10:52           ` Ian Jackson
2015-06-30  1:43             ` Chun Yan Liu
2015-06-30  9:08               ` Ian Jackson
2015-06-30  9:32                 ` Chun Yan Liu
2015-06-30  9:42                   ` Ian Jackson
2015-06-25 10:07 ` [PATCH V5 3/7] libxl: add pvusb API Chunyan Liu
2015-06-25 11:15   ` Ian Jackson
2015-07-07  1:25   ` Chun Yan Liu
2015-07-07  9:57     ` George Dunlap
2015-08-06  3:11       ` Chun Yan Liu
2015-08-06 17:21         ` George Dunlap
2015-08-07  2:31           ` Chun Yan Liu
2015-08-10 10:08             ` George Dunlap
2015-08-07  7:41           ` Chun Yan Liu
2015-07-16 15:01   ` Juergen Gross [this message]
2015-06-25 10:07 ` [PATCH V5 4/7] libxl: add libxl_device_usb_assignable_list API Chunyan Liu
2015-06-25 10:07 ` [PATCH V5 5/7] xl: add pvusb commands Chunyan Liu
2015-06-25 10:07 ` [PATCH V5 6/7] xl: add usb-assignable-list command Chunyan Liu
2015-06-25 10:07 ` [PATCH V5 7/7] domcreate: support pvusb in configuration file Chunyan Liu
2015-07-13 10:08   ` Juergen Gross
2015-08-06  2:49     ` Chun Yan Liu
2015-07-13 10:09 ` [PATCH V5 0/7] xen pvusb toolstack work Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55A7C749.50207@suse.com \
    --to=jgross@suse.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=caobosimon@gmail.com \
    --cc=cyliu@suse.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=jfehlig@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.