Only call libusb_hotplug_enumerate() once from libusb_hotplug_register_callback().

Else when registering multiple filters the same USB device may appear twice in
the list.

MFC after:	3 days
Sponsored by:	Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2019-06-26 12:04:54 +00:00
parent a41b0ec143
commit a5b24a2b65
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=349410

View file

@ -1,6 +1,6 @@
/* $FreeBSD$ */
/*-
* Copyright (c) 2016 Hans Petter Selasky. All rights reserved.
* Copyright (c) 2016-2019 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -200,6 +200,8 @@ int libusb_hotplug_register_callback(libusb_context *ctx,
HOTPLUG_LOCK(ctx);
if (ctx->hotplug_handler == NO_THREAD) {
libusb_hotplug_enumerate(ctx, &ctx->hotplug_devs);
if (pthread_create(&ctx->hotplug_handler, NULL,
&libusb_hotplug_scan, ctx) != 0)
ctx->hotplug_handler = NO_THREAD;
@ -211,8 +213,6 @@ int libusb_hotplug_register_callback(libusb_context *ctx,
handle->fn = cb_fn;
handle->user_data = user_data;
libusb_hotplug_enumerate(ctx, &ctx->hotplug_devs);
if (flags & LIBUSB_HOTPLUG_ENUMERATE) {
TAILQ_FOREACH(adev, &ctx->hotplug_devs, hotplug_entry) {
if (libusb_hotplug_filter(ctx, handle, adev,