From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=60698 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGFYf-0001OF-2p for qemu-devel@nongnu.org; Wed, 10 Nov 2010 13:38:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGFYd-0007Ix-8O for qemu-devel@nongnu.org; Wed, 10 Nov 2010 13:38:08 -0500 Received: from mail-qy0-f173.google.com ([209.85.216.173]:55762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGFYd-0007Ik-6J for qemu-devel@nongnu.org; Wed, 10 Nov 2010 13:38:07 -0500 Received: by qyl33 with SMTP id 33so3510061qyl.4 for ; Wed, 10 Nov 2010 10:38:06 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1289409261-5418-11-git-send-email-gleb@redhat.com> References: <1289409261-5418-1-git-send-email-gleb@redhat.com> <1289409261-5418-11-git-send-email-gleb@redhat.com> From: Blue Swirl Date: Wed, 10 Nov 2010 18:37:45 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] Re: [PATCHv3 10/14] Add get_dev_path callback for usb bus. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gleb Natapov Cc: alex.williamson@redhat.com, mst@redhat.com, qemu-devel@nongnu.org, kvm@vger.kernel.org, armbru@redhat.com On Wed, Nov 10, 2010 at 5:14 PM, Gleb Natapov wrote: > > Signed-off-by: Gleb Natapov > --- > =C2=A0hw/usb-bus.c | =C2=A0 35 +++++++++++++++++++++++++++++++++++ > =C2=A01 files changed, 35 insertions(+), 0 deletions(-) > > diff --git a/hw/usb-bus.c b/hw/usb-bus.c > index 256b881..6292282 100644 > --- a/hw/usb-bus.c > +++ b/hw/usb-bus.c > @@ -5,11 +5,13 @@ > =C2=A0#include "monitor.h" > > =C2=A0static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int = indent); > +static char *usbbus_get_fw_dev_path(DeviceState *dev); > > =C2=A0static struct BusInfo usb_bus_info =3D { > =C2=A0 =C2=A0 .name =C2=A0 =C2=A0 =C2=A0=3D "USB", > =C2=A0 =C2=A0 .size =C2=A0 =C2=A0 =C2=A0=3D sizeof(USBBus), > =C2=A0 =C2=A0 .print_dev =3D usb_bus_dev_print, > + =C2=A0 =C2=A0.get_fw_dev_path =3D usbbus_get_fw_dev_path, > =C2=A0}; > =C2=A0static int next_usb_bus =3D 0; > =C2=A0static QTAILQ_HEAD(, USBBus) busses =3D QTAILQ_HEAD_INITIALIZER(bus= ses); > @@ -307,3 +309,36 @@ USBDevice *usbdevice_create(const char *cmdline) > =C2=A0 =C2=A0 } > =C2=A0 =C2=A0 return usb->usbdevice_init(params); > =C2=A0} > + > +static int usbbus_get_fw_dev_path_helper(USBDevice *d, USBBus *bus, char= *p, > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 int l= en) > +{ > + =C2=A0 =C2=A0int l =3D 0; > + =C2=A0 =C2=A0USBPort *port; > + > + =C2=A0 =C2=A0QTAILQ_FOREACH(port, &bus->used, next) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (port->dev !=3D d) Braces. > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0continue; > + > + =C2=A0 =C2=A0 =C2=A0 =C2=A0if (port->pdev) { > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0l =3D usbbus_get_fw_dev_path_h= elper(port->pdev, bus, p, len); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0} > + =C2=A0 =C2=A0 =C2=A0 =C2=A0l +=3D snprintf(p + l, len - l, "%s@%x/", qd= ev_fw_name(&d->qdev), > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0port->index); > + =C2=A0 =C2=A0 =C2=A0 =C2=A0return l; > + =C2=A0 =C2=A0} > + =C2=A0 =C2=A0return 0; With this return value... > +} > + > +static char *usbbus_get_fw_dev_path(DeviceState *dev) > +{ > + =C2=A0 =C2=A0USBDevice *d =3D (USBDevice*)dev; > + =C2=A0 =C2=A0USBBus *bus =3D usb_bus_from_device(d); > + =C2=A0 =C2=A0char path[100]; > + =C2=A0 =C2=A0int l; > + > + =C2=A0 =C2=A0l =3D usbbus_get_fw_dev_path_helper(d, bus, path, sizeof(p= ath)); > + =C2=A0 =C2=A0path[l-1] =3D '\0'; ...this statement will have undesirable effects... > + > + =C2=A0 =C2=A0return strdup(path); ...like this.