From nobody Sat Jan 04 10:21:45 2025 X-Original-To: dev-commits-src-main@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 4YQGhB0ZSrz5k488; Sat, 04 Jan 2025 10:21:46 +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 4YQGhB01X8z44np; Sat, 4 Jan 2025 10:21:46 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735986106; 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=TOFJ4B8ftXAHyS7YGm2q1gICuBz3kC6CVvYEbhG/hpk=; b=uwzUkVA46ZjQ45/ToI5ZhJ/3EJ6Snr1vrQOVznLlYpmZwSrzHEfHCg0e9qhwSaPjMwJ+si nmjkNLPlNEe4EevWA+hLi8UASCTFj6FCz4P9gcHQ8MzU6nn4nkTSlM8Kh4E414keaQvZoi ++dvUV1z+1ADO5r63xB5cmgPs+4CFZGDVQsWsKxsd/525OqCixZt1w6ABL36jLAxhLEX5I uVLEy2vydUiiQnyjUJI+Uo+/h1qD28UDCj198PzEDMU8Eu6zXKfPv+vu3xim8Na83QrXjM IlxT2FXhLrDKLSNsqX7L9OOrvEZ3GKlPMcuz+UOHC4vNCfxMqzguGK7pVHgsRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1735986106; 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=TOFJ4B8ftXAHyS7YGm2q1gICuBz3kC6CVvYEbhG/hpk=; b=BgxQVwOaTA/to/Qt0WTakDMZ8Xmo9zwvA2nzfappRioJlbe+PF5WLyKQHcf9Z/KFluJH9C pDDkyJytwtPTmX1/MVDaDhvj5PIti2zA0IMh8K3SpSmBGF9uK8G3wXagKIkbJ/6PE+Z5Yx KsicXOxtyvpHxRYoZ8f+SalnQGQnX7KQbsSfG9EoFU/W4PPy/pGLstvLYJ5Re+n9Co2ZkD avztHc8wS0Ec3HZegWJkRJ74ffbMUdELKlUNdTX5uD/CSZkvdtM01c7kHrfzhQY1E4qWLv Kfy74xQciPjA/s5dmnw2Gm3sSHcszP3FDPv4b37iJiuBhszQcldLUZy6ZSyRSA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1735986106; a=rsa-sha256; cv=none; b=ukuDbcxtzlNtQqLA8xCTtR+btwHQoWeG0wUUIIkqgxSNLakA8JmkGKcR5taQcGLYghf/L5 UzQDoQNGsjGIvogBMbfg1cw8OpxB2na6gXDNbx3Q4cOedx97hpzTTj60OXwbt0NKDUYSvp +7ihIrQeuwsNGlWqiXAuZL6iiO2BlSd4mA+pxz8fnOFVfBd7v8p/rs5sPbVFf0PUb9YwKm 4DbtIn8d4+tg9pwYDeIaMTQc7MfxtHMK/rhR+AhE+7LQ/F38BvRqUZAr7tRy+h6oL7Rcl6 IF4VjjbYLWStqg1KW5Ef4AWVtaeySID0+M6IDkUiaeAhgMTsMeKtuMx+VIIBHg== 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 4YQGh96X39zp0k; Sat, 04 Jan 2025 10:21:45 +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 504ALjAn054616; Sat, 4 Jan 2025 10:21:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 504ALjCD054613; Sat, 4 Jan 2025 10:21:45 GMT (envelope-from git) Date: Sat, 4 Jan 2025 10:21:45 GMT Message-Id: <202501041021.504ALjCD054613@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: ba5834b8e11f - main - libusb: fix hotplug sigbus List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ba5834b8e11fd002a663d083a464e397e76cb3a9 Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=ba5834b8e11fd002a663d083a464e397e76cb3a9 commit ba5834b8e11fd002a663d083a464e397e76cb3a9 Author: Baptiste Daroussin AuthorDate: 2025-01-03 09:50:30 +0000 Commit: Baptiste Daroussin CommitDate: 2025-01-04 10:20:49 +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 --- 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 */