From patchwork Fri Nov 29 19:25:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888922 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BC3C1A254C for ; Fri, 29 Nov 2024 19:25:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908313; cv=none; b=sOC+LHlW7teFeUJr9AO1P+RIRz1erxRJr014PAXYMoHA7fAZOp73jCCWwDg52sG+vrkkEz6waukJ5sTZxc1qvDRZfnyU9Wyw9hJggZyQm3acAnhCXaWhaGML7p8eQG/1KqMlASM0wOIOnX9UUa68Zivw6HGG7EPSlzYcNubhjic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908313; c=relaxed/simple; bh=KDAOGjpXXULpZa75pLl+o8CodfY7IbmICZMYyev2FdU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T/EEnjtkuyZUJEssN1rWLsUMAVhZIrJ6h51VFhrGibpDWB1/hYukHCUIdtgDo5nN4sOi8CDUmDHss+6KzWmfGMmuxvia6HgoTSpLvbHwnzRTuQtEs3wromuuQU4/lUw/SKADyamVDUbEWSbFEgKCOugxp+0v0qivMXsXfYcrPcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=T/vk8ZML; arc=none smtp.client-ip=209.85.219.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="T/vk8ZML" Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6d87a55bc50so11754556d6.3 for ; Fri, 29 Nov 2024 11:25:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732908310; x=1733513110; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DsG2Wx3W9iEMxWqh3g5yUw4V+bP3sc1QbSYtLT8mhKI=; b=T/vk8ZMLG+g6cSw/uloiOmkCDvM8y5KeYGFMRun0KbsM6Z5F6M06LgllDP0n1CzuN9 VM2/1Tp/ffu2oFAdXdyxa6MWewiMvOEpvYqS4BgjFoIu+6yuejQ2871B3Xtvq1k7d5zC Lt/djj0sGnmwyTG0XhIkQOLDz5gdv9g3c3FyA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732908310; x=1733513110; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DsG2Wx3W9iEMxWqh3g5yUw4V+bP3sc1QbSYtLT8mhKI=; b=qe4BFw/Ot3l0AV/GiTpSBT79jCzDLdrZ/W/XSlXW712Zk7QZAuMM5OixkfTPcLEev4 qjdmQXdT9mUBcB2byFDhMUTcfwLS1oBMT+Puqpkj4nSyGRA+3NfOb323AAooeaAwKE3W GGeJu7LVCw367dYe2yXmkx1BddtSRfwl8g8eHSP1hKWOnSfEH0/wCesMqtfiPMfb8w1Z ckobjyZGaRZVFvaObM/TDj1LsJ1zgIfoF5GQ4Pf5xv2BarsBWN8R7A95DIE09AEOXvPK jvqULe7eTpJuukIVht6iUHrqDyVl6VurusDaBmRXjXNm8vDv83rt4ZSkkXsgpFag4jT1 /wgw== X-Forwarded-Encrypted: i=1; AJvYcCV3qXz+uitWRy8f7DpGoFGq3ZkSqCEnKRvrHp4u/c5fFKoBTpFoGlhcsmj+IHMQD4D1zx3UQ1Fe+f/84g==@vger.kernel.org X-Gm-Message-State: AOJu0YxZAYIOahhfxWfPan1GGD0uxn9UQ8GUQKCadJXfGX4QEgJzStpq D1k9lvy/ikumps9j+8rIAi+qsBeACeJ64sJQDnbM7hjvv8oUySixNOdz/Hhjcw== X-Gm-Gg: ASbGncvrpExA7bvjRjF+N99lohjKSbTu30IuY1/PHNhV92QdZAcn5aPCuj84qa5cw1o /VELdavgghoEK1hVaIHK/oFiKojW6l0RvhFWENNVKY/KneMuUA0EInM6XIZJuZo4T62w5a44F05 2WNZ7Ui3BOAJUzxyL9UFm4P7V39daefvos3oAhJhzQGi3UjA6wXMCXIqq7wz01sVHd4a2DLJcT4 G3UQn+wEGSzaGvy9AMJzPQyyWqbevYKrPMb1Xy8JQyBTU4iT1eTuHiHV7VSvxPlUe3NYJzqkrC0 RqIku8K2X5h3baWK1o+Wmkc6 X-Google-Smtp-Source: AGHT+IHWYLjW914nhGcA62UKvuHc86hH3lbm+mb3t304Ztc6ITsE/xyJVsbWU3vwDNxLRMjZMNifvQ== X-Received: by 2002:a05:6214:1d25:b0:6d8:8289:26ac with SMTP id 6a1803df08f44-6d8828927damr78350326d6.45.1732908310529; Fri, 29 Nov 2024 11:25:10 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87d899ec2sm14462146d6.50.2024.11.29.11.25.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 11:25:09 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 19:25:02 +0000 Subject: [PATCH v3 1/4] media: uvcvideo: Do not replace the handler of an async ctrl Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241129-uvc-fix-async-v3-1-ab675ce66db7@chromium.org> References: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@vger.kernel.org X-Mailer: b4 0.13.0 ctrl->handle was used to keep a reference to the last fh that changed an asynchronous control. But what we need instead, is to keep a reference to the originator of an uncompleted operation. We use that handle to filter control events. Under some situations, the originator of an event shall not be notified. In the current implementation, we unconditionally replace the handle pointer, which can result in an invalid notification to the real originator of the operation. Lets fix that. Cc: stable@vger.kernel.org Fixes: e5225c820c05 ("media: uvcvideo: Send a control event when a Control Change interrupt arrives") Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 2 +- drivers/media/usb/uvc/uvcvideo.h | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4fe26e82e3d1..88ef8fdc2be2 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -2046,7 +2046,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, mapping->set(mapping, value, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); - if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) + if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS && !ctrl->handle) ctrl->handle = handle; ctrl->dirty = 1; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 07f9921d83f2..ce688b80e986 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -150,7 +150,10 @@ struct uvc_control { u8 *uvc_data; - struct uvc_fh *handle; /* File handle that last changed the control. */ + struct uvc_fh *handle; /* + * File handle that initially changed the + * async control. + */ }; /* From patchwork Fri Nov 29 19:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888923 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF4CF1A286D for ; Fri, 29 Nov 2024 19:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908314; cv=none; b=FTQBkFsT30stfrUt/ijUXUmJqZt2ePgg7YQb9ktUYYjpfJedTYns+mm/P7AIjPsXuXzep3ZMtc32KHXluM6CVy/2qczVN/KATlCGb6ynE+8LgEqE6akhAHdMYr0exh+NhLBlXN8mggYPgw0TBpZhjouDk5Yeh4IrGUzZB/wz5T8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908314; c=relaxed/simple; bh=Zy1WcuTev5lX3bXIs4fw/TsAuA82ld2oaDvt3MBOS90=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xk1AHJ+Y/+vI/+SfDu4Ps5eVv+id9n5Gx9/geXWZN+V0Z2hreLf7HukMVH9R4nggVAxdQXdJi8CKXwt709MvAXeS/8vgjEhYnEMXA3RGH0oKd0BqtvimyvdEc8CkMCLxnPfLUZHB9h7gNwkWqYLeDJC3WSMsaRb904fJWim2AJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=hk9GHpCA; arc=none smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="hk9GHpCA" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-7b667d2fb9dso123142385a.1 for ; Fri, 29 Nov 2024 11:25:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732908312; x=1733513112; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=oQeQ2KyqHtNBRriL9fVSW5MUmGsZLOcz6c7UY+k+UN0=; b=hk9GHpCAa93ddWHZ1b5JNNxZXsDhBwfn5AXD1sh72MCBtOre/SVB+5bc6Ve9s7pCGK Blbb3ffqY3rzvt8OMdnUg8pb3dsmcrueVCMhV/4/up9s+g5zTtJycbiE3SFog8a3aOuy VUcS/aDpttdPQryxrDEn9HTHNteRFrwmHjKEM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732908312; x=1733513112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oQeQ2KyqHtNBRriL9fVSW5MUmGsZLOcz6c7UY+k+UN0=; b=jEj5CjXPmcoFFwdbOv6GKi09RT1RpBuAiLoq4T7LVv1ZnkUg1JX8qlGb1T1jWX5QQm C3lLEN1cWdO2tk8PllQMaZu/SP4LqA0yfHQT/loBqXUnqENhFE9KZLjbsdz1zArHIrtG 7l6UTDh9MDuix3hxcrItAR2QvMGCP2ROJJXwRRYP/x341GSvQTMMHAX2WvNqQh8RUKxc alU0+mm3EsN/jlvKVwRbTHyoZuWNAyULMJcZUYWArbAu/B+h2RmKaB24AEKw7BtElhtH UJltGBy04WSuhc3hLyUMViQd00I1pDQJbgP4dr9potoFzTkYc8DS1irPIyLdwyfRBsX7 HQRg== X-Forwarded-Encrypted: i=1; AJvYcCU3Uvk8gC93stOAWOIzqPBuuZIS10Qs6fmu/q/97b+ydsD+vcn+Ycpsai+k1mTeHNYRiix7+v56iO2QXw==@vger.kernel.org X-Gm-Message-State: AOJu0YxkOwl8bFhUnl4C+B0jMiiRGMtAWenbJW3yDJfchVZ39EiHeX5h +f/RD326ZpqZoGY8ViYQ/ekSOiDU3kkHLAJDoPgjPfZwm6okxkvCYzuF5iyRbw== X-Gm-Gg: ASbGncseMV9gnZuZ5p65wsulJR8bcsdu7F8Z1D+APRd5SDTZl4f36XxbD7B7bIKrszE fCa3+FGDq5YvvV8wKNtY5Kfh0bhA5pcS2our8RotGdpqbE1gw0Yo/NkuzWS0+WQT6QzcYaoyRps BE7EkKTV2xgTOCehMDAiMUOUqjFFUjGNX7r9IlXKqHjgjrGlwRqe+kebNSZ2BvQVxOhBYDzGd0Z mV/eCQVcBWbdFX0kTl7WLBeiGu45FSJ2jNCy2NQpRlilfiqxA4FYqMRE26e8SpfrztabCo1pzMb V8AiUmv2JFplWYWYCgPhQhLT X-Google-Smtp-Source: AGHT+IGedfeMWQrD0Uy4movxPEueNKjXW4h6eR7BQ7bbYDKwsyyTMfuMQXVM2jydDrBBUQytGq8yqQ== X-Received: by 2002:a05:620a:8013:b0:7af:cfc0:7822 with SMTP id af79cd13be357-7b67c2c2828mr1659490185a.33.1732908311936; Fri, 29 Nov 2024 11:25:11 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87d899ec2sm14462146d6.50.2024.11.29.11.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 11:25:11 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 19:25:03 +0000 Subject: [PATCH v3 2/4] media: uvcvideo: Remove dangling pointers Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241129-uvc-fix-async-v3-2-ab675ce66db7@chromium.org> References: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@vger.kernel.org X-Mailer: b4 0.13.0 When an async control is written, we copy a pointer to the file handle that started the operation. That pointer will be used when the device is done. Which could be anytime in the future. If the user closes that file descriptor, its structure will be freed, and there will be one dangling pointer per pending async control, that the driver will try to use. Clean all the dangling pointers during release(). To avoid adding a performance penalty in the most common case (no async operation), a counter has been introduced with some logic to make sure that it is properly handled. Cc: stable@vger.kernel.org Fixes: e5225c820c05 ("media: uvcvideo: Send a control event when a Control Change interrupt arrives") Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 44 ++++++++++++++++++++++++++++++++++++++-- drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ drivers/media/usb/uvc/uvcvideo.h | 9 +++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 88ef8fdc2be2..0a79a3def017 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1579,6 +1579,23 @@ static void uvc_ctrl_send_slave_event(struct uvc_video_chain *chain, uvc_ctrl_send_event(chain, handle, ctrl, mapping, val, changes); } +static void uvc_ctrl_set_handle(struct uvc_control *ctrl, struct uvc_fh *handle) +{ + /* NOTE: We must own the chain->ctrl_mutex to run this function. */ + + if (handle) { + if (WARN_ON(ctrl->handle)) + return; + handle->pending_async_ctrls++; + ctrl->handle = handle; + } else if (ctrl->handle) { + ctrl->handle = NULL; + if (WARN_ON(!handle->pending_async_ctrls)) + return; + handle->pending_async_ctrls--; + } +} + void uvc_ctrl_status_event(struct uvc_video_chain *chain, struct uvc_control *ctrl, const u8 *data) { @@ -1589,7 +1606,7 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, mutex_lock(&chain->ctrl_mutex); handle = ctrl->handle; - ctrl->handle = NULL; + uvc_ctrl_set_handle(ctrl, NULL); list_for_each_entry(mapping, &ctrl->info.mappings, list) { s32 value = __uvc_ctrl_get_value(mapping, data); @@ -2047,7 +2064,7 @@ int uvc_ctrl_set(struct uvc_fh *handle, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS && !ctrl->handle) - ctrl->handle = handle; + uvc_ctrl_set_handle(ctrl, handle); ctrl->dirty = 1; ctrl->modified = 1; @@ -2770,6 +2787,29 @@ int uvc_ctrl_init_device(struct uvc_device *dev) return 0; } +void uvc_ctrl_cleanup_fh(struct uvc_fh *handle) +{ + struct uvc_entity *entity; + + guard(mutex)(&handle->chain->ctrl_mutex); + + if (!handle->pending_async_ctrls) + return; + + list_for_each_entry(entity, &handle->chain->dev->entities, list) { + for (unsigned int i = 0; i < entity->ncontrols; ++i) { + struct uvc_control *ctrl = &entity->controls[i]; + + if (ctrl->handle != handle) + continue; + + uvc_ctrl_set_handle(ctrl, NULL); + } + } + + WARN_ON(handle->pending_async_ctrls); +} + /* * Cleanup device controls. */ diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 97c5407f6603..b425306a3b8c 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -652,6 +652,8 @@ static int uvc_v4l2_release(struct file *file) uvc_dbg(stream->dev, CALLS, "%s\n", __func__); + uvc_ctrl_cleanup_fh(handle); + /* Only free resources if this is a privileged handle. */ if (uvc_has_privileges(handle)) uvc_queue_release(&stream->queue); diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index ce688b80e986..e0e4f099a210 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -340,7 +340,11 @@ struct uvc_video_chain { struct uvc_entity *processing; /* Processing unit */ struct uvc_entity *selector; /* Selector unit */ - struct mutex ctrl_mutex; /* Protects ctrl.info */ + struct mutex ctrl_mutex; /* + * Protects ctrl.info, + * ctrl.handle and + * uvc_fh.pending_async_ctrls + */ struct v4l2_prio_state prio; /* V4L2 priority state */ u32 caps; /* V4L2 chain-wide caps */ @@ -615,6 +619,7 @@ struct uvc_fh { struct uvc_video_chain *chain; struct uvc_streaming *stream; enum uvc_handle_state state; + unsigned int pending_async_ctrls; }; struct uvc_driver { @@ -800,6 +805,8 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chain, u32 v4l2_id, int uvc_xu_ctrl_query(struct uvc_video_chain *chain, struct uvc_xu_control_query *xqry); +void uvc_ctrl_cleanup_fh(struct uvc_fh *handle); + /* Utility functions */ struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alts, u8 epaddr); From patchwork Fri Nov 29 19:25:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888924 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 064001A3A94 for ; Fri, 29 Nov 2024 19:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908315; cv=none; b=V488/2A5o3ajNXZKoCW2DwM5kYHfFNx5xGIzwiWmVn9seE9ZA9A4R4iMtaYpHVo3wDQtQ5w/LKR67m8p2350mZ4Mptyy3W34o3fu/0gocZ/t4EDwSvoZD+A6lHkOo9RIP90KmJZmyB47M8DmVOOgkmTzIVUefWVSNZF+EqLr4Vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908315; c=relaxed/simple; bh=mTx9kJaioWNO5uqqFbQnJEwHqDWVPPS5kmBz66j5EZ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pCbQqV63xgj+WxDXHXxURYMtSR0YdcxHaGn8BAPP04sAwuMuRWQu8kBDbf+Nj7tSUfifB2VZ1aOzeZGPC40/MNLCCLQvKc7SNWgQj8/P+bruVKV7HjDY2QipRrxLJao8g6UM8Zpa+AVyX5CrUtM6Bl+oG7s5rPooQsTbNlyY2pM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=aBf+X/Bb; arc=none smtp.client-ip=209.85.219.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aBf+X/Bb" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6d87fffeb13so10975356d6.1 for ; Fri, 29 Nov 2024 11:25:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732908313; x=1733513113; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Lc5F8NAtNe3x2vw3Nhwg+vdINmv6+xp/VOBllqqRjXg=; b=aBf+X/BbIT2TBPYOdGMT3WNce3nAk91uPGEa1eSOjtxItwyhmnyzpA81asTyUdYVoR MF9yw609uGMtYkgpsjcfMnrQLxu0zU8KXbBa7gnM0Gsbfcj2tPiwMScxk6of278MNOKb MDWXtw//kOGgY0OiVjGUj17CLF2Q4HlhxO5A8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732908313; x=1733513113; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lc5F8NAtNe3x2vw3Nhwg+vdINmv6+xp/VOBllqqRjXg=; b=V0tD+9U/DQu6KfyKW83gOZHaTLa+vc5CZbDqxCBkAl5Nz6oaZj4ZJ0m9IZMQ+rbGn6 8ypUI7L2utjU+RK85XvoJGtAmhPlFqYiJuBcVGHujW4/T4icTehwafTJxId9LU+XN8ro qQGGGrPCf9IXfYlbV8OXlVj3jus4nitvZaH0gzjPBYLBr6xtfdE3LYtmkFncA4UU9RbI xxOWdxRHk1EKnuEuxSeJ0h68FsF0g0fVu6YzDUVx4XIUZcGziRz2y27BTvym+c7OH5Hi CyILJU+tbyiPEVcyzQUUXMONnxcWNbIiLXADeoseM026CrRB3iSy2bon7ETXU4MA/sOL Hi+w== X-Forwarded-Encrypted: i=1; AJvYcCVEvIhFMaw5kvYib8y6pa9NytLZYB6MqIGPVqU1oA5PBc+qfM4BGHheiCCSo2CQKR2avhDp+6J02J29vg==@vger.kernel.org X-Gm-Message-State: AOJu0YwOnrVb45gEp5fH3Yn8dP9hdfVtF+o/E713jSuyD8N9u3YNCEQm PD40c5B4rO2BMiw3cW7JlkH//wXpKugmtaP2nW/+lmzxzp4TypGn/UYjhBLwtA== X-Gm-Gg: ASbGncuM9CnQ1s1nqSA7QE3dx1wfmMu05nOoPdKTnbfBCkJr2asBcWjYDihgB590eTG /bYnRWGMuwHoIwfUko9uXsNG4j4AT7V/VYulpGBK7+V9SoRx1/h2WvR0F/2CpYbfgawu2xi+DVX yQXcH7Kzm9OTd6aIF673MW5qnzWGfzrRfhQ3yCzS34F/qQ5dwSYtn7Ew4Hib0Yxr5JAeM118if1 xtXgZr8IbpwPeXAM7ZJnSHphUH3PWVW5JtLmVPsEm+ALZV6lgNN5jF/wM5LOwKTHCY2LE99qjZH oGNtPId93zeb/+hGU3cDYhIy X-Google-Smtp-Source: AGHT+IFdLvcLiH4k2Om49MhI8qLceyQxgKY9mTSa5zTIbcimzBKS55ZzkocL0pPO1xLeZHkbghcwGA== X-Received: by 2002:ad4:5aa5:0:b0:6cb:ec71:f1a1 with SMTP id 6a1803df08f44-6d864d44973mr199471616d6.17.1732908313178; Fri, 29 Nov 2024 11:25:13 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87d899ec2sm14462146d6.50.2024.11.29.11.25.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 11:25:12 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 19:25:04 +0000 Subject: [PATCH v3 3/4] media: uvcvideo: Annotate lock requirements for uvc_ctrl_set Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241129-uvc-fix-async-v3-3-ab675ce66db7@chromium.org> References: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 Make it explicit that the function is always called with ctrl_mutex being held. Suggested-by: Laurent Pinchart Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 0a79a3def017..1b58e558604b 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1958,6 +1958,8 @@ int uvc_ctrl_set(struct uvc_fh *handle, s32 max; int ret; + lockdep_assert_held(&chain->ctrl_mutex); + if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >= 0) return -EACCES; From patchwork Fri Nov 29 19:25:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888925 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC93B1A4E77 for ; Fri, 29 Nov 2024 19:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908316; cv=none; b=E/qo03+NrKqKPs74U/0WeopwEHeLONISUeXtEZpPsPg+A5iHPbEbKrQHtHx2RfszIwnFGPqTbO7ftzbSdNQlr7AbevrV3Om2/uOWRjNxheeeO+kO7zlDKSu+xlsai1ygbeI1Wp6256EDiJzYJM6TAzyGfUR/rTqgeg+7Yqc2E+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908316; c=relaxed/simple; bh=XUx4menmu/stFBE7lkIhaln7CdzGv+6pSaMM952p6qE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L7PcU6uhH5+PrOui7iG8TfpK7liIx0GjEoGSw07y7aVzvm0TkTykb9GgpbE0n7E1IedfFkJ80AiUY6cN5EvlXNQKxpSxLRqlJ3gG4bFcM8xqVE6xIq3TiXHpAK/ETSmUexYVf4+BQgEHtRD0CPE6unnBo9DPPnX+8xMzyH/Z02A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=jMOK2cgK; arc=none smtp.client-ip=209.85.219.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jMOK2cgK" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-6d889a1f7a6so3923416d6.2 for ; Fri, 29 Nov 2024 11:25:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732908314; x=1733513114; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6nl7Ezol8cCw5t0X68ApdPTyYZfINMaJDWIUvhxei38=; b=jMOK2cgK1OgEAg333gdphos+z+XIFir0okfHis0x8hV6M/xeXxy/ThdYgq2XESgGjz gFNjEkjNV2jvyLMCGixePiIQQ1eLdZsYsYHh9gzjJ8ETm0r36khHnAgKTtLETs9qthJ7 fN2gk6rbGkjy3BNTg/3GeKsflsCUbhq7D6/iw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732908314; x=1733513114; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6nl7Ezol8cCw5t0X68ApdPTyYZfINMaJDWIUvhxei38=; b=vKvvJlmYcmS1/OP7bqkV0thRsSLbZPLaRynqpC6SwkNTLSTSkjU+vEJkN/fPQq+Oda qT758C+eyJfn8ylCudrShOijVS+e1sFQq8I/UWD6Yn4xnwRpJPh1ppLHJo5ijjavWbd0 vYKFk4c9NaMRC5CX2HDexGIKb+bifQccxi6KNQBCu6XC+fqJFCpicqcqZbhzmdp7vsjj k34tdNCZDRP66IViA6VfaGavudpdeTfaI8R8bU1+VO2E9vaqzqgMXAaZu+17E7nNfvwT eTdGdJxITousBRl/hKklf1TnJVyC2R11uTjMvPGKdfmTYAS0QfE+8Ei/9fKc5paKUF9h Z0Mw== X-Forwarded-Encrypted: i=1; AJvYcCXMDAHKC9M3u9Nh29MGs+sU4DTlgP0R3nSt/fDQXKtzE6SmRuuGg5+o/FVhKY4euDGHMygRHbZoJxBd6g==@vger.kernel.org X-Gm-Message-State: AOJu0YyV/61bqdAyAgE8dh/dwtYdchbtco/rJICuSw4+0QsPB3XY9ml6 4I6d4qOrJKgwTHOjkrd7Q0t91MPE48xGcMI5vuLGh4a9MQhAoQKQa/P/93BGpw== X-Gm-Gg: ASbGncvkfEcYQdcbKSCMJr9KWPo6GO1M6R6kVkayM3gY0S7L75ZwuSzDKG0X3iPTa/v tHx3HFlGEZf8xlhzh8B9dvL1oLcVqIj4CDTVljhR3BRpVNCTro8F7FbFTR99wx2dRmBE5gf97xS 4gJxOAbCiGkVlaCA2Sv+apwOefDBADzPM7FTFcSPKLsZFMpdj47Sq3lUF1jRnh7iiQplJ8EXYzW t8Gcaya0ja0ROh8w8gOn/RUyVvDiV4SxYHzf8eFPprRSkMEhnRT5KCCTrqQdC65X78xtFygjDJe ijzRYh7DPs5DKr9j4ezOtguE X-Google-Smtp-Source: AGHT+IHjqJRktZLhz6NaZh+WfbURnZUbAXxMRHeD7FdgtGCNkYRC+4y7nJMCRQlFRwuCpsM1e0G4OQ== X-Received: by 2002:a0c:b542:0:b0:6d8:81cd:a0ce with SMTP id 6a1803df08f44-6d881cda2damr54003696d6.43.1732908313864; Fri, 29 Nov 2024 11:25:13 -0800 (PST) Received: from denia.c.googlers.com (5.236.236.35.bc.googleusercontent.com. [35.236.236.5]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6d87d899ec2sm14462146d6.50.2024.11.29.11.25.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 11:25:13 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 19:25:05 +0000 Subject: [PATCH v3 4/4] media: uvcvideo: Remove redundant NULL assignment Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241129-uvc-fix-async-v3-4-ab675ce66db7@chromium.org> References: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v3-0-ab675ce66db7@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: Hans Verkuil , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.13.0 ctrl->handle will only be different than NULL for controls that have mappings. This is because that assignment is only done inside uvc_ctrl_set() for mapped controls. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 1b58e558604b..2d984060654c 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1657,10 +1657,8 @@ bool uvc_ctrl_status_event_async(struct urb *urb, struct uvc_video_chain *chain, struct uvc_device *dev = chain->dev; struct uvc_ctrl_work *w = &dev->async_ctrl; - if (list_empty(&ctrl->info.mappings)) { - ctrl->handle = NULL; + if (list_empty(&ctrl->info.mappings)) return false; - } w->data = data; w->urb = urb;