From nobody Thu Dec 26 18:33:47 2024 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 92AD21A254E for ; Fri, 29 Nov 2024 19:25:11 +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=1732908314; cv=none; b=NxgksJAEnFrDkDZgslmhi5giNvb2PH8QmHpusgngY1idaskgb9kgDk3v23exSwwl8ar1AFr17kwkJVDINdqs6Tw7o/xnzumfqNF73CWox5r2iXOvGAFfuVILStVoiYZ6f75nM7Xuk391DWRQTMAfyUJ+WUgAYzmqgJuHimWLDgY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908314; c=relaxed/simple; bh=KDAOGjpXXULpZa75pLl+o8CodfY7IbmICZMYyev2FdU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EVIYMihknL4cnPfmAMeqVkRvpx5SSN9DhvQDB7XrcLhjcw84/NgSptR0fARmQcWWg2pnFPV9UEZi/avCKSuwg6WM20EYg3m3EgRqF7nSpDTzH6+9Yqa1r2tiMW04ll6G+qlcYaEO3YhZdOUmTKuf4z9EtndLmmarq9mg7p6QN8A= 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.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="T/vk8ZML" Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-6d87a55bc50so11754566d6.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=uqEP4tN5KR5/uHllIDiSpzRpsiUPFRnc4V9lVKwzcFsid2xXIxigvU4zqmAeVIFkIW F+jmGSK0VsCquJl3hbzere69IXqbNukQi7iitteNAOGRVV2/2y14hf9YjEDfcdBXS2oi 9ko6UxFKESozI6Xh4R1T3HOEA8y0rf6xW4kKGt1jZ6SGdn9X6sKPfczc7nmufCHMPEaJ c+rrpv8IXbNrWu2W+/Dbp/3uO8Cl8ty8TgOdKYkap9ydZUTnUMuk2wf+MjZF+JgZvxeO Lp18ZVi1eFZWYaK/L9hfeQZ0WLWvt7al6x3uBJRFqG/j4NN95JjnMOY6uA+2h1OPPTeZ +JUg== X-Forwarded-Encrypted: i=1; AJvYcCWgPsRqKODnHHvNfyidSoSsurODc0MPMPkRj2PnkJS84gtR/VXVqbQt/51DTCVyjpO5jajZELFsZdrcZTc=@vger.kernel.org X-Gm-Message-State: AOJu0YzHZDGJvWVg7DymqoxxbS5q54RMmUAbZtxPPP8T9NK0pnmb/qUp AeXt4XhFmN3CjXDNohdKDodviekOiBUsMe9a5E+u9sg+C0+nm3wVhTnP4CHxDg== X-Gm-Gg: ASbGncuBc2/T6oQ+H9Kg0o+IyxXDdtefInW99X1Q7TcjZ0OI16V2lYjYh+6CawKYuZB VTqigAPJaGyo1o+YugQKy/+qi00LBVxCeK/wWyfvLtlkGpfkbwL5kPjpqvbL7WKA1mFUzmQqBhZ O+vKn8AXvj0C9vr0DJWcCiYbweLt5J2gd5xUn3frbUHm012u1PI0hFGDsXq/zRdrsLzWArLrxpT o9S3ei/Tp5l0rq/MJP+4S+Br8ldk5QfI6LMzPCPERDJZBHu3K/DbU+pz2Tth6nWwZf0zeTU8mro n63gCKYcSL5YwaHX7KzY0jnP 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_c= trl.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)); =20 - if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) + if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS && !ctrl->handle) ctrl->handle =3D handle; =20 ctrl->dirty =3D 1; diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvi= deo.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 { =20 u8 *uvc_data; =20 - struct uvc_fh *handle; /* File handle that last changed the control. */ + struct uvc_fh *handle; /* + * File handle that initially changed the + * async control. + */ }; =20 /* --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 26 18:33:47 2024 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 05F6E1A2C21 for ; Fri, 29 Nov 2024 19:25:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908314; cv=none; b=stVHw3/vL7OB1g/gVQ4VkUGDUdbS7OXBUxSDHJGPldUXAmfTbvI5RsrfpHhQHrVUphsq1f7SSQIFaW3JCdHH9jxxhNDoy0vJYNFnXVRDGggBLtL7oO1sRWlwZKrcQGOE4p1ConOKaVPTgStBvJC75khfTK8CvvMSL+uJD5kbuww= 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.169 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-f169.google.com with SMTP id af79cd13be357-7b66812a653so138436985a.0 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=QGoPYekejMEUvzKpdGnjQJPoQQMpe2yrUr5lHB84mLhXec8PP2e6wdbDmH/+lmIfNA WQp8G4uXNQgjbksL4genBkTMuhrTXzz+ZJYDQrQEAFesNrtwsFmOx8CWSV4Xw4tKOU1/ zsq+PGhQ1KoWg4Z2c/unsCphZiKs3WelUwQc/kaISkNncjwJDwNOSeR0B3G+67A6m1Qt a9jOSz0gTCemw9cjKFUQJvsIbGrFVz2cvpCLE3kD7actXCqt6SGkriDAnt82ubDAL3TX SYWK5ZRhLqnndaYfr9Q5jf0rAAkkhPreAxHxjHzZzOgmBi1csnmH5We/t9+KIMOwd/le DZdw== X-Forwarded-Encrypted: i=1; AJvYcCWUicIXvbDEw4rJ2CduCjcKWvHas5pibpbSkyWu1bgyzgjfhSpBFAoJgXXXzAyENrFsq6vSg6kdKb/So7c=@vger.kernel.org X-Gm-Message-State: AOJu0YxZRUSItAcVfeVFS0NmdNUIn9N/SK+18lnk3V4hUjFO+nG1E++J M+XRz2lmZVBDn2GNzhAJ5U18PcaXXXnOJWkIxLT286yHonepVplhlre5f89XHg== X-Gm-Gg: ASbGnctTJkhrJ+4jlWMffvO1cRrJlBttAeHtcjIzJtuE0U3JQZZTyC4ba2KulGgcGE4 nCwYwlf5ue9Tee6sk8hfjlimBwWpmPEsXmw4DAHioqnqYsHm3lb5PBay4tBi6WCXVmvgN6tOl5H BOBdo5DkaO+S7xC9qQDRzjBuMfc0ft0vT5UFGebEs15Cz2cG+Ry7McGMipEcbWHbNnBUtZ93hmD YFgcxXLDwkSX4tMnunBEDi5I503GpcOSGcOWWGmJ602pnfD670F9GuiAWoQii6n+CkcHBR/JZR5 7a/Ps715NX31Sh15kOSINJ8S 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_c= trl.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_vid= eo_chain *chain, uvc_ctrl_send_event(chain, handle, ctrl, mapping, val, changes); } =20 +static void uvc_ctrl_set_handle(struct uvc_control *ctrl, struct uvc_fh *h= andle) +{ + /* 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 =3D handle; + } else if (ctrl->handle) { + ctrl->handle =3D 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 *ch= ain, mutex_lock(&chain->ctrl_mutex); =20 handle =3D ctrl->handle; - ctrl->handle =3D NULL; + uvc_ctrl_set_handle(ctrl, NULL); =20 list_for_each_entry(mapping, &ctrl->info.mappings, list) { s32 value =3D __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)); =20 if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS && !ctrl->handle) - ctrl->handle =3D handle; + uvc_ctrl_set_handle(ctrl, handle); =20 ctrl->dirty =3D 1; ctrl->modified =3D 1; @@ -2770,6 +2787,29 @@ int uvc_ctrl_init_device(struct uvc_device *dev) return 0; } =20 +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 =3D 0; i < entity->ncontrols; ++i) { + struct uvc_control *ctrl =3D &entity->controls[i]; + + if (ctrl->handle !=3D 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_v= 4l2.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) =20 uvc_dbg(stream->dev, CALLS, "%s\n", __func__); =20 + 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/uvcvi= deo.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 */ =20 - struct mutex ctrl_mutex; /* Protects ctrl.info */ + struct mutex ctrl_mutex; /* + * Protects ctrl.info, + * ctrl.handle and + * uvc_fh.pending_async_ctrls + */ =20 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; }; =20 struct uvc_driver { @@ -800,6 +805,8 @@ int uvc_ctrl_is_accessible(struct uvc_video_chain *chai= n, u32 v4l2_id, int uvc_xu_ctrl_query(struct uvc_video_chain *chain, struct uvc_xu_control_query *xqry); =20 +void uvc_ctrl_cleanup_fh(struct uvc_fh *handle); + /* Utility functions */ struct usb_host_endpoint *uvc_find_endpoint(struct usb_host_interface *alt= s, u8 epaddr); --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 26 18:33:47 2024 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 1D4981A3AA8 for ; Fri, 29 Nov 2024 19:25:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908315; cv=none; b=IEpDPxxc5a6OQkNQSLxxVP4fZNZln9d+T12myzl6/eNyAS3ojkPtMhkQI0oZzqc9yCd3Pf/QOgBKJnIqZ6D209dxrbbR82lidJnFk5exoXwcogXcxIbhpVhX8L/kgqXqyFTIFGEtcCp7BITnphypW47+KH69SvumoOoAh64v00w= 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.42 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-f42.google.com with SMTP id 6a1803df08f44-6d88c6d0fa3so3766766d6.2 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=RCtbWnotFP5mXbLQGd7a6uCYmKcJU8jhwKSz5v6HIMwXqENrF3qUlA1+0QJpDjGXft RR28vxcq5QY3kzuuEdEvjPuxwqCMMCodh428Z3SPjjnFZxKiHdbTjJT7RRlePSmKxCJ3 aQUFQjJqmKO9k/rCLrc+GMF130fnfA4EXy3OrNFb1cO4snr/Y7cqlCxUPjNKHAL9K/WS Hk6wuYndqnd9CtpZ4qTCkF2hSu5cDTiAuitNO6edxFH7I3gcAGpBP/ZS2sINqE0B28N9 xXRrzOnagWuargMDIn3gT2PB9iWfAidanI4DCRDatGs3VhmVA95QKjCLgnqVoiJvA4CJ A7Gg== X-Forwarded-Encrypted: i=1; AJvYcCX8ITA+Q6Q5oO5FekRCOT63FXtLq3wh3EGNpR/27QIhshefRzGX2+sgF/yvBWf9kSwHW05siXTFYOrBngc=@vger.kernel.org X-Gm-Message-State: AOJu0YxpfvGXQzTxcYO3LUllmAtMTCmfPCW/ntlpOynK2DGnGVnpV15l yPhCzCEMZ+TuUW9Jv7wT6bHfuPpbvAjEAtUuOr0ziGVvTgYsXcE+4os8A4btog== X-Gm-Gg: ASbGncuJ9KscGiem9qohPLDJFv3VB5LTX3DFUOxXx32lrnFP+ztNLlx51V8Qv0FnIAX /hvrx5ZLYov8oFEiovaapcpiX6EjNnbvkQpmaFISuBGbhruFh2+7le18tYkNtOj9BDhK9yCXd/U U8oXr4UyHU8g7fvCpsQErl1D9WuOpzL6eG2XA4yW1Z9u7IHYV9rmAYVQuPZJUHPGJEuRRGS6Mgj loNkBOyeje6MLaFl1rn2ZRMukAvLZqR9gWRkFJL1LtUvCBWAjVJ6tPFAZpCbJRwt97VLH6u3dM0 pPYamK7hodFifO1tgxIgwPTo 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_c= trl.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; =20 + lockdep_assert_held(&chain->ctrl_mutex); + if (__uvc_query_v4l2_class(chain, xctrl->id, 0) >=3D 0) return -EACCES; =20 --=20 2.47.0.338.g60cca15819-goog From nobody Thu Dec 26 18:33:47 2024 Received: from mail-qv1-f49.google.com (mail-qv1-f49.google.com [209.85.219.49]) (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 BA9AF1A4B69 for ; Fri, 29 Nov 2024 19:25:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732908316; cv=none; b=cKtyVHQ9gzmB8QzZh7E3mYIO32IrzfGfEpmXEAzJcRX2KtDVfeQb0UgiPnv6pkpn+OfbLdLN8/iUEmd4yY5aTQIj18reUuSLkp885pV+lW+PutCVDU80ffkI/bevjQxwdnQB9jRCfOtoKAF+vTIq+MZ/ijrj3ecfbKjIKgI8Jdc= 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.49 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-f49.google.com with SMTP id 6a1803df08f44-6d849a93088so14256746d6.1 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=Gm9WAYspMC+bfuxaqp6LZjH1jalOiepykDOcTzDANpZznIL96ccmVwC2ufQi6M8ip/ EwF9jn3QnFxrpgg58HsPH9FeAsE+8N3r/N3/vyGPPnv9LBJg5+peH8f1MnAISbWDMAq5 C3N/d6zq08Hrug2LMT+Gf2P8sXL4rr3FX80wfVJ5TBJP0noG8FJFKFYX1AQaDiMHiPB1 sSkAzPSTamx94AbQLidT8uBlHDEW7K5H7OClEF4csw75cWUzHWJ26AGuwWDbV5qoNw1S bk6r2x5m0TCDKa6F4ezGMkMOgtLXLh5HIGqZn4uBOLWjdryUGFxflxZQXRBM6jG5txfg xKng== X-Forwarded-Encrypted: i=1; AJvYcCUPSWt79OgqxqX7wnKIhBoK56lta9uFCDvIIFrNWI83Ru8tr+dRu7EKmDT3jlHJFI0szlMDiTYsiGRcaZ8=@vger.kernel.org X-Gm-Message-State: AOJu0YyyAKlMcLR1EkHbpGTtLMT4l+WiLuqk5HF3i6YhKRYO1Z6kK7rM cfz8KcHI7xnVEARplHM/Wj9sytPFldgS5XqcL6obIf5tFX8FvvoyVW9c4dkksw== X-Gm-Gg: ASbGncsG3ztPKV2XZjGpzNwam0fPKTJIykJAo/ihdKlKU/16uf2XnSpr5QfTkLIsx7r 8ePxwQhRkapJJVCZRIRDRVh/ZpPBzVYVq4SmVUF+pvgJfrz7O7GQxSn7Cy1p0rLQuXwgiftZisT H30JP2jK63IxdtnIeIGtFAsGS24iIj1mjs25qyI1fBwb9L/vz5ZQG39SqMgRwb1aNFm8PF5Jvtk YOWODTpQBofsKabxXnISb430iQJCqZDJWxTHQpL1lI+dnhRbr0wGspZtgcXYrSfOvJYWUlSOpSZ i4uOYrWGDJOtJJD6GOpjTgzL 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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_c= trl.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, st= ruct uvc_video_chain *chain, struct uvc_device *dev =3D chain->dev; struct uvc_ctrl_work *w =3D &dev->async_ctrl; =20 - if (list_empty(&ctrl->info.mappings)) { - ctrl->handle =3D NULL; + if (list_empty(&ctrl->info.mappings)) return false; - } =20 w->data =3D data; w->urb =3D urb; --=20 2.47.0.338.g60cca15819-goog