From nobody Wed Jul 22 15:12:50 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 4h4yRl3z6fz6mFRP for ; Wed, 22 Jul 2026 15:12:51 +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 4h4yRl1FFWz3kjt for ; Wed, 22 Jul 2026 15:12:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1784733171; 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=/EzOBE6ldS2IOyLlxurn00P/+uyu+j0mkyLmdxP3YBc=; b=bIRjhrPHbkRjI8twxRevHVmRaGVRFVpX337XLcg8vRH4CS7ivASI7ueNPq+T35dT7n7hF4 BqC2Zy7v+FG08+Xo+k1sxPUPCWJschzN1DVdA3zyx9JiS7oJMcKJ6x93CfKk1f1m2mExtJ 5TTVsejBWBVq6JQWJIUywZAOiv0Yp1QZrZVzmHBmFo/yj8MbGLdeA5yiuhcc6DHgVB7RZI tWmnFur35U3PVk2PQIhvcGJEqmUq1ytIE0bl0j9M/TA6QXwSxnrSSf5vpWrvZo8o76Bh0t vrEQ2vFUaXm5r249K0Jhw33mawg8zIwewSKC4wQunmGA+xGbdE3deL+1uAxizQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1784733171; a=rsa-sha256; cv=none; b=rGDf8ker3h/WQkAQGr92uzVBwz4+/BkydCcuwIH2sWMDs5F7WJvkDazggbkXp9/gch5Tqs TiPw0Ha8LRYMZji2TT1SR5gNlEvonrvYem5VfWZ8S658cocL9CI478v0rhNQziWwQyUKsa 9aOk1ZCmWaWqu0tY9Dcw6SsWIQtRty/GGrfgsmcKrMiXnY4E4um5ByCkN1A1R/B6k6I/5J OZwzARbGVeNoqUrrgjk2JhB30tA6Nywz10B3vy8yiznMh15Kg3iq4i2ucGpqbLLs9LHEqB kN+3HmNhzoq3/cHL4j92aw3JZvyVcBFyL8tDklMB9RFCQHVoltqtzTLZKCEK0Q== 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=1784733171; 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=/EzOBE6ldS2IOyLlxurn00P/+uyu+j0mkyLmdxP3YBc=; b=xtZEufrD73iO185+JwQm6bvIQnOcVVPoZuAHVyXRQg0thEKETUb2ZxppPA9mwRwNCssrmV sai5pDVBd3m0t012fFokDyrv/365gQ5q6ceEAS5sLss2JcjbVQIje4pAQ2KuUXXNV/H4Tl /tiykHlUsJZMnE1KL0jHBSxxTHui/Jb+yB7F2I0f0a3XPDVQ9ajcBdI3nvWlWU3IiPcG+5 9VB94eHSNoNMf/tWXftuXHhmyJtGrPlQrba0aruXZ86ImPvimw8mPlYJOkS0KRxkXOQq7P GywWS1MI0papVrs3D9//quODYejYRyYALt+9fSj8N1zlb3udwoKzVMb0Wmj4nw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4h4yRk6ZSyz840 for ; Wed, 22 Jul 2026 15:12:50 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 33f9c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 22 Jul 2026 15:12:50 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 12b4a02bd881 - main - uvideo: fix close/detach race on streaming teardown 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: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 12b4a02bd88117b07f3e142af71b70bade4fd57e Auto-Submitted: auto-generated Date: Wed, 22 Jul 2026 15:12:50 +0000 Message-Id: <6a60ddf2.33f9c.710b3d4a@gitrepo.freebsd.org> The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=12b4a02bd88117b07f3e142af71b70bade4fd57e commit 12b4a02bd88117b07f3e142af71b70bade4fd57e Author: Baptiste Daroussin AuthorDate: 2026-07-22 08:18:23 +0000 Commit: Baptiste Daroussin CommitDate: 2026-07-22 15:10:58 +0000 uvideo: fix close/detach race on streaming teardown detach() stopped streaming and called uvideo_vs_close() before destroy_dev(), so a concurrent close() could race the teardown and call uvideo_vs_close() a second time (double usbd_transfer_unsetup), and mtx_destroy() could race a close still holding sc_mtx. sc_streaming was also read without the lock in both paths. Reorder detach() to call destroy_dev() first so all in-flight cdev methods drain before any teardown. Read sc_streaming under sc_mtx in both detach() and the last-close safety net. --- sys/dev/usb/video/uvideo.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sys/dev/usb/video/uvideo.c b/sys/dev/usb/video/uvideo.c index bfcd6696a8e0..57d31d2b5286 100644 --- a/sys/dev/usb/video/uvideo.c +++ b/sys/dev/usb/video/uvideo.c @@ -960,21 +960,20 @@ uvideo_detach(device_t dev) sc->sc_dying = 1; - /* Stop any active streaming */ - if (sc->sc_streaming) { - mtx_lock(&sc->sc_mtx); - sc->sc_streaming = 0; - mtx_unlock(&sc->sc_mtx); - uvideo_vs_close(sc); - } - /* Destroy character device */ if (sc->sc_cdev != NULL) { destroy_dev(sc->sc_cdev); sc->sc_cdev = NULL; } - /* Unit number is implicitly freed when the cdev is destroyed */ + /* Stop streaming if still active (e.g. detached while idle). */ + mtx_lock(&sc->sc_mtx); + if (sc->sc_streaming) { + sc->sc_streaming = 0; + mtx_unlock(&sc->sc_mtx); + uvideo_vs_close(sc); + } else + mtx_unlock(&sc->sc_mtx); /* Free frame buffers */ uvideo_vs_free_frame(sc); @@ -2911,12 +2910,13 @@ uvideo_cdev_close(struct cdev *dev, int flags, int fmt, struct thread *td) mtx_unlock(&sc->sc_mtx); /* Last close: stop streaming if still active (safety net) */ + mtx_lock(&sc->sc_mtx); if (sc->sc_streaming) { - mtx_lock(&sc->sc_mtx); sc->sc_streaming = 0; mtx_unlock(&sc->sc_mtx); uvideo_vs_close(sc); - } + } else + mtx_unlock(&sc->sc_mtx); uvideo_vs_free_frame(sc);