All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jürgen Groß" <jgross@suse.com>
To: Chunyan Liu <cyliu@suse.com>, xen-devel@lists.xen.org
Cc: george.dunlap@eu.citrix.com, lars.kurth@citrix.com,
	caobosimon@gmail.com, ian.campbell@citrix.com,
	ian.jackson@citrix.com
Subject: Re: [PATCH RFC V2 3/5] libxl: add pvusb API
Date: Tue, 10 Feb 2015 17:01:22 +0100	[thread overview]
Message-ID: <54DA2B52.7060100@suse.com> (raw)
In-Reply-To: <1421656131-19366-4-git-send-email-cyliu@suse.com>

Just found other issues:

On 01/19/2015 09:28 AM, Chunyan Liu wrote:
> Add pvusb APIs, including:
>   - attach/detach (create/destroy) virtual usb controller.
>   - attach/detach usb device
>   - list assignable usb devices in host
>   - some other helper functions
>
> Signed-off-by: Chunyan Liu <cyliu@suse.com>
> Signed-off-by: Simon Cao <caobosimon@gmail.com>
> ---
>   tools/libxl/Makefile         |    2 +-
>   tools/libxl/libxl.c          |    2 +
>   tools/libxl/libxl.h          |   58 ++
>   tools/libxl/libxl_internal.h |    6 +
>   tools/libxl/libxl_usb.c      | 1277 ++++++++++++++++++++++++++++++++++++++++++
>   tools/libxl/libxlu_cfg_y.c   |  464 ++++++++-------
>   tools/libxl/libxlu_cfg_y.h   |   38 +-
>   7 files changed, 1623 insertions(+), 224 deletions(-)
>   create mode 100644 tools/libxl/libxl_usb.c
>
...
> +/*Get usb device information */
> +static int get_usb_devnum (libxl__gc *gc, const char *intf, char *buf)
> +{
> +    char *path;
> +    int rc = 0;
> +    FILE *fd;
> +
> +    path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/devnum", intf);
> +    fd = popen(path, "r");
> +    if (fgets(buf, 512, fd) == NULL || ferror(fd))
> +        rc = -1;
> +    pclose(fd);
> +
> +    return rc;
> +}
> +
> +static int get_usb_busnum(libxl__gc *gc, const char *intf, char *buf)
> +{
> +    char *path;
> +    int rc = 0;
> +    FILE *fd;
> +
> +    path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/busnum", intf);
> +    fd = popen(path, "r");
> +    if (fgets(buf, 512, fd) == NULL || ferror(fd))
> +        rc = -1;
> +    pclose(fd);
> +
> +    return rc;
> +}
> +
> +static int get_usb_idVendor(libxl__gc *gc, const char *intf, char *buf)
> +{
> +    char *path;
> +    int rc = 0;
> +    FILE *fd;
> +
> +    path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/idVendor", intf);
> +    fd = popen(path, "r");
> +    if (fgets(buf, 512, fd) == NULL || ferror(fd))
> +        rc = -1;
> +    pclose(fd);
> +
> +    return rc;
> +}
> +
> +static int get_usb_idProduct(libxl__gc *gc, const char *intf, char *buf)
> +{
> +    char *path;
> +    int rc = 0;
> +    FILE *fd;
> +
> +    path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/idProduct", intf);
> +    fd = popen(path, "r");
> +    if (fgets(buf, 512, fd) == NULL || ferror(fd))
> +        rc = -1;
> +    pclose(fd);
> +
> +    return rc;
> +}
> +
> +static int get_usb_manufacturer(libxl__gc *gc, const char *intf, char *buf)
> +{
> +    char *path;
> +    int rc = 0;
> +    FILE *fd;
> +
> +    path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/manufacturer", intf);

File does not exist in newer kernels (checked 3.16 and 3.19).

> +    fd = popen(path, "r");
> +    if (fgets(buf, 512, fd) == NULL || ferror(fd))
> +        rc = -1;

Another reason not to use popen(): file doesn't exist, but rc = 0.
And buf contains garbage.

> +    pclose(fd);
> +
> +    return rc;
> +}
> +
> +static int get_usb_product(libxl__gc *gc, const char *intf, char *buf)
> +{
> +    char *path;
> +    int rc = 0;
> +    FILE *fd;
> +
> +    path = libxl__sprintf(gc, "cat "SYSFS_USB_DEVS_PATH"/%s/product", intf);

File does not exist in newer kernels (checked 3.16 and 3.19).

> +    fd = popen(path, "r");
> +    if (fgets(buf, 512, fd) == NULL || ferror(fd))
> +        rc = -1;
> +    pclose(fd);
> +
> +    return rc;
> +}
> +
> +int libxl_device_usb_getinfo(libxl_ctx *ctx, char *intf, libxl_usbinfo *usbinfo)
> +{
> +    GC_INIT(ctx);
> +    char buf[512];
> +
> +    if (!get_usb_devnum(gc, intf, buf) )
> +        usbinfo->devnum = atoi(buf);
> +
> +    if ( !get_usb_busnum(gc, intf, buf))
> +        usbinfo->bus = atoi(buf);
> +
> +    if (!get_usb_idVendor(gc, intf, buf) )
> +        usbinfo->idVendor = atoi(buf);

atoi is wrong. idVendor in sysfs is a hex-string.

> +
> +    if (!get_usb_idProduct(gc, intf, buf) )
> +        usbinfo->idProduct  = atoi(buf);

again hex-string.

> +
> +    if (!get_usb_manufacturer(gc, intf, buf) )
> +        usbinfo->manuf = strdup(buf);
> +
> +    if (!get_usb_product(gc, intf, buf) )
> +        usbinfo->prod = strdup(buf);
> +
> +    GC_FREE;
> +    return 0;
> +}

  parent reply	other threads:[~2015-02-10 16:01 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-19  8:28 [PATCH RFC V2 0/5] pvusb toolstack work Chunyan Liu
2015-01-19  8:28 ` [PATCH RFC V2 1/5] libxl: add pvusb definitions Chunyan Liu
2015-03-03 11:10   ` Ian Campbell
2015-03-03 16:45     ` George Dunlap
2015-03-04  7:26     ` Chun Yan Liu
2015-03-04 10:00       ` Ian Campbell
2015-03-04 12:26         ` George Dunlap
2015-03-04 12:33           ` Ian Campbell
2015-03-05  5:04             ` Chun Yan Liu
2015-03-03 17:15   ` George Dunlap
2015-03-04  8:28     ` Chun Yan Liu
2015-03-04 14:41       ` George Dunlap
2015-03-05  6:07         ` Chun Yan Liu
2015-01-19  8:28 ` [PATCH RFC V2 2/5] libxl: export some functions for pvusb use Chunyan Liu
2015-03-03 11:10   ` Ian Campbell
2015-01-19  8:28 ` [PATCH RFC V2 3/5] libxl: add pvusb API Chunyan Liu
2015-01-28 15:54   ` Ian Campbell
2015-01-29  3:24     ` Chun Yan Liu
2015-02-10 10:08   ` Jürgen Groß
2015-02-10 16:01   ` Jürgen Groß [this message]
2015-03-03 11:38   ` Ian Campbell
2015-03-04  7:47     ` Chun Yan Liu
2015-03-06 16:50   ` George Dunlap
2015-03-09  9:39     ` Ian Campbell
2015-03-09 10:17       ` George Dunlap
2015-03-09 10:41         ` Ian Campbell
2015-03-20  9:37     ` Chun Yan Liu
2015-03-17 14:03   ` Juergen Gross
2015-01-19  8:28 ` [PATCH RFC V2 4/5] xl: add pvusb commands Chunyan Liu
2015-02-10  6:25   ` Jürgen Groß
2015-03-03 11:43   ` Ian Campbell
2015-03-04  7:48     ` Chun Yan Liu
2015-03-06 17:25   ` George Dunlap
2015-03-20  9:02     ` Chun Yan Liu
2015-01-19  8:28 ` [PATCH RFC V2 5/5] domcreate: support pvusb in configuration file Chunyan Liu
2015-03-03 11:44   ` Ian Campbell
2015-01-28 15:51 ` [PATCH RFC V2 0/5] pvusb toolstack work Ian Campbell
2015-01-28 16:07   ` Pasi Kärkkäinen
2015-01-28 16:17     ` Ian Campbell
2015-01-29  3:22   ` Chun Yan Liu

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=54DA2B52.7060100@suse.com \
    --to=jgross@suse.com \
    --cc=caobosimon@gmail.com \
    --cc=cyliu@suse.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=lars.kurth@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.