From nobody Mon Jun 22 13:37:00 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gkTl11Wb6z6hCRZ for ; Mon, 22 Jun 2026 13:37:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gkTl0742gz3wGw for ; Mon, 22 Jun 2026 13:37:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782135421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zKPsyhUv7QKjBb6VwRgXnOHF1+C0kY15kQkPsBjgGnA=; b=h+WSPSlOWLsLpZ2KqcaM4NZYbGw3qvLQgMOaNC17a0ryn6cvcE9EBMdERno7LSUne7kVrY JZXdy+V6Ct4ke3azPT6avMokm7PRESV4SjKEiwsog5U0MeMGgsYEUCkFo4ZlOs6yuUoq7r 34LA9uTYAZsPJBHI4C+5mI3zGn0iXi3ztF12LTdusyHfiYoGkXulBwCttm/9DqvA19RNV1 Bk1btkYnWA/kMCRCl0Y9hc73e44kO1b2TllyvPMl78A9p+AZF820Bd7l58Luu2sVk1h3/x gHNf9mh1netEpDk2KOpaIZp7zee7LZd/57YiQhItWpdk+Qxec6Hpu+gPXmvzsA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782135421; a=rsa-sha256; cv=none; b=PzDl4HfON8zPUyexqkmG60MDozBvFOfUlSi9RKucJs/be7VI9foEFBm32Ltp+hddxEzggg qREOAP+CXL3OYl0vDOoTZTeFu3dlFXmTlsbsS5w6DPn/YAixGvW9ny0vZVvHX2F+fTRRtc cDfCaUlzk8MrTQkg7xKq3w1zXB8C5WNqJfqyo7eol5W0yeU1MZfAQPU+MbD1I5j44v8PgW CWYgBny4rnePcmGHCkwDV3FIcrmY9l9E69MoUgAQkwhl+BJC3SCMrFvBIQMhikHyaUTeh4 UU52LugGez73Z4XF3sGFq04aFzw2zhlFw8XtFUioXW0FSfMkiJstn7taOrKa7w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782135421; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zKPsyhUv7QKjBb6VwRgXnOHF1+C0kY15kQkPsBjgGnA=; b=BGmV9Rm26UxXalzBcEaoHKwkA+K9PYLps9ZKYp1ZXA1gxKJi3lrefUe+C+51mUgspLwi5K SyeHVKIT+108tMbZ/pyneLAwZJEPHRUJLIBnSgh2l1ZhrhkcJt3qAG+Ada2ZUn45konPXv icyrf4Qe78R+ZavkT0KyK5ys94TRVQsDPs4iKqmtcN4WW5qCu2KxQqwtJKN6ylN70BxqVY GeGGHOheF2V8AVg/3m/Zpb8LToi3Q8KT5ndq7oXvEgmqzuCsZhI9kFWEHXYdPkecZvSV61 82wKEY65rtXVGGh4+jgmsX5U6BijNJ0F80CsfHUK7/NRYuF97F+Mp+EsTSXIcg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gkTl05PJczqfN for ; Mon, 22 Jun 2026 13:37:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3b4d7 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 22 Jun 2026 13:37:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: ShengYi Hung Subject: git: be95871347a8 - main - libusb: refactor the process of setting option when init the context. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: aokblast X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: be95871347a85f6feac59d036f62182fce847f23 Auto-Submitted: auto-generated Date: Mon, 22 Jun 2026 13:37:00 +0000 Message-Id: <6a393a7c.3b4d7.aea6234@gitrepo.freebsd.org> The branch main has been updated by aokblast: URL: https://cgit.FreeBSD.org/src/commit/?id=be95871347a85f6feac59d036f62182fce847f23 commit be95871347a85f6feac59d036f62182fce847f23 Author: ShengYi Hung AuthorDate: 2025-07-09 09:36:07 +0000 Commit: ShengYi Hung CommitDate: 2026-06-22 13:36:47 +0000 libusb: refactor the process of setting option when init the context. From https://github.com/libusb/libusb/commit/6622f386f52807dac76c8a260c98aa02c311bc93#diff-c1f9bc250077d41456a3e580fca0ddf5d8c25b741bff6d9b9505990a8b70b254R2358. We are able to set all of the option from the init_context. To address this, we modify the process of setting option in init_context to make it be more clear and then adapat libusb_set_option inside to all other option. Reviewed by: adrian Sponsored By: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D51224 --- lib/libusb/libusb.3 | 2 +- lib/libusb/libusb.h | 7 ++----- lib/libusb/libusb10.c | 41 ++++++++++++++++++++++++----------------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/libusb/libusb.3 b/lib/libusb/libusb.3 index 52b83c700571..7b977103eb59 100644 --- a/lib/libusb/libusb.3 +++ b/lib/libusb/libusb.3 @@ -118,7 +118,7 @@ set the option level to the given .Fa value . .It Va LIBUSB_OPTION_USE_USBDK use USBDK as a libusb backend (Windows only) -.It Va LIBUSB_OPTION_NO_DEVICE_DISCOVER +.It Va LIBUSB_OPTION_NO_DEVICE_DISCOVERY disable the USB enumeration. .It Va LIBUSB_OPTION_LOG_CB customize default callback function with diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h index 5f8af0eae6cc..00255291ebd5 100644 --- a/lib/libusb/libusb.h +++ b/lib/libusb/libusb.h @@ -303,11 +303,6 @@ struct libusb_transfer; struct libusb_device_handle; struct libusb_hotplug_callback_handle_struct; -typedef struct libusb_context libusb_context; - -typedef void (*libusb_log_cb)(libusb_context *ctx, enum libusb_log_level, - const char *str); - struct libusb_pollfd { int fd; short events; @@ -330,6 +325,8 @@ struct libusb_init_option { }; typedef struct libusb_context libusb_context; +typedef void (*libusb_log_cb)(libusb_context *ctx, enum libusb_log_level, + const char *str); typedef struct libusb_device libusb_device; typedef struct libusb_device_handle libusb_device_handle; typedef struct libusb_pollfd libusb_pollfd; diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 9c0f4edb9513..c00d8ec8be8b 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -208,6 +208,10 @@ libusb_init_context(libusb_context **context, ctx->devd_pipe = -1; debug = getenv("LIBUSB_DEBUG"); + ctx->log_cb = NULL; + ctx->no_discovery = false; + ctx->debug = LIBUSB_LOG_LEVEL_NONE; + if (debug != NULL) { /* * If LIBUSB_DEBUG is set, we'll honor that first and @@ -227,24 +231,29 @@ libusb_init_context(libusb_context **context, */ ctx->debug = 0; } - } else { - /* - * If the LIBUSB_OPTION_LOG_LEVEL is set, honor that. - */ - for (int i = 0; i != num_options; i++) { - if (option[i].option != LIBUSB_OPTION_LOG_LEVEL) - continue; + } - ctx->debug = (int)option[i].value.ival; - if ((int64_t)ctx->debug == option[i].value.ival) { - ctx->debug_fixed = 1; - } else { - free(ctx); - return (LIBUSB_ERROR_INVALID_PARAM); - } - } + /* + * Set the default from default context then override by options + */ + if (usbi_default_context) { + CTX_LOCK(usbi_default_context); + if (usbi_default_context->no_discovery) + libusb_set_option(ctx, + LIBUSB_OPTION_NO_DEVICE_DISCOVERY); + /* libusb_set_option will check if debug is fixed by the + environment variable. If it is fixed, the override will not + take effect */ + libusb_set_option(ctx, LIBUSB_OPTION_LOG_LEVEL, + usbi_default_context->debug); + libusb_set_option(ctx, LIBUSB_OPTION_LOG_CB, + usbi_default_context->log_cb); + CTX_UNLOCK(usbi_default_context); } + for (int i = 0; i < num_options; i++) + libusb_set_option(ctx, option[i].option, option[i].value); + TAILQ_INIT(&ctx->pollfds); TAILQ_INIT(&ctx->tr_done); TAILQ_INIT(&ctx->hotplug_cbh); @@ -294,8 +303,6 @@ libusb_init_context(libusb_context **context, } libusb10_add_pollfd(ctx, &ctx->ctx_poll, NULL, ctx->event, POLLIN); - ctx->log_cb = NULL; - ctx->no_discovery = false; pthread_mutex_lock(&default_context_lock); if (usbi_default_context == NULL) {