[Spice-devel] [spice-gtk 09/13] win-usb-dev: do not allocate memory for hub devices

Christophe Fergeau cfergeau at redhat.com
Tue Mar 12 14:11:36 UTC 2019


On Sun, Mar 10, 2019 at 04:46:08PM +0200, Yuri Benditovich wrote:
> When processing list of USB devices, avoid allocating memory
> for devices which later will be skipped. Use existing libusb
> struct first to check whether the device shall be excluded.

I probably would reword the short log
"win-usb-dev: do not allocate memory for hub devices"
-> "win-usb-dev: skip hub devices early in g_udev_client_list_devices"

> -static gboolean g_udev_skip_search(GUdevDevice *udev)
> +static gboolean g_udev_skip_search(libusb_device *dev)
>  {
> -    GUdevDeviceInfo* udevinfo;
>      gboolean skip;
> +    uint8_t addr  = libusb_get_device_address(dev);
> +    struct libusb_device_descriptor desc;
>  
> -    g_return_val_if_fail(G_UDEV_DEVICE(udev), FALSE);
> -
> -    udevinfo = udev->priv->udevinfo;
> -    g_return_val_if_fail(udevinfo != NULL, FALSE);
> +    libusb_get_device_descriptor(dev, &desc);

Do you know if these
libusb_get_device_descriptor/libusb_get_device_address are going to be
expensive compared to using cached values?

>  
> -    skip = ((udevinfo->addr == 0xff) ||  /* root hub (HCD) */
> +    skip = ((addr == 0xff) ||  /* root hub (HCD) */
>  #if defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x010000FF)
> -            (udevinfo->addr == 1) || /* root hub addr for libusbx >= 1.0.13 */
> +            (addr == 1) || /* root hub addr for libusbx >= 1.0.13 */

Note for later: I'm not sure this still needs to be conditional as we
depend on libusb 1.0.16 now.

Looks good otherwise,

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20190312/7288cc59/attachment.sig>


More information about the Spice-devel mailing list