From nobody Tue Jan 07 09:03:29 2025 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 4YS4pT63lpz5kCmt; Tue, 07 Jan 2025 09:03:29 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YS4pT4mlkz4vJM; Tue, 7 Jan 2025 09:03:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736240609; 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=v2LAVu4sn6XOHpNP/h6L47cjqWvruGBn10Vhr2ACg54=; b=DlvZXns190afdP36C9nILZfG4MIIkB5tfYlnSI+m9jeOfyOd0D80f0f/E//IdHIyiUgewz AWTGg+5D8IxHLc7kQzt+U6HeQBHe5OHnTQ4gYy35xqDhOrFgl2EP8RelQZL0nbNgh2vxY1 yg/DBznDWLA+Kq4yynyWRgGevPiNC35l34KeSdQ3SIWVxMGypm5ax3gj5y6FUmVt12t3el O2GOZGZjk7bBisg+wvy8zhloQUjZlUe+mqk4VGtOWnN/eX1nHADadxwNsFMzbWFBH0wOlA pwGvQrS1OaDPiNo7pSm7Dff/KMva0rhq/Dy2J6ICtFpTjQYReHK/arqNo1oImQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736240609; 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=v2LAVu4sn6XOHpNP/h6L47cjqWvruGBn10Vhr2ACg54=; b=BgGCEKMgKV5Q8Z2m+CKjsqz1NLBjfARC50YwYl6RpEEbuWAT82E+91flJ36SEzTqqsYzmh GvmSuLrKi84hz9JZVK4d0HhtmPb32nw3j/nFgQKHfJmoqbjY5fj/24kdSA7IPw80QPz3na I1ahVLCMOnTXalYj+k1w9UBT544aAAfcZZYYxmQZ7dAz53mltP69HUp/O5TX9lIleFzQxi bjpV/prffxGmr556GhRyIaexBbMvH5xMwePPAbtb7Kkwi+aIcAywfkek6YFzg48gkCpT+e KdZxQ+sHXkcbSbi/WCsBASWaMyeeMt7SeS1F3j1tTIgWjmbrb1I70WEmNwE8jw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736240609; a=rsa-sha256; cv=none; b=k8POy8cIHzCOXgddBkOOC9tfX9jIGlv82L5dtS+W1yR8vJzHsn5F9G/yRGYQ98MInAMwi8 Y+d79YkXkPoV75P6aLSldBWJFmi3M1eYLWwbQHr9U8ZBN78oyE19ztw001bkRzhruy7b3x YiQSdqLqgkWRKLMLf4RSfGlUV00A7KmieJGjH9qqkZVPq1nht71OBJQboVy5N+FYIg1HJU iAXsp1EyUhE8/UOf9GtLk3FUdNcVuhY+e8b/2vzO0/QvIi2/LdVHCp+XKofCdrTjjXITdu 7E0Zmj7c99NEQHgd8VrFmGeKWEfaPMg+SnoScCMWgHcHOGhkUeePh0vXbY6eBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YS4pT3W3Zz13Z6; Tue, 07 Jan 2025 09:03:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50793TN6097265; Tue, 7 Jan 2025 09:03:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50793T5n097262; Tue, 7 Jan 2025 09:03:29 GMT (envelope-from git) Date: Tue, 7 Jan 2025 09:03:29 GMT Message-Id: <202501070903.50793T5n097262@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: eb9fa4c2d786 - stable/13 - libusb: fix hotplug sigbus 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 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: eb9fa4c2d786b327bb4d9bd7727428c70a33c710 Auto-Submitted: auto-generated The branch stable/13 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=eb9fa4c2d786b327bb4d9bd7727428c70a33c710 commit eb9fa4c2d786b327bb4d9bd7727428c70a33c710 Author: Baptiste Daroussin AuthorDate: 2025-01-03 09:50:30 +0000 Commit: Baptiste Daroussin CommitDate: 2025-01-07 09:03:21 +0000 libusb: fix hotplug sigbus When a hotplug callback has been registered, and the program using libusb is calling libusb_exit then the thread handler is set to NO_THREAD which result in the variable controlling the loop the be set to 0, it does a last pass through device available without having done a scan, which result in a sigbus after it tried to unregister all the devices. directly break the loop instead and cleanup the list of devices this fixes the tests with LGPLed libusb's hotplugtest program MFC After: 3 days Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D48298 (cherry picked from commit ba5834b8e11fd002a663d083a464e397e76cb3a9) --- lib/libusb/libusb10_hotplug.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/libusb/libusb10_hotplug.c b/lib/libusb/libusb10_hotplug.c index 9d00b1dbe5a0..98903686f76b 100644 --- a/lib/libusb/libusb10_hotplug.c +++ b/lib/libusb/libusb10_hotplug.c @@ -112,22 +112,25 @@ libusb_hotplug_scan(void *arg) libusb_device *temp; libusb_device *adev; libusb_device *bdev; - unsigned do_loop = 1; - while (do_loop) { + for (;;) { usleep(4000000); HOTPLUG_LOCK(ctx); + if (ctx->hotplug_handler == NO_THREAD) { + while ((adev = TAILQ_FIRST(&ctx->hotplug_devs)) != NULL) { + TAILQ_REMOVE(&ctx->hotplug_devs, adev, hotplug_entry); + libusb_unref_device(adev); + } + HOTPLUG_UNLOCK(ctx); + break; + } TAILQ_INIT(&hotplug_devs); - if (ctx->hotplug_handler != NO_THREAD) { - if (libusb_hotplug_enumerate(ctx, &hotplug_devs) < 0) { - HOTPLUG_UNLOCK(ctx); - continue; - } - } else { - do_loop = 0; + if (libusb_hotplug_enumerate(ctx, &hotplug_devs) < 0) { + HOTPLUG_UNLOCK(ctx); + continue; } /* figure out which devices are gone */