From patchwork Tue Dec 3 21:20:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 847503 Received: from mail-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.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 19EC820A5E3 for ; Tue, 3 Dec 2024 21:20:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260821; cv=none; b=js+hbMamjYO3MOe4BOyWs+wBhJcPOBs0fAW82lqv5+8zgqq9n6YXJ4DN3jkad7Hh38XHSI6uQ2VZ9kqF5q+K1f/VIVRrhtYVJvusdeCvU/yyFIVJc2c+XZwCyMI8tTMEKrqAcravQ7W78iBxPdfNE+ppBBcei33/SvImdK4ObT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260821; c=relaxed/simple; bh=7mCRueWRTLrrGtLhTrWTfJrRJJeyxio72U+xB2LFHbE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LxUWl2RbuAFCcOf8TkegGVJN7kVmJFIUaIBm5DQagUNOU+0jVN9kW89Ymf78O4PtQEpHWW2yYgnM3xVjbNqHkKvBAiUv9CxhnCh5CxRnAoWG5o5eoXp+6/JQ6QURrUofL8sUQJx/mr2kVWxwbGy/Y4nmaDN1vVEvtQmML/uN6W4= 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=gUrKRpxU; arc=none smtp.client-ip=209.85.222.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="gUrKRpxU" Received: by mail-ua1-f42.google.com with SMTP id a1e0cc1a2514c-85ba8b1c7b9so98321241.1 for ; Tue, 03 Dec 2024 13:20:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733260819; x=1733865619; 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=nOOe/WRZagmMi60fK6VqlpT1825okMetV6N8Itrt7Mc=; b=gUrKRpxU6EkNh4vHEcfwnmHu/m5hvanTzMo9A1zIUfBYmGDA+S6xLJX3/Ku9+lWBmG z04PkCjd7l0drl9qQ0ZbEtHw0E5BfBOfVU0zx6NpY2/RWOmfk8ggkMQUja5VFqkM0L3P +afi/E48bmAE8OT1ag/ZlWFhUo2v8b5SVYbVc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733260819; x=1733865619; 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=nOOe/WRZagmMi60fK6VqlpT1825okMetV6N8Itrt7Mc=; b=PB7W8iqTm33DRt61enRy+hX6yKjsxh0wF19bp1bxgk7TKMzm9zYejoQiaso9k+9SJo WEu2YiDJVAB7yGN662EyBwIQJ/9oh2nvoKTMUwdrQsK60XwHpzgC9uXlYvkZimzKNQ41 VpcQnpdBHgQ8PvjForKvb4K5EE0gYm/RxNLShNJiUy2YrFGjOjbyjD4lVjkwme6UEG5Z /e+DJ81CB71q5pBC27keVPzEk5ECD+BzAL5/rAYnGZtrN6IIPm51mSJfdN4kpdllXZ1M vzaAKUKCq8JOWrc4ye0JTtmTMJLVveBxjc7kfpurWzAHYO7jFXbOhOIrmsK3F8BDVlfN NfxA== X-Forwarded-Encrypted: i=1; AJvYcCXbkoIAgvJJHuSVtg7KwL+0pL26FjWbnrcqYfd42OEZHu5vLB+mOgBEpRDB7N6YpEM9KgH4YSkWfOsGtQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwSRCMyeygYsqUPv4Qu43Tpd+DnhelEypCUdE/hegNMT/s3K5s3 EZU9lRpK7cUjSvOq0EMtDrr0dyYAXp39JNpK0RXFyibrcp50t6CWaEPy6XrM7Q== X-Gm-Gg: ASbGnctbZ7Hb9RyAvJTwaIJXK1uaL9QrBZ5Hgf9ifsLG2zLx3vrkA4bANm2mrfrAbqR APweEpcKtlDhBEO5VdwpxEnNQA6+qxVylFUx9aN8nZ54grTexGz7siUjYpeN6UH9e/InXW6oq+y Xwv+23BNiT8URPOSY+txJho3ideIjgq6oFFMBxIj02mseqCeCVN6uEmyC00HHvY1YIU518RjMXA uJI7RuGAKcH4ado+7Up/1cphVNZHQkAz9vu9lxyyR+/3JmtyPHOCIu8o11SuyCEihCM9K7y0rkT YAn+zv/8CA6dgiwOG1PMzj8v X-Google-Smtp-Source: AGHT+IHiizhG1r48NiSLYamAD0KEtJnCWIjp3L1I6RSZUBOGagQM6jryT2Os08sSfMtFWidXsF8z6Q== X-Received: by 2002:a05:6102:2a7a:b0:4af:5634:d26f with SMTP id ada2fe7eead31-4af5634d73dmr23535275137.13.1733260819058; Tue, 03 Dec 2024 13:20:19 -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 a1e0cc1a2514c-85b82a89d5csm2140364241.8.2024.12.03.13.20.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 13:20:17 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Dec 2024 21:20:08 +0000 Subject: [PATCH v6 1/5] media: uvcvideo: Only save async fh if success Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241203-uvc-fix-async-v6-1-26c867231118@chromium.org> References: <20241203-uvc-fix-async-v6-0-26c867231118@chromium.org> In-Reply-To: <20241203-uvc-fix-async-v6-0-26c867231118@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 Now we keep a reference to the active fh for any call to uvc_ctrl_set, regardless if it is an actual set or if it is a just a try or if the device refused the operation. We should only keep the file handle if the device actually accepted applying the operation. Cc: stable@vger.kernel.org Fixes: e5225c820c05 ("media: uvcvideo: Send a control event when a Control Change interrupt arrives") Suggested-by: Hans de Goede Reviewed-by: Hans de Goede Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4fe26e82e3d1..9a80a7d8e73a 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1811,7 +1811,10 @@ int uvc_ctrl_begin(struct uvc_video_chain *chain) } static int uvc_ctrl_commit_entity(struct uvc_device *dev, - struct uvc_entity *entity, int rollback, struct uvc_control **err_ctrl) + struct uvc_fh *handle, + struct uvc_entity *entity, + int rollback, + struct uvc_control **err_ctrl) { struct uvc_control *ctrl; unsigned int i; @@ -1859,6 +1862,10 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, *err_ctrl = ctrl; return ret; } + + if (!rollback && handle && + ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) + ctrl->handle = handle; } return 0; @@ -1895,8 +1902,8 @@ int __uvc_ctrl_commit(struct uvc_fh *handle, int rollback, /* Find the control. */ list_for_each_entry(entity, &chain->entities, chain) { - ret = uvc_ctrl_commit_entity(chain->dev, entity, rollback, - &err_ctrl); + ret = uvc_ctrl_commit_entity(chain->dev, handle, entity, + rollback, &err_ctrl); if (ret < 0) { if (ctrls) ctrls->error_idx = @@ -2046,9 +2053,6 @@ 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) - ctrl->handle = handle; - ctrl->dirty = 1; ctrl->modified = 1; return 0; @@ -2377,7 +2381,7 @@ int uvc_ctrl_restore_values(struct uvc_device *dev) ctrl->dirty = 1; } - ret = uvc_ctrl_commit_entity(dev, entity, 0, NULL); + ret = uvc_ctrl_commit_entity(dev, NULL, entity, 0, NULL); if (ret < 0) return ret; } From patchwork Tue Dec 3 21:20:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 847161 Received: from mail-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (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 4CFB720ADEB for ; Tue, 3 Dec 2024 21:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260823; cv=none; b=Pzknf+R5ffl2lHkWllJrxdqvbA4BxnSSRSte4Kv0tb4tO8jr1G6vjQSDWiLD0ioTlYpenxcdtpn39N4vNhirBLSeOhaXXI90qU6mJ1rV84njsO1r8+Ma+l/SD0Uf9jvG7QcQ3/IkmBKXQCXgmaGw/hhHMQ+D3dY5PbX3uQ7eT2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260823; c=relaxed/simple; bh=l4/lhwctK3kBC3s2JyaOOWF9ukBbTcldFztSXBtwWD8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cGzvyVOqSnxQAv11AXz+/4iFf+JR1Rm9H2SqVrnl3c2eKAuVqasR5E6n/qBqhQlve5uwN1ZdH3prP5WsSqzsaAtX4TKyBdNNtEUa49T3e05iiHAWsZtZNH5eaLbvNPjmNunWIaerQXfReTeaI9xxtpI0eOTrit0v1IEVJjv98hI= 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+E6Nm1h; arc=none smtp.client-ip=209.85.222.53 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+E6Nm1h" Received: by mail-ua1-f53.google.com with SMTP id a1e0cc1a2514c-85b92397fe2so818894241.3 for ; Tue, 03 Dec 2024 13:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733260821; x=1733865621; 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=nL4Atu/0WT3Bi8AnR4uXCq5U/XlhAxlSF0B4ijqZik8=; b=e+E6Nm1hFjwqcRGOb8qFT7tP30MVCZ5B+SM3iPDu9n3QNPvXzjxd1FrRbPpgbWkJ2+ UQRcB7vnhSiW8iDNOGfhOXGnvMlywv8romtCbY4/Sxd7jBX8CozCRYEuXKIjGLuPIjg+ T91RF4uUsqLpE+A9X3QSjA8e/9zqooMdpCNlE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733260821; x=1733865621; 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=nL4Atu/0WT3Bi8AnR4uXCq5U/XlhAxlSF0B4ijqZik8=; b=N6PzKspLqRdo2cYLAPVFASi2IEcMOqCaCloa38oStf8DIVUxzg7cBOWD9qNtBkC+nr Cc+NZuleWuCLQTq4eCpj+S6kb+2yzt1Bo5kdgWZsi/Gg6yyElGn9AIsUokHOvzM/cQuF N7+zoXKX5gDByOShZSUmdOukdwoYDVhqWCdxC7g36nZbT0vwkTdx1vqdhxk0+/FrVf8H 04/88GvFs7sBqc4OJdCe268/7W7PodWklUfdHk0CIGRvZlgim5Cakax+MZKd4nzch5Dv OtTV0f2CeOVLj1kAdm4UaHPwjw+XGv5uTLEZZYEMDbbwE+Cqkwur7d0xGedPWm1GOVUZ vxnw== X-Forwarded-Encrypted: i=1; AJvYcCUa56OfitYNdAtJAUNQwmgehjPu/7sI3NXZ7SjDfnMQij34e6V+4mweBzOfZ4lU2VUL0UOU2D0n/9Lx7g==@vger.kernel.org X-Gm-Message-State: AOJu0YzZgoKIXwt/py5rNTKF4/mSh6++FWgerSnHADbyideHcGEAYKAh 4s/vAJ8Ttpl8L43sdnUvgf2NPt0EOxYxogO+A3X4fYRKukG0WrNniODU4BmriQ== X-Gm-Gg: ASbGncuLyEAtRJ7YY94zbj2TQ5rHPo7IuagBgucVliNMWNErZIVp9IZldCbpBzYZEhw 5Mp18KiiUjnjkg3Z6wZf0vFgg277+pUYZuEpN3e0EMGbIw5+sMpY5tVrCAyaUVVzyapUDHChd3i YU0NowvR2oRkfILcF3o+cPL+IM3ad6ADp1WBVcqdy3llaa9dCCB/dj/u36J15dc3C2IfTs+HF8u /28EM/SnIWAQ5rTkiBVTWg35bH9PNtI59ikUZFqz/+lJo3CjvDNVbW+UFkzN4rhHT9hC87jms3h d4nae2XmsA03i0pkq698FF8Q X-Google-Smtp-Source: AGHT+IFDq/YyaSDjFBUXsfLRGsjk8UOE+Mft2rZWydxkoxjhSW9PDslAnWq3gxZr/nwtXjYBEcitrw== X-Received: by 2002:a05:6102:e0f:b0:4af:4c4d:c8e8 with SMTP id ada2fe7eead31-4afa4fb9017mr3596621137.7.1733260821288; Tue, 03 Dec 2024 13:20:21 -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 a1e0cc1a2514c-85b82a89d5csm2140364241.8.2024.12.03.13.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 13:20:20 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Dec 2024 21:20:09 +0000 Subject: [PATCH v6 2/5] 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: <20241203-uvc-fix-async-v6-2-26c867231118@chromium.org> References: <20241203-uvc-fix-async-v6-0-26c867231118@chromium.org> In-Reply-To: <20241203-uvc-fix-async-v6-0-26c867231118@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 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. Cc: stable@vger.kernel.org Fixes: e5225c820c05 ("media: uvcvideo: Send a control event when a Control Change interrupt arrives") Reviewed-by: Laurent Pinchart Reviewed-by: Hans de Goede 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 9a80a7d8e73a..42b0a0cdc51c 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1640,10 +1640,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; From patchwork Tue Dec 3 21:20:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 847502 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.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 822F920B1F3 for ; Tue, 3 Dec 2024 21:20:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260826; cv=none; b=tsEPeXhwfbrEr1yF4RqNLfCudfA65jIfFba9MKQTLOEeIMuYWy5zTz3voDDWihMzOqN8CTYgqOQSJCWJ7+BNYJXbic6rv9WvKJFR5HYy1tcffNI87Ky/pp/QGWljMjRxa9whl0PH6P4zxmUBQEuWfE9qlMfxi0KP8dwLaozmG24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260826; c=relaxed/simple; bh=C3v2J+2poN58Kyl3O5+kAnV8oVk30/d9asKCtbOCpXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dxiQxm2wFyBZwATlDX+LwdQzaF1B6x0slPN3KA1rg/RnLJGn5YsXlKJPooduWrhZm24RhK/J66SBqULLUoq4iF+Y2l/qk/WzhIRjo6zbutr+h3z+h2ivRu7jPg0FeCop9svAMVvhW4/qOZkW2sc7phsg1UIK78hXtEukzPUB2II= 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=AR4aT02T; arc=none smtp.client-ip=209.85.161.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="AR4aT02T" Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5f22ea6d874so2247113eaf.1 for ; Tue, 03 Dec 2024 13:20:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733260823; x=1733865623; 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=8ac3SDhZgwboifbpkv9WFxBdAVzUo9z6wiYYzPt9fB0=; b=AR4aT02TJkCl7TZbBkxYTst8fo2qkgQjde1s2ADTzzrdR6VZnOj8Y8kS2C2EJgYq0X 52Z4yryiwUacuZHQ2t6LsBHj0OilhfNTUCDOvCBM3ks8V5Q9SfPdV5LRrT6dof8MmPMj CnEc2OAFM20yjR+L/1kUb0V24yMi9I4uzZYIQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733260823; x=1733865623; 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=8ac3SDhZgwboifbpkv9WFxBdAVzUo9z6wiYYzPt9fB0=; b=wkmCuNn2U1Ab/Can7hT7954vr/Y8QyV237bNNsjyh29dkDlu0DAC8xRPKHVXcaJbik 6A1NxqP2BIja4ne81RUY0M+pLuxZ8MwLpfoU9ctZ4WLPLpJqZftCpYTA9MeO0lDP/A1V tdtVKQiX5N+x37H1c/I8eCj9BqHkT1H5rakxU3e6Bx/0EqDFkK0wjEaADOZVgvBJ3kxg ST13v1gGEbBesOdAOKqlBe6WbSDTNdFgn0wYeIJLI5fddpSmA7LDHdSayWcbnPMaSiLn eQAbCBZqvDxgvKTj0Fp1dwSjgDQ+c1ricUg0Z9FbEuJxlkTzernTCYsnHLcVTNxPUlgW /jYw== X-Forwarded-Encrypted: i=1; AJvYcCUvwaCGdqWGRedQXxu48VeBF23a/d96TRESCgZPoVbGxv3ofweqqfiBM74prWPKMr+im6ZjIH8PXtTuzA==@vger.kernel.org X-Gm-Message-State: AOJu0Yy/GD1ndS0D+CMAjXdv1QLqSgcV493BGecV9klkgoyUFsHWemCP h8fexdPwGt68PtMFGB5R0gO/4xYq9/R0oIJYclYPDA5LgzDhQhwihDYIvDN2Pw== X-Gm-Gg: ASbGnctFG+kQKTRs5M6F9D4fmQjSj6jRiLokyDjRLKhveSLtqDeF8pRQ1rtPGOswt3d rJhEzWxqbxowJCNVXEGaQOXT9EfsOxOtGRSxDyySasQsA18Q+Zs7ctnojF9hz/UpUKkzsMzkCwM IkxqUUkRyUj/ZqdrLPKtIxCx4EODBp3fN5zQ8KbnFcKob+LT2ULh37HBlh5RgKntS7dtgk9b2oZ lbAHcKlYM/93a3kPg9D5TGsRj22MWF/CITyJ/v7Bh6hhLhR7buncVI05TEszuJe5juR00BUH15I lgv1CtfK9KxsWJhRkgJxj09G X-Google-Smtp-Source: AGHT+IHGHLmqOEE6bDN/rik+bHTtTVn/fqIntJnNo8WaDnRDY6V/anFIBM7Fu6XvZHT/7pziDCMZzQ== X-Received: by 2002:a05:6359:7903:b0:1ca:a437:3322 with SMTP id e5c5f4694b2df-1caeac0e68cmr447232455d.16.1733260823542; Tue, 03 Dec 2024 13:20:23 -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 a1e0cc1a2514c-85b82a89d5csm2140364241.8.2024.12.03.13.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 13:20:22 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Dec 2024 21:20:10 +0000 Subject: [PATCH v6 3/5] 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: <20241203-uvc-fix-async-v6-3-26c867231118@chromium.org> References: <20241203-uvc-fix-async-v6-0-26c867231118@chromium.org> In-Reply-To: <20241203-uvc-fix-async-v6-0-26c867231118@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") Reviewed-by: Hans de Goede Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 58 ++++++++++++++++++++++++++++++++++++++-- drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ drivers/media/usb/uvc/uvcvideo.h | 9 ++++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 42b0a0cdc51c..def502195528 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1579,6 +1579,40 @@ 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_fh *handle, struct uvc_control *ctrl, + struct uvc_fh *new_handle) +{ + lockdep_assert_held(&handle->chain->ctrl_mutex); + + if (new_handle) { + if (ctrl->handle) + dev_warn_ratelimited(&handle->stream->dev->udev->dev, + "UVC non compliance: Setting an async control with a pending operation."); + + if (new_handle == ctrl->handle) + return; + + if (ctrl->handle) { + WARN_ON(!ctrl->handle->pending_async_ctrls); + if (ctrl->handle->pending_async_ctrls) + ctrl->handle->pending_async_ctrls--; + } + + ctrl->handle = new_handle; + handle->pending_async_ctrls++; + return; + } + + /* Cannot clear the handle for a control not owned by us.*/ + if (WARN_ON(ctrl->handle != handle)) + return; + + 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 +1623,8 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, mutex_lock(&chain->ctrl_mutex); handle = ctrl->handle; - ctrl->handle = NULL; + if (handle) + uvc_ctrl_set_handle(handle, ctrl, NULL); list_for_each_entry(mapping, &ctrl->info.mappings, list) { s32 value = __uvc_ctrl_get_value(mapping, data); @@ -1863,7 +1898,7 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev, if (!rollback && handle && ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) - ctrl->handle = handle; + uvc_ctrl_set_handle(handle, ctrl, handle); } return 0; @@ -2772,6 +2807,25 @@ 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) { + if (entity->controls[i].handle != handle) + continue; + uvc_ctrl_set_handle(handle, &entity->controls[i], 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 07f9921d83f2..92ecdd188587 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -337,7 +337,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 */ @@ -612,6 +616,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 { @@ -797,6 +802,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 Tue Dec 3 21:20:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 847160 Received: from mail-vs1-f45.google.com (mail-vs1-f45.google.com [209.85.217.45]) (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 515DD20B803 for ; Tue, 3 Dec 2024 21:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260830; cv=none; b=GF5b/pWZAUO5a1026EKFHNt7LvwF9eeziJIcD7h905Jo2jPA7iMfdvInuTcrpRgRoalIN5OcWzlvqmuiPoBGGODqq5tJMkvEozlxxygYOZ5rI6FjHbM0VNp+Bttt8qEnVXV6bHeGZEnCWHU7xH8q/nKHL5eY/ECseGRGwKUH2qU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260830; c=relaxed/simple; bh=9X5eIMvV46W8qWA8ZhdVfchZUxJMWj63sIIb96EFcB0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B4o1QZT8QiOlyxCWDWIW6jTWZWdzluF2xICk1wphbOPB2bt1/KYp3vjlN5fzWII4FKJezjSIDnERNokTx+VOmWjkMjzy5nBHlJq1OcGGptxqXCNmMdwGvvDsPCYUkz0+8rYVRV3k7KabeZlLSFsY/kG8hQr4sBPG6TiIMeuZiTA= 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=EHUBukod; arc=none smtp.client-ip=209.85.217.45 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="EHUBukod" Received: by mail-vs1-f45.google.com with SMTP id ada2fe7eead31-4af09420293so1910804137.1 for ; Tue, 03 Dec 2024 13:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733260828; x=1733865628; 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=1uy+WksCKY0gvDpLPtmZnEMUkklb+4A0f37uyRA+CFY=; b=EHUBukodyLCUlXFgla1ljTvMtqfT0HDw6Pqn1Ma+XA0lgBvEOPgeV+itcdpTDLE3YD ja81cqalQCJJmOYm17L6Z05FtLHpk+FdjQwv1XJqsGWRAqIQC3U4l4FdYXaGFjE0Ftgb dTETW7f1RH0f89JDYP/abGa66MrTx2UfDocoI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733260828; x=1733865628; 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=1uy+WksCKY0gvDpLPtmZnEMUkklb+4A0f37uyRA+CFY=; b=IHSP22MSB9hR/VlGDM9ZGYNBBea/sWl2cw52iJElK29g+TGpxiPiMbf5XoAqDCJmfg gbv5S+hzx49sFZmEL8yFODkf7skJbaQUbRsuF+ZQFv/xDRzIFvjnAozQaOxFAPTd8ytI r3ZHeNRlEwFLU/NFSuKwpXlYpfAR9QkUMo7xtopMQWz82TgPEFmrml4ET6F7erART3HO FZHWPdnYoRsNweJ8XiQE9R/ojFamD5gbSPvhLcAHGPmfQGPLQLV26i3lW5Jb62+PlkmJ PgQH5lMuqdA8FwbzwTQdGcVUwcP+kYUwkPHLQmn8sQ59JBkRIUH6dE0P5fA5mF+PUPB5 vqqA== X-Forwarded-Encrypted: i=1; AJvYcCWLQdFowPB1s255wLdN8ECgWtdOHWzVgvs8Vs/X/d2FWTg/OM59SBuf2mLAYMz6M8fA47SBwcSVRH3TAw==@vger.kernel.org X-Gm-Message-State: AOJu0YwpZ/mXtKPsE7hVGwlcx6O59P0NwCnqHyMBJ670ihqTS0pHs4NH WsXOnKioRh7EFlLPhi82LfbnDXbw5B57IuGqDua37rjToHAbwONwtlj2KKktOA== X-Gm-Gg: ASbGncveFDAXe5RBzpXqsuBoDrN0pMqe2L3Nxq/gaaDYQnug2AyXhJFIoC+gCMONoP/ 4ke3CZ4r0XQgTPKSE+ktJhEFaZH/MabSJM7WSFItApAD/s7P2zuSk727KcUZXESzCkXpGvBObL0 iXw3v/HFiHavrhxmjSHUey7KEPxh01yIEA5Y/bazJJOypp2OZfGSh8uTg9x9DTZCYPzgLu+hHAl fT4oDs0FjfC9pHvy+spCF7zor6ZHg1vgLCeklXNJpEdz5dFSGlurE2tPnolCf83iB4UntoCp/YR CxYakP2wgOiS54DQJSDYEB8x X-Google-Smtp-Source: AGHT+IHRabdBjEHecDYvRcDdxhxnXbNb23cpwrgd+owBsDEQqOzvydhJ6thhewZyJGu/Nbu+3cfgmg== X-Received: by 2002:a05:6102:9c4:b0:4af:5f6a:e73f with SMTP id ada2fe7eead31-4af973111b4mr5826942137.24.1733260826831; Tue, 03 Dec 2024 13:20:26 -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 a1e0cc1a2514c-85b82a89d5csm2140364241.8.2024.12.03.13.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 13:20:24 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Dec 2024 21:20:11 +0000 Subject: [PATCH v6 4/5] 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: <20241203-uvc-fix-async-v6-4-26c867231118@chromium.org> References: <20241203-uvc-fix-async-v6-0-26c867231118@chromium.org> In-Reply-To: <20241203-uvc-fix-async-v6-0-26c867231118@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 Reviewed-by: Hans de Goede 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 def502195528..3dc9b7a49f64 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1981,6 +1981,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 Tue Dec 3 21:20:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 847501 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.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 0BBE820B80A for ; Tue, 3 Dec 2024 21:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260831; cv=none; b=sjCrkDOhSwBkR4aLwh/u+FpGe8kQ0wG212ADqwbfaawv6Ja6/E2reWWBzJDpTEiAeDfLf8/l+r6LVmj1zD543K5A00mD3lqxwnDpCmYvTHSx4UEibGhCRFZ9WjzrCDFmfBoPy9sQkg8lxvGzEqxG5fl+OPAF0iEXieiV969cDRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733260831; c=relaxed/simple; bh=jFTBG9LprJIjbHQlM1I0RJN2j3CUZpzoB8yyx/zxbSw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fEjuKvMGwLXiiZhvrCJKoNa0jAfVmzNVaKzqFJgmyorEIdO6gIIMgASq3lAWEfKw7ssLfFLIyT7zAf9r0rrSRpzT+TCZwe6xpt1rgPWKZRoqeugqnOQFUAnFTVs2ciSPrypHMaH+w10bvMn2o634FGbKhJIuUS9udbZ2dg+SCwg= 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=LyCfcK68; arc=none smtp.client-ip=209.85.210.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="LyCfcK68" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-71d5af465b7so2644319a34.2 for ; Tue, 03 Dec 2024 13:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1733260829; x=1733865629; 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=zLLkfyeupXOCJEsbtIiRnjf9v6qN6z82wPD/jzcKBAs=; b=LyCfcK68f5N6DK8XS3wwSUe+nlKahIqetZ+9qL/+vkDYLNgYksRTzeJvB2aNRsYtko 4dvZu9OcRJhgIUngglhimUfE2S6HpL2qRnQG3de59EpLklP/DcTyNcJpnkNRH2VPYDfz GrJiJreNnCvDuXZ9iuCo8GlHhGX1oQFHHxHK4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733260829; x=1733865629; 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=zLLkfyeupXOCJEsbtIiRnjf9v6qN6z82wPD/jzcKBAs=; b=bUzZfh4FXbW4+8Gvb1VmS1QfyNhOI8hmr9mG9sytO45rwT6Wh+wwfFZ2sgZ/1IsOus ciKcAGYJvsQ7qFs/Vdj4MGMIH8pYXTNyhMEPhxzL7xZ8x0WXh+NF9Uc32vMjFffyKKWu 4Oubs4y+rwzgant7eB6ZAv/n6tM9xE2TA1/n2sEJSILTVEFwcSS7RYdaBdvOqYtBLmqN MbbI8vX4tDV+zKvWNXhBzi//sk8KEVa/jbmmBab331D+ij8QkxO31tJpD2nHOKuH+3pJ 9EFAMCiuJRzxEKCmLnxQ0LtuQgrYBjdyWNGz+RBwPZTPrwVnr4SOaKIObYUUYpOujazz afwg== X-Forwarded-Encrypted: i=1; AJvYcCW3tmrfk+CzyKXesbpuMfVNNpLEvIlt6oZL+nEAAhLE5ElsO/OZpOi/XEs3sdNGarfHLuou/0k1fcsbJw==@vger.kernel.org X-Gm-Message-State: AOJu0Yw1LaJ4R7dfsHEdDLYMTQ2WI7ILG7iimrM6Ei3rstTJIAmweoeN Eg04qzoUprom8fDmSTcMAHDLpC9avR3TS6le02N1BwM7LnOhcbPtaW6OGrkgZA== X-Gm-Gg: ASbGncugZOYISVAdO3XNHTiMfupkzGYTLNVss8PUqAnsWSq2Xa9VDmBtD3aTH9ocqcm e31U72TXz/z0w2A7n8jfwillf6ItOi/BcUTZxXo2zBJRRV5Yhq/OTH9JcpfyGAe9UHFmfZQu2mx 4H0AEZp9Xo2Zm1riSOvjFJIr2VPJufMAlfV0IMdJLFco7iA8bPhSNC17t6u9zixxGZ2zSMaDkHv yXYB5cFqKoSMlpwTc0u3LoN4GWdt8OkVonKgvME8jHYuFlr8oiXO5M+oaOLlHXK2UhvN/DRn5aP glS0KNypZTDKe2P0DdlGlEaD X-Google-Smtp-Source: AGHT+IHXPcyq+8B+KJ1dPXvdy3NU/VpWuqhFh2jcwyvKYbPbXmP0jy2dIclUy4Dce3/3CyVeNJ8Jdg== X-Received: by 2002:a05:6358:5bcc:b0:1ca:9660:67db with SMTP id e5c5f4694b2df-1caeabd17d0mr509285255d.23.1733260829162; Tue, 03 Dec 2024 13:20:29 -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 a1e0cc1a2514c-85b82a89d5csm2140364241.8.2024.12.03.13.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 13:20:27 -0800 (PST) From: Ricardo Ribalda Date: Tue, 03 Dec 2024 21:20:12 +0000 Subject: [PATCH v6 5/5] media: uvcvideo: Flush the control cache when we get an event Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241203-uvc-fix-async-v6-5-26c867231118@chromium.org> References: <20241203-uvc-fix-async-v6-0-26c867231118@chromium.org> In-Reply-To: <20241203-uvc-fix-async-v6-0-26c867231118@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 Asynchronous controls trigger an event when they have completed their operation. This can make that the control cached value does not match the value in the device. Let's flush the cache to be on the safe side. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 3dc9b7a49f64..db29e0e8bfd4 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1622,6 +1622,9 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, mutex_lock(&chain->ctrl_mutex); + /* Flush the control cache, the data might have changed. */ + ctrl->loaded = 0; + handle = ctrl->handle; if (handle) uvc_ctrl_set_handle(handle, ctrl, NULL);