[Spice-devel] [spice-gtk v2 5/9] usb-redir: cosmetic changes in hotplug_callback
Yuri Benditovich
yuri.benditovich at daynix.com
Tue Jul 23 07:40:47 UTC 2019
Sorry, this is a typo in the comment - should be unexpected condition,
i.e. exactly the bug in the code
On Tue, Jul 23, 2019 at 10:33 AM Frediano Ziglio <fziglio at redhat.com> wrote:
>
> >
> > 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 at daynix.com>
> > ---
> > 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
More information about the Spice-devel
mailing list