From patchwork Fri Nov 29 21:30:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888943 Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (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 4E0B23224 for ; Fri, 29 Nov 2024 21:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915830; cv=none; b=TnPK0ijsThyy4JyT97NE6bHNePiIUiMFeumWCFNJwimsKxCXLi+mwP0s4a5LatUNipZicOvNAQWE4G+wY4Mksr1BQNsxS8gx3lAZ0r0GbBUJMIu4d6kL48O/VYVB9ZAstLjF64qO30cYiNZR9lk2EhAxeROou7RyRTNLWKMAW/Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915830; c=relaxed/simple; bh=KDAOGjpXXULpZa75pLl+o8CodfY7IbmICZMYyev2FdU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ozSKlbrDJNyHnN24HIgllH16yCacEVBlQlCw1k3mFi5Avlc1dR63Tprr3XSqsKqYco7EIaeJ+jGNV0FmrWuuldU1HnXB0hOoAHUcfP27VNlyIdVHkeefE0cuiZcyCCl2K3p/NFqWgoErraQUXwWWGNkj2JMAa4O9mJeRNCwAliw= 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=NaYQzduX; arc=none smtp.client-ip=209.85.221.180 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="NaYQzduX" Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-51533f41ce1so619091e0c.1 for ; Fri, 29 Nov 2024 13:30:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732915828; x=1733520628; 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=NaYQzduXureuKtm8f+lz5Tvdh8IrdFxPr0YwAuFJoGNwuSH8Ir9lT11NE6ebrCz2Ts fiPUI+u6GObFm7qjuU93nToWOIdY0h/XCX5cXLy6aSp5P50Y2lPYeGdOzNlr1+Ele2oO CBQh2d6L7tT7z8CASI8UN6BAoIt4cfTHd3tJM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732915828; x=1733520628; 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=J+X2abSOCukndu98KGpsLG/tx9xRVq0K5GOL5DoqpjqfKotjzZtXq0vvaZn9fPPqgx JEVLANR8RKStda5TB/F8rQGXG5BItKGkS9eeKvyFkjM0YobUI0VwkBvlW8y2IJkhVfCt pfSsSoqCgk/Y7i0ACthTFMeaVp7T6+ZXd+EZtG3ZT9/H1H8eJZOJA3pio2iSsv3o2IcA 0EcbFCkig9wmHNAvynXzs+rmdQFopFW5zNPEleBLtb8ssQDpdacLde/NY/CsnS5nt/b7 1P9IGu4apjikyMh2lPvsEoruLk5wxLnK3JU6uBn8cA4qyzd/omT1JiZ4TL5ORSDpOCvW L/gQ== X-Forwarded-Encrypted: i=1; AJvYcCVPFeoHBxCShkVrxXbGPdVCiVGHeBLlffacWS+8yAkTWYRJRz2S2ARqynaI0d6HtSbJV+FaOUOqF9S+Rw==@vger.kernel.org X-Gm-Message-State: AOJu0Yxk1AMoKTbtGbeKNiymoqvjQv99ACKMq7iiPID7dfyqQxm65U1l Db6B9KzQqENPb9lD1G7MN8s1P1lU7nDPmXZQnUoJ5NhnVp5D2kXu8vnw47svng== X-Gm-Gg: ASbGncsqoWLNDJeA7M5+8lcLLjBjCa083XYOPly2aL0SgIJt8ydWcXG06hFaDYQ4qRb FA+qbQxwW+A2kemy6qFcXCD8uPPAO0pLUhJErjmtup0ChIqZYZxshUOD+OBJ/Olk8GeokXsXW1W txSTlPURA8J2/JsaJTLAK9FInIv6ZgPAZMCDW0NBey1yRxzpAVCJmWvdFfnTAztAHFgfxPqTBbf wl4aINy8jB4WZWu++Qf6XQJv5Noh0j6QuA4re6inzBPzAxMQrauSw9DN5eTpYmyVU85WNqB3L/q /t0ZYxtFTz0CU9IY9LoaIr00 X-Google-Smtp-Source: AGHT+IH/h19gXrwsr/4Bm2brThGr7h969wtQPyxlHGBXmx03EjgzxndUgkQD4dm85b4dZ4/o0JrBRw== X-Received: by 2002:a05:6122:208f:b0:515:3bb5:5622 with SMTP id 71dfb90a1353d-51556a15ed7mr15838902e0c.12.1732915828303; Fri, 29 Nov 2024 13:30:28 -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 71dfb90a1353d-5156d0c1b7asm607254e0c.36.2024.11.29.13.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 13:30:27 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 21:30:15 +0000 Subject: [PATCH v4 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-v4-1-f23784dba80f@chromium.org> References: <20241129-uvc-fix-async-v4-0-f23784dba80f@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v4-0-f23784dba80f@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 21:30:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888944 Received: from mail-ua1-f54.google.com (mail-ua1-f54.google.com [209.85.222.54]) (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 385F81A76D5 for ; Fri, 29 Nov 2024 21:30:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915834; cv=none; b=r4sKWKY3ffUvD/bK2rgaLTPujl7C7N6S7KysPrpYofy/G50y+iZWCd3MAigTUUOv2dCL8i9ZarHlSTbZuOtTqP8Z5Fgn9KvQsJqAGR6vKy1Eq6GxrlsrgvXKAEhWctyCD/FhGQshz+nJXWUiTLgRxvplAp6dCe4jGRSGpgVBoKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915834; c=relaxed/simple; bh=+pfaMnSC0go4/J60SrpKpFXQ/i2qf8ZpJd+CtfqYHc4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WML/uS2yGChE83iddhtT+3/END6XkMOMrlTJy4UvdUkQB0Mo4dwi6U9wVfmjRpveNM1ZD4XFanaL96oD3MrHpAa9eG92Qz2H/zRtbf1Bv+4fnpYApjwfddFp6vIahbfR806OxJJpLQZoCim00fSNsqvI74xm1XFbQaoEkfjuNGQ= 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=meuxX1IQ; arc=none smtp.client-ip=209.85.222.54 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="meuxX1IQ" Received: by mail-ua1-f54.google.com with SMTP id a1e0cc1a2514c-85bb08df36dso37799241.0 for ; Fri, 29 Nov 2024 13:30:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732915832; x=1733520632; 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=GhCf5eirgTgth8XVE2W1qnK6YW57KSpNmGivwsRejzA=; b=meuxX1IQdfC4s6PO23AcZGaieysvEH88HOrPUrziIUJfjtUVWF+WGlOFSSlKjA4M6C gWw0POZB7PHE6Vy8m6SVrmB0gBi6B5mLkAlHKFMQUc2bhVVPTGb1m4mL0Da6g07LQ39d ibkiV7i+wGSwSa5cTnhkmYE2y6mW0p3DSF+mo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732915832; x=1733520632; 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=GhCf5eirgTgth8XVE2W1qnK6YW57KSpNmGivwsRejzA=; b=ByQQzfnWzSwmfpTjuF9z7GY1Iv+Go4hYOGmKPyZWO2bKiuWWX+7/OgFpM9gat6sOb+ 5IdPIB7dxWXd533u4+gyG+1Sz3TVL+Z3zuYtcORwAQrkGGdG1p9DarBuUpk7VKRHe6fL 7AMKBurKfOKsQI/k6Tn7WBzfQCseSj+qH+M/LH4fn0QElmUBQUbsO4EovOYlsN8+D1uw EeZSMKTT2dnCbDuWY0d2CBkYR+fb7N4aTzbW5i2I/+5ggCerRWdfu+Y9v77IzJ6m6ZXt sfgC5YtfPwU4A6f+J5mWGeBCRDjVrzP2KXGzIZIwayT86VZXFJD7LEawsQpmfjImNeqk V1hg== X-Forwarded-Encrypted: i=1; AJvYcCUl7R8aLjlfcSan0SBXDXVECz8D52yTCyF0pYlZbSO0ReNlU7ew+myOVGF7qWOurgRU0LhlskFiJefHmw==@vger.kernel.org X-Gm-Message-State: AOJu0YyL/RwUtbRhDHHbuFeeVRl0llBGrk95cjVswU5Wh3A7oeClSe4K XSTjZVu04WlsULxcvUt2z6GmWPskY7MEK8gQUINp6rT27SwWB9Lna09GKKG1MQ== X-Gm-Gg: ASbGncu/wBX7Ob9opEQQ59yKoRUSKIEIuk1V+F11KzDUxymrsmj89PDyYgcDpEuwuYA RP80ENM1ovpFEMyleW0K3x2RMxMeQYEMndSH/KqHnEtCtzdtvgm0k4zkNTtjryxo9WCST4WCZHu l3v3v0zK+qp1EkBnodQaTHXpuOqJysWLuB/pA0z/8CATm9XIQwvNyPazQ0vtYKuKV81aesbpqYq ZTL4E7ySPhSXHcwOn/hmnJanzaJHjujdOh5+CEDkjL3M7kbqw1MF53y4ccZFH6jLIohvgdlxDOp yljCUiS6aP3I15FmlEGf0kro X-Google-Smtp-Source: AGHT+IFYwmDx0IKqcsATxkcItz9Kemn9Y5b19SBUmQymuvzPqTIPXsfSyh1fHAg0r6gBeJc73H4R+A== X-Received: by 2002:a05:6122:6419:10b0:50d:40bb:ae14 with SMTP id 71dfb90a1353d-515569e2f8cmr9832094e0c.9.1732915830592; Fri, 29 Nov 2024 13:30:30 -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 71dfb90a1353d-5156d0c1b7asm607254e0c.36.2024.11.29.13.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 13:30:29 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 21:30:16 +0000 Subject: [PATCH v4 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-v4-2-f23784dba80f@chromium.org> References: <20241129-uvc-fix-async-v4-0-f23784dba80f@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v4-0-f23784dba80f@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 | 54 ++++++++++++++++++++++++++++++++++++++-- drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ drivers/media/usb/uvc/uvcvideo.h | 9 ++++++- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 88ef8fdc2be2..bc96fb475b9c 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1579,6 +1579,33 @@ 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 (handle == ctrl->handle) /* Nothing to do here. */ + return; + + /* We can't change the original handler. */ + if (WARN_ON(ctrl->handle)) + return; + + ctrl->handle = handle; + handle->pending_async_ctrls++; + return; + } + + if (!ctrl->handle) /* Nothing to do here.*/ + return; + + handle = 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 +1616,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 +2074,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 +2797,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 21:30:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888945 Received: from mail-vk1-f179.google.com (mail-vk1-f179.google.com [209.85.221.179]) (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 81B171A08AB for ; Fri, 29 Nov 2024 21:30:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915836; cv=none; b=S6kgNasyN5Wg3mPuebCwJg7JjV/BsU6h7TCVSiiIUc889V/L1OHDg2fq6BlaiXuz85gz00daj2ZT21olcZNl3wyQoInJtPfNIvqsNC+B0NaDK77OekCxJMgCZo2VrzlLBuzZRCbFi7bjUkbCHZuCpJrmSdDRWsHJ9kW97DwUMjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915836; c=relaxed/simple; bh=hem3w0cqOpuUXnWOHaCYg59eIwff39vWTS7lxdWqD60=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dMz3ydbna10nAYAJOPNf/KP09gh1S8XbFNN+eObGXVo+ImUX5U9oMtsS+GpAyEJ64gWB7nQ4XYU+7E7ffXMoY0R3s1/RDESBZxqKGcbP27v/3jLXCTQ13TJhSeGPplUnMpRvKn8Nz0wEzMuwV5fnPxX693CBqcH4P6BGnei9p4I= 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=e/8AYeGv; arc=none smtp.client-ip=209.85.221.179 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="e/8AYeGv" Received: by mail-vk1-f179.google.com with SMTP id 71dfb90a1353d-515526c43cbso529773e0c.2 for ; Fri, 29 Nov 2024 13:30:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732915833; x=1733520633; 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=W2rn5S7/m2AnqfUGp/AXrxEjHYa6ExomvekQA1z9JF8=; b=e/8AYeGvFl0mTTpkqIdVoIQlg7ntOEz9BgkVB+GNsqQQnOiS1b0UddHAUVy32Gb/3k Cxo7l7cHzHcv6+bm0aOE559bbAd5Xew5Rupki6+dM/QHnxU2kRBFLWpPLxBM6fuDjCnk j+3rkyfyyvR4GUpL/fXb5fFXq0bqsjzGO4RcU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732915833; x=1733520633; 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=W2rn5S7/m2AnqfUGp/AXrxEjHYa6ExomvekQA1z9JF8=; b=OykHsVWD1DIidlOYEuHqVgIxa5ihMTQ0FEQo4I2CiGccStSMfdVwpLLltP8rXhQPaw 7Aoiwe+Dhgro38LGBIGGLnHmgWSHM3SH/vX49W3K1ahPTH77baGW8lj253c86ezMPoRN G58ZSGusJHnDyQUWHxOYTRY0jvcnBkI6jt9JpB6rQBkJIdKqM9pZrB+wYCUw0VruTvBl tUcWLaISsgBTNZRq9+wVZ4l8XqLA3bQYGWbmcXtAQy2YaqkliJZeoKBLuSw9MqPzNiSp wqzUNassXawbqGLZ01zjK6ClVvzNLYCAN+L662yYHXXu5wP+99k7FFPfq9DYWRlLi4I/ cZqQ== X-Forwarded-Encrypted: i=1; AJvYcCXWJRHo7VkTm06rkqAi+Yv26lbX+WU2/fSdY6nbGHbCNzUanuNL7yzdxW9b6MMlNMw9qiU/yfALGfteTQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzSSiW5xgiVlNHzwzRb+c1mEoGyM7zza2Ov820hzNcQ/gGg71w+ X5P5DqrNESSD4KWS9jC8azm82yOtL0Zj6qFvANY+QOmr7DMVESu5mFnMBr8LUg== X-Gm-Gg: ASbGnctwmD9wRt77zOqKxQtaBd9P9MVctviFlbDcpPzhBudUWTsITzYyTFMWl6IbmhP hO5UCQrqXkP+rM/bRLgeOg+OHWFdlNSZNCjr+h1v3XfgHzXcJa5ZGMHi+Enw9JwMtYf701NX/tI 2Lqt2/ung7IcZz+66y/gSYxnTQSUNKY6Xv+hl/w0er/lqCUJJWCT7koHUULymIxjUPE88o0eM7h vVhmsB8NcPcHYg9nFX00NSKl1q21UqhPdl8/vZUaPy4rGv3Xbz4TwQcLK8R30GfvXq+KneIhOpD CDiccLuodLCehHRN/iuZhckM X-Google-Smtp-Source: AGHT+IEcGD+/QiSnHqDspBxFeqf8V4eyWtSEYu06OHOVvuFJxL4mfm7VoAcu1T8tpb9Ahblgt2JqVw== X-Received: by 2002:a05:6122:6089:b0:515:4b68:c37f with SMTP id 71dfb90a1353d-51556926b00mr18430743e0c.6.1732915833363; Fri, 29 Nov 2024 13:30:33 -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 71dfb90a1353d-5156d0c1b7asm607254e0c.36.2024.11.29.13.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 13:30:31 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 21:30:17 +0000 Subject: [PATCH v4 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-v4-3-f23784dba80f@chromium.org> References: <20241129-uvc-fix-async-v4-0-f23784dba80f@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v4-0-f23784dba80f@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 bc96fb475b9c..e02540162dd4 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1968,6 +1968,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 21:30:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13888946 Received: from mail-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (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 D8FC51A9B4B for ; Fri, 29 Nov 2024 21:30:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915837; cv=none; b=hgbahnbPHLfHIOOdQm4oC2OiDm9POCRoOrhpK5zvIYPHjCQNFCujZmG9DqZgEDEZh9iJPinHBD1rTV5GP3nsLRPLa1O9aHyEyhLCphz/uZsmPnqZXLg71KsJFIuT+KSZvlYEIW2vAnHrWcDyXKDeJwX8I6X+eIAs19iNERu5nqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732915837; c=relaxed/simple; bh=v5QezjflINmr1he5MndfMVx+1wL6381Mly0MlSiNytI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DLv0qib1586gJ3ybWLjeXmqJdetppK54Jm4YgAIQ0t5BIgTciin8RN82XnL9PNaORDMRWibmFKerObba4bTC7pC701b58KCV4r/sqQ8oUvum+XixEXn0BqGtj5B1qd2uQi4MZlZyoNZznPqp2SF0GkAdBsPIwoYndo2JZy+UG+Q= 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=VlOtASaq; arc=none smtp.client-ip=209.85.221.180 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="VlOtASaq" Received: by mail-vk1-f180.google.com with SMTP id 71dfb90a1353d-515192490c3so598897e0c.3 for ; Fri, 29 Nov 2024 13:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732915835; x=1733520635; 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=ucJjvH6Z5O34BPMy+Kt0AFvVfn1owPFISOzjaTX5B9k=; b=VlOtASaqZgGUN69hfmv2Q3C06dVq6HZ0oZ5O9zpr4MoV8hFqszUHXMe2OlKzGIKatA 1qMmb5mBPkDYA9ueUHWJWUkIiyq4q9rkstP98TXzICFTZACTgPwYiIZtDEAiTkjFh8f3 kFhI7QEWuFM8VTt3AnA6iB2dXL141oLZcD4Fg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732915835; x=1733520635; 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=ucJjvH6Z5O34BPMy+Kt0AFvVfn1owPFISOzjaTX5B9k=; b=FFOtjn12vy4P9/A2Av1SZOqnBmjO4C/2OIogHWRTB3syUUyTWFh5BYL9zKqd26dyCS SCApUS+i3LTFqJ9gK5q+Q+sBpQLqBo2VYOd8DSEa70/yI/sTpFl3gmJqqzgFUViNwMa0 XGsB7rcAg6nPlb/Jo1FlaY5ilOGiJct78kt6VP0txXivQ0OOX1IKQDk7EGL2BXHJCw1J Xy8KQ6SvO3ORgQkxrVluuOUS4QNzNBCdb/x7HEIyXm5HKmdyxxv6OraLcwHkcAc9TS8v 5/KqP7YDKCNKA/dm2bDdGX+NyRKwIMB4l9NmIHfdpNLQVwVMmFq8co+eeH+DODvQVxm/ v03Q== X-Forwarded-Encrypted: i=1; AJvYcCUID/Pq67NKqQJym55Cbl7aneyMsGwobIVmeaLCmXhgBCYPgm5KCLTiTSsIPsPJTqxWOcltdFfnhK96IQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yy37CEj1toIx0dC35di/9P2WCF0gJHSJtTfUckXZyvSO60THZRK TDu/T83Qv1YNP0Jxj1zUcbjeFK3XlvZd+NMFnkOJXqbu6Rn6Hi6wPEFxNCPApQ== X-Gm-Gg: ASbGncsbGXvProqnSiZx8sK0r282VpaZNqoZffuJz1YhUOTdTH0HeEPxzZvY9RG7aom aJRFPLXtu2SQ8hvma/l5YUQaBF9pb40tCdFM++2fE5mxMC4k598bbJlUHQzfMh8ucw/3gxvZgLx Ih+RAOSTT3Ch3ZefjldK6J4Fq+v6Mk2KL+jVR2S/BntiopRf7AdRellkKmBMm6e44FWn+Tzl2n5 AkinJ4sx5pmB36VqacN5RUgpJ5MRHwED8Dmk3i8RTrUe/AkhXkcl5arHuiajox9qHxHxlergZSQ SxhtNStrMTOreXDUYVIWyBTm X-Google-Smtp-Source: AGHT+IH3VfM6LqkrJkK/UlQJJZ22q3iU/5oBBscMFmZZcqik+YSMZUFM/OEX7FkQUFRdN8ccT/KNFg== X-Received: by 2002:a05:6122:2a11:b0:50d:35d9:ad60 with SMTP id 71dfb90a1353d-5155692de66mr16955127e0c.5.1732915834862; Fri, 29 Nov 2024 13:30:34 -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 71dfb90a1353d-5156d0c1b7asm607254e0c.36.2024.11.29.13.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2024 13:30:33 -0800 (PST) From: Ricardo Ribalda Date: Fri, 29 Nov 2024 21:30:18 +0000 Subject: [PATCH v4 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-v4-4-f23784dba80f@chromium.org> References: <20241129-uvc-fix-async-v4-0-f23784dba80f@chromium.org> In-Reply-To: <20241129-uvc-fix-async-v4-0-f23784dba80f@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 e02540162dd4..8483e6760be2 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1667,10 +1667,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;