Re: [spice-gtk v2 5/9] usb-redir: cosmetic changes in hotplug_callback

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

 



> 
> Unify parameter name for libusb_device.
> Use g_return_val_if_fail for expected condition.

See https://developer.gnome.org/glib/stable/glib-Warnings-and-Assertions.html#g-return-val-if-fail
g_return_val_if_fail represents a bug in the code, not an "expected condition".

> Remove redundant casting.
> 
> Signed-off-by: Yuri Benditovich <yuri.benditovich@xxxxxxxxxx>
> ---
>  src/usb-backend.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/src/usb-backend.c b/src/usb-backend.c
> index 53ac430..e837579 100644
> --- a/src/usb-backend.c
> +++ b/src/usb-backend.c
> @@ -108,21 +108,22 @@ static SpiceUsbBackendDevice
> *allocate_backend_device(libusb_device *libdev)
>  }
>  
>  static int LIBUSB_CALL hotplug_callback(libusb_context *ctx,
> -                                        libusb_device *device,
> +                                        libusb_device *libdev,
>                                          libusb_hotplug_event event,
>                                          void *user_data)
>  {
> -    SpiceUsbBackend *be = (SpiceUsbBackend *)user_data;
> -    if (be->hotplug_callback) {
> -        SpiceUsbBackendDevice *dev;
> -        gboolean val = event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
> -        dev = allocate_backend_device(device);
> -        if (dev) {
> -            SPICE_DEBUG("created dev %p, usblib dev %p", dev, device);
> -            libusb_ref_device(device);
> -            be->hotplug_callback(be->hotplug_user_data, dev, val);
> -            spice_usb_backend_device_unref(dev);
> -        }
> +    SpiceUsbBackend *be = user_data;
> +    SpiceUsbBackendDevice *dev;
> +    gboolean arrived = event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
> +
> +    g_return_val_if_fail(be->hotplug_callback != NULL, 0);
> +
> +    dev = allocate_backend_device(libdev);
> +    if (dev) {
> +        SPICE_DEBUG("created dev %p, usblib dev %p", dev, libdev);
> +        libusb_ref_device(libdev);
> +        be->hotplug_callback(be->hotplug_user_data, dev, arrived);
> +        spice_usb_backend_device_unref(dev);
>      }
>      return 0;
>  }

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]