From nobody Wed Apr 8 03:06:10 2026 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40A48391E58 for ; Tue, 10 Mar 2026 22:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773181399; cv=none; b=UQA7ooTSBR+ruo7IKoUygOncEYijRb2uCGLzS2NhU+TlV7PLkriKPhdhNNOg/HLWrz2BJBX2pxetvr6+NqlaccsEO+eDUfN1YghHwtumvdrssDSVqJBOj+rEuNMX7UCNg6dDFGLP7DiKmIjix/dLARodJsb92SAii96m8yukbP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773181399; c=relaxed/simple; bh=2BWLBbJHj6+XBLMk2n+WNRmXU0uVWWkr932TZGVpSBI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=AM/k8tvveGxdPbEPUHC7fF2uRnNxs5ZEICOxGHAkiLgEJhdoYc0C5BE1Dnd3jPsbaf7ybNGfaB/ilPCdBL22xTcqYHPYeTodzgBU+tJDL1KXTKEXwSrKBzksQUVaWECuZlu9vkhwMcR/E3Ar76bOBKn8SipQyh8NMmMLebcxWLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Bq8/b3uQ; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Bq8/b3uQ" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1773181396; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qrP1oGG317mA+DmnsrLL8HVSskRTO5cPeFTQIZYRW64=; b=Bq8/b3uQYv46dsStc8hyVQqvOsg6N/uHtRfPXBtccGryAu73XYQZUXOUedSgWzjNaoyWi5 4MlyrE5AMR/bH756hPXvXwt5IA1dKTMpMYionGkGGng3k3oxLeeEJQq5QhdzgM8eP7OCl/ SW8rXGshaDoJS0W8WI5bEfoaCN+5wJU= From: Sean Anderson To: Laurent Pinchart , Hans de Goede , Ricardo Ribalda , linux-media@vger.kernel.org Cc: Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, Hans Verkuil , Sean Anderson Subject: [PATCH] media: uvcvideo: Fix deadlock if uvc_status_stop is called from async_ctrl.work Date: Tue, 10 Mar 2026 18:22:59 -0400 Message-Id: <20260310222259.1202061-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" If a UVC camera has an asynchronous control, uvc_status_stop may be called from async_ctrl.work: uvc_ctrl_status_event_work() uvc_ctrl_status_event() uvc_ctrl_clear_handle() uvc_pm_put() uvc_status_put() uvc_status_stop() cancel_work_sync() This will cause a deadlock, since cancel_work_sync will wait for uvc_ctrl_status_event_work to complete before returning. Fix this by returning early from uvc_status_stop if we are currently in the work function. flush_status now remains false until uvc_status_start is called again, ensuring that uvc_ctrl_status_event_work won't resubmit the URB. Fixes: a32d9c41bdb8 ("media: uvcvideo: Make power management granular") Closes: https://lore.kernel.org/all/6733bdfb-3e88-479f-8956-ab09c04c433e@li= nux.dev/ Signed-off-by: Sean Anderson Acked-by: Ricardo Ribalda Tested-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_status.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc= _status.c index 231cfee8e7c2c..2a23606c7f4c6 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -316,6 +316,14 @@ static int uvc_status_start(struct uvc_device *dev, gf= p_t flags) if (!dev->int_urb) return 0; =20 + /* + * If the work called uvc_status_stop it may still be running. Wait for + * it to finish before we submit the urb. + */ + cancel_work_sync(&dev->async_ctrl.work); + + /* Clear the flush status if we were previously stopped */ + smp_store_release(&dev->flush_status, false); return usb_submit_urb(dev->int_urb, flags); } =20 @@ -336,6 +344,14 @@ static void uvc_status_stop(struct uvc_device *dev) */ smp_store_release(&dev->flush_status, true); =20 + /* + * We will deadlock if we are currently in the work function. + * Fortunately, we know that the URB is already dead and that no + * further work can be queued, so there's nothing left for us to do. + */ + if (current_work() =3D=3D &w->work) + return; + /* * Cancel any pending asynchronous work. If any status event was queued, * process it synchronously. @@ -354,15 +370,6 @@ static void uvc_status_stop(struct uvc_device *dev) */ if (cancel_work_sync(&w->work)) uvc_ctrl_status_event(w->chain, w->ctrl, w->data); - - /* - * From this point, there are no events on the queue and the status URB - * is dead. No events will be queued until uvc_status_start() is called. - * The barrier is needed to make sure that flush_status is visible to - * uvc_ctrl_status_event_work() when uvc_status_start() will be called - * again. - */ - smp_store_release(&dev->flush_status, false); } =20 int uvc_status_resume(struct uvc_device *dev) --=20 2.35.1.1320.gc452695387.dirty