From nobody Tue Jan 07 09:03:08 2025 X-Original-To: dev-commits-src-branches@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 4YS4p50r61z5kCxp; Tue, 07 Jan 2025 09:03:09 +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 4YS4p508YFz4tnq; Tue, 7 Jan 2025 09:03:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736240589; 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=ISvK5WdNHdoK+vTPtTMBRfDEWOQv38xlFwtlbBKe1Ck=; b=HfyTB0JxaDmsLksRxWFgCocECgZUwBnfpdnGZquE/YV0PUBJr8GR+tiun/45ZfPaB/QzKS tvNfl0fDmVrn1hWe/1HmSgqWwVTTW4z+bpnglEUlvqQZhC3GX81F6ittV1AZ50EWmRcz9P 1/VA3nmvEgDb/K6pdDV1eYF9KRZQ4Vk3rQa9ekPbo5GuSgSaeEFr/dv+hVRIkxQeOinyGo fOqs8HPEe9BIGvtJuszPc7Z2Zx0f9v5/HB4NFeMJIMHSpV1KrjC5IlUeympBID9TLNlTlW r/lKMmLU++jD0jxBwwg1gNPaRNHJzBoe/MUc8LQoIBGZN2/71o4icilkdpWnSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736240589; 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=ISvK5WdNHdoK+vTPtTMBRfDEWOQv38xlFwtlbBKe1Ck=; b=vHRABed63FRVgBJ3UQOEEfqG5HZY6PF4PzM+dhADFAi6usfxaWPJDHA6t3Z/56wD4qd5dY 3pkT3mFsEa5+4JRCGgqyayw2BwZKei2CdsaMppTLEVpvcYiTy9HltLg4+9pJS0vfgZLsxy v7xaRSYXUHhvAbPc6VmRtorBJ8jj/XALvqBmKlDHmzlMF0b2PNj8wDHNVaSFFwOmY9gYAA 80U7wPbhH0lG5NLKButyozAKwr3e7UZaDqlE3b4O60BvEYoSaAZBNQgqRZLROWWX9l7Bnh MD7sA6kCGJesJ/AKkUpcgomVqgGWt2sOtueMyNoJOI29pVQwLpH2NgXkwOJuog== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736240589; a=rsa-sha256; cv=none; b=besshIPByNgoEOqmytHuO4jFVAdbJUj6e52rQj9GvGtf4Oq+sXKzl78Rr3+cKBDsaPeEC5 zK+1KalNDAaLzNpshTrKSetmNW6/vGPotGiS72GZ8070FUMQInx7P5P26scnJBn6AWKHaZ XlxUB3rgn1vOZS7hP53kavtzxUk7hYrRK1TfaRsLCMeFpi1W2PRxhDhXFoCUP4scfn0XOh 1BqPeuAI4gcmWZX1mykPYHZxMO9b89FYQVPmeHDVfHSeKMlUgF8VmilgMv6MzFqWRgHQB/ /Ieswf5B/dtZa38ooE2Ru7Kk46mbpLk2ah69B8Nm1HZHZov9NqsGAIIbAErDkA== 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 4YS4p46XXSz13HL; Tue, 07 Jan 2025 09:03:08 +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 5079385Y097056; Tue, 7 Jan 2025 09:03:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 507938Vn097053; Tue, 7 Jan 2025 09:03:08 GMT (envelope-from git) Date: Tue, 7 Jan 2025 09:03:08 GMT Message-Id: <202501070903.507938Vn097053@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: 58734b18794b - stable/14 - libusb: fix hotplug sigbus List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/14 X-Git-Reftype: branch X-Git-Commit: 58734b18794b772a2f964bf08863808680f0c81a Auto-Submitted: auto-generated The branch stable/14 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=58734b18794b772a2f964bf08863808680f0c81a commit 58734b18794b772a2f964bf08863808680f0c81a Author: Baptiste Daroussin AuthorDate: 2025-01-03 09:50:30 +0000 Commit: Baptiste Daroussin CommitDate: 2025-01-07 09:02:57 +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 */