From patchwork Tue Nov 26 16:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886167 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) (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 D0CFD1D8DE4 for ; Tue, 26 Nov 2024 16:20:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638029; cv=none; b=kR4nC3vAo60O1iCf/BS2nyrT3ffJbLen5CPTwXCDZS3umyuQd4jQ0leepIkZsWw2twT65gUAI3W7thuWx9E1eYoNx/vXwDsJ5i9e6k6gUZ1MJOH1muc2zNbe9C0u7xV2UPhLOUgSogvtQ7H+gW8a42g3nx95HhCKWwrQjZMsrp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638029; c=relaxed/simple; bh=P7cJDdqJWrLuL8K2uEZRvjaoWn4MVm6+xAAkGWyiVYg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SfupTq2t2Z2fYSyx1n73qk4jee3tkjp66ql9A6WP15nqM6hWHPo68p367L8djdYCp1kBMYaMJwk03F3RY0pr6OZwQBicyK/lG+joNiSGf/dLv2KEIy1cKssgY5As08ijdY4G/AoyybkLiqq3ugwTLPZw14ISdpZB0mlCqfAH7Dw= 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=cgn8Km/S; arc=none smtp.client-ip=209.85.167.174 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="cgn8Km/S" Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3ea60f074c3so383959b6e.1 for ; Tue, 26 Nov 2024 08:20:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638025; x=1733242825; 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=HKrUO2mKilVMnb8uGrp8DPUwicBtZJtjKmdkARmt5l4=; b=cgn8Km/SwG/fy7Su2kBHmgQdxp4jgrnKQwgxfpOGNl+ypdIaiXrPknhCQbvMIZTfJt R/a0qS+xkU7kokODG50CKAm8vWLzvpdd08E7KhjxJu90MNRAOdLwjmZpuMmjCvI6v7Ao Ygjfa1A1G1bBqu0wWOTFffn5hwQpFNco8sVeE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638025; x=1733242825; 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=HKrUO2mKilVMnb8uGrp8DPUwicBtZJtjKmdkARmt5l4=; b=HQ07N7JxJYVNYsF2AmYm+aJbHH+bRYW1D/tacUFfqpJ2AAhuwsK8fdWmPzmxIWRRg3 GDgOTvusB1thTDIWiHQEw830oNbyV3/SKzc6DpGOFkDMdJTZaaDikeixXOkP9CVpze8H w83BX4XPwSdfLHJq5PkBqdraDozMW0wZdmNHNCL/UK106qzmOCTPcACVKCkhFEHpgYQ/ H6hDoZy8lASr1xxQA+csshKcQrUQW5Yw61s0XpvysUGNfh/Hfs0oHdPUdEXUompZ0K2k MSRK0elq7IriRPheCbSMH+rF49MRuWEN89dGkt2DTlk2ad4eIl5m0UEfc0QGWC/+1NR/ 5IHw== X-Gm-Message-State: AOJu0YznQpuOjlJ04QRIdwIz3edlQi7uBK3HFn3rtDQJ12DKbUt+Mref wz8YbFLgGG84Jn55iqstr6h/SOJFpimty1awPrtw9pkL0EFZjtBPXe75WKjp/Q== X-Gm-Gg: ASbGncvlVstQqnrueJPGHQE47eYw2bgki4tJD8veH+HnyYIxon+5rk/F9tbN5OA09VL c2OL1FStRJykZ/SMGEj50TFs7TZXnzJBxEWHbsNqShBYyb8fKLpYQqys+xF3GtIcdsb2xqOzCg2 ZZesVurwum9dbWkoiDTSz7emgchCuGHcDpyDYC1bFQ1XugBbSvKJS/wv/i8fTOcURaq0BCiFe0a ulu0QzrnoOYDshgp8K2yuHfBBs8VKMJIqwoNFPz9ki2sH4qjkYpUXOETBlZuDIsRKMzRxuNorHa htX/sqmqB/1UP+9gqDGalb7q X-Google-Smtp-Source: AGHT+IFdNgRDGrF5CTdu4yR9Csg3r8Ps+A7V5ZKG5GFvlDcY4AMEGEJVb3A2Xw6tVAlAoAPaVnBh7Q== X-Received: by 2002:a05:6358:52c8:b0:1ca:9839:5d09 with SMTP id e5c5f4694b2df-1ca98395ef6mr446689555d.8.1732638024799; Tue, 26 Nov 2024 08:20:24 -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-85b4e8205fdsm346532241.1.2024.11.26.08.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:24 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:51 +0000 Subject: [PATCH 1/9] media: uvcvideo: Do not set an async control owned by other fh Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-1-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda , stable@vger.kernel.org X-Mailer: b4 0.13.0 If a file handle is waiting for a response from an async control, avoid that other file handle operate with it. Without this patch, the first file handle will never get the event associated to that operation. 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4fe26e82e3d1..5d3a28edf7f0 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1950,6 +1950,10 @@ int uvc_ctrl_set(struct uvc_fh *handle, if (!(ctrl->info.flags & UVC_CTRL_FLAG_SET_CUR)) return -EACCES; + /* Other file handle is waiting a response from this async control. */ + if (ctrl->handle && ctrl->handle != handle) + return -EBUSY; + /* Clamp out of range values. */ switch (mapping->v4l2_type) { case V4L2_CTRL_TYPE_INTEGER: From patchwork Tue Nov 26 16:18:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886168 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.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 9A70F1D90BD for ; Tue, 26 Nov 2024 16:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638030; cv=none; b=iwzb9qveX7zI3n58IE6WbsQLd6Bz27Wgc1GddR1UZNnotOAXXwsdxu8aKi+OQSP2oRg1S5fuZCU0XjQxEyG1nzO9dp1hsXoMXtvQjqu2uTqXSvWYBsFrMONk3uU9LZztgAleSCgw6Zqiz9mTH3DH7WeVnNr/OJwVI8bHK1gxvEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638030; c=relaxed/simple; bh=bePKgiLEtOHWWqdfEmU/XMv+SebhE/yNQeG1T0V3x24=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C+g9HQr/+hDutSLY27X6KxyC/kSfo3vurgoDlamWjeEUEgClc+ropKa1ApmRW4CO1eyrP636cgtfcqmwjfQXUyJJxH6qYc1JotrHXvRExa6a9ZaYhBniMFp73NMaAmHc7W5U4QUvMf/+Z6HUvyUCiLowDHFZCXOFz+2b6HVd1/Y= 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=n1pC5ZRk; arc=none smtp.client-ip=209.85.161.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="n1pC5ZRk" Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-5f1dc7c6c67so1109274eaf.2 for ; Tue, 26 Nov 2024 08:20:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638027; x=1733242827; 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=wWYCqdEsM1ywI2Gtcd8gKpH4aZIyvZJP5EwMGSKse/E=; b=n1pC5ZRkKg5+lJn6bXhLCgHK5vlrNXDky9eTBqNcXFgaLWiGc1qt/AJNdhX532ie8B J829HiOfuWSQwRcoI0sWJdPHYh4Cv3784OpX7uPAWuFguf4tGNvYrnz3Fb6AhtjefNlo iZCRXARmquTkCxhHk4Ff8nClZCF7S6MRVRf9w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638027; x=1733242827; 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=wWYCqdEsM1ywI2Gtcd8gKpH4aZIyvZJP5EwMGSKse/E=; b=peIwIIlSRIqu6wL/+VfbA+ryyMeOjiYanikhIa3EAn7oeVJpMbt12yTMn7IYX6nF43 kq1Q9/OHN0Ge7Bd1bb87BKy8Qzbw9k+IHcQYTkE7Mpl14m/wqaOqOUxAqZKzk1n8O7PZ UibY4gJiRQbNhyEQHLj49suVZlMk1H5r0oCtKJyDLHzhbr3QR7WOgNXZXG/qL77YmwDh Z08FozyJN/6ioo3z9MthPD/W01XDKjgtfoGtvQJ+TXqIUWmleQBZRGw1OiKXhLypHzDh 6j2OZFSQdIkmZPhM9fCsvB3lgQ9x1o93j1LoYlO9Z5yUIGGDqtY0f+oOad5JHsDNTpZo 6SJw== X-Gm-Message-State: AOJu0YyWR7C6lS+VOi+GOgdpoKuW3KPWzPJYr1pKfLSCd7kZ6fSfZF8G fZRhK3zqdC2hEKIRdizb9yz5pUXtLW1x9hdHQjkagME00ez/VppD2N94IIljeQ== X-Gm-Gg: ASbGncvm5S+EmXT4yzNqHQrbzZyLscfPPjUWQy0LoNLwQIvhvlzwTUdmsIyjGKRpe93 gFDxoEqUI8ZAqP0lfhJyjruYd2kgPpDQlt/QNXxOFNi5daH+bjO0EPn1t8JEYav+oy2IUonYYpM uiIujqFzzzrCYO+Hz/RUE0hARA79G5dSocvLI+BvJTOPnfoLP11rH4JXNyIadbflFsnwbdJumap bvG0GA/DoOHLrtTQSHIHDxMvKAtgusIxvHLfsmJ3QT7KHGt+/unVRIgODoS8niwsdkR49p956Oz yJYB/Ui4DselV3ik2jXuUF+7 X-Google-Smtp-Source: AGHT+IFP7tn9XGl7nTv1mz1ZVEhZf7iMYG/c3Vw4razkI9b6q1iBbwoYYcil2Tl02KVex3tVQ1+aRw== X-Received: by 2002:a05:6358:949f:b0:1c6:1d18:7c44 with SMTP id e5c5f4694b2df-1ca79708784mr853391955d.6.1732638026153; Tue, 26 Nov 2024 08: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-85b4e8205fdsm346532241.1.2024.11.26.08.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:25 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:52 +0000 Subject: [PATCH 2/9] 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: <20241126-uvc-granpower-ng-v1-2-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , 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. Keep a counter of all the pending async controls and clean all the dangling pointers during release(). 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 | 40 ++++++++++++++++++++++++++++++++++++++-- drivers/media/usb/uvc/uvc_v4l2.c | 2 ++ drivers/media/usb/uvc/uvcvideo.h | 3 +++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 5d3a28edf7f0..11287e81d91c 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1589,7 +1589,12 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, mutex_lock(&chain->ctrl_mutex); handle = ctrl->handle; - ctrl->handle = NULL; + if (handle) { + ctrl->handle = NULL; + WARN_ON(!handle->pending_async_ctrls) + if (handle->pending_async_ctrls) + handle->pending_async_ctrls--; + } list_for_each_entry(mapping, &ctrl->info.mappings, list) { s32 value = __uvc_ctrl_get_value(mapping, data); @@ -2050,8 +2055,11 @@ 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) { + if (!ctrl->handle) + handle->pending_async_ctrls++; ctrl->handle = handle; + } ctrl->dirty = 1; ctrl->modified = 1; @@ -2774,6 +2782,34 @@ 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) { + int i; + + for (i = 0; i < entity->ncontrols; ++i) { + struct uvc_control *ctrl = &entity->controls[i]; + + if (!ctrl->handle || ctrl->handle != handle) + continue; + + ctrl->handle = NULL; + if (WARN_ON(!handle->pending_async_ctrls)) + continue; + handle->pending_async_ctrls--; + } + } + + 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..2f8a9c48e32a 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -612,6 +612,7 @@ struct uvc_fh { struct uvc_video_chain *chain; struct uvc_streaming *stream; enum uvc_handle_state state; + unsigned int pending_async_ctrls; /* Protected by ctrl_mutex. */ }; struct uvc_driver { @@ -797,6 +798,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 Nov 26 16:18:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886169 Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com [209.85.160.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 2BDFF1D9346 for ; Tue, 26 Nov 2024 16:20:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638030; cv=none; b=TV8YIHf1QIAqRGUKI1CGSZP9hsdbupkVivC2ynn67rxIE0y3Ts1UjCx7doz/Lsf8G/Qw1xT5czvXtFg+XM4e977r6bIsX8NuQrehgbrNK33eDfoH7qZPen6cnj38j6l7di5diKBlMNbnDyiI/wffNjdlHBekawHAfdeuPB1wQMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638030; c=relaxed/simple; bh=+QRDEeTl7+1Tb8QYvDBOC4J4A2Fgnf7J9axjy/zTuzI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YbcwzXzne70Wo7hwT8nie3om4cT6ZB1+oivrMKL3Ghpi0mA9mzNvFFSRR9Fa2d+/yuk38HfXE/PwaD7UgZvrHo+yYdN1axlK3DEtgfsbB8Ws6BT+awYmO1b4Rf8nYRf8Gd/CiHjwRnA/xw4+lwHkJ9kP5+F6wSRrnk5P2E4ey3g= 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=SMqT6XFK; arc=none smtp.client-ip=209.85.160.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="SMqT6XFK" Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-29685066b8dso3294972fac.1 for ; Tue, 26 Nov 2024 08:20:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638027; x=1733242827; 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=7Ec+aWUlYjfVkeFGABKzygP7a2zM71aZZNNdskYbc+0=; b=SMqT6XFKwwx794539RRBfMKLXbV11L7MVNP7bWUF5I7VzK0PNRKuMvfe7a1x5jfgYg /2I1hMC9l/GPsru1DjVWWMXayn9szsU3SKOLa2hGzrVIgTrN/21E9cOEwV+3nxAe8cfu d52t5c7Hn90hzeiYgqW/3e4fbpmBMcwagokxc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638027; x=1733242827; 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=7Ec+aWUlYjfVkeFGABKzygP7a2zM71aZZNNdskYbc+0=; b=P1tSN6M+pZD5jgI62bSDBpaoAWHHELf4rOPMjMjX2uyFUFr4fuwf90eVxgBK4khr91 QKEb59EyXnDQMCZAMyox+q7tNFTg04yDN2BsAdBo6aXZetrL6OY4oDzNZkcPWbiGcJAg VOzqfLbLaSjlRW0yIsgsg7kqdhJM+sWI9W3KjW2y19K34LkiR/DC7CVvXdySsvEJy/IZ H7ifUgMubMtiMBxasFeA5SCfabOJ/pLtozciQjhAZvpLFrYxoWk+hy4TD2+qBp9mTEPR X9YwkpNTQZbX0Te7gwS1jHbY6I1jzGOKxONLXq3lYA2feFzObju1a2EJZoPaVe6ctazq OlOg== X-Gm-Message-State: AOJu0YxfqDQD1+bYP05ISUsp7boONdJJxja2cq3seWpU5OSmdH9No8dK daEQHYNQ91hx/TERSrvz4xxwi5uEP9V79MtkeU5WwAR2rrB03zLmb2snbfBplg== X-Gm-Gg: ASbGncs9h1JJWO8FWvBgil9NOSjpkpLFiBXmul2egQVDxI8x9GNT1iKo9IWmAu2kgOg 1Axrv5xaJxDZKPFz92WXU3ZCvWBjIWcqnO9ZIxTwOYx6bHUpnYOLVPj8dQ9wGUYksmqqz94wORT ph/qG0oY8mtaeX0xRqDmsSLqmtaslGUB1cFAb7agkIOJIH8hkBS6PreRC0leoktf8r1GsCCx3dX tpE6wP7K7zpOk7Xf8O5cPUwizSPKNexUGPTvhiM3/vbxem4VJw+nYYkgo0A+GxB2EBDibBq4EOJ ZMZmOVyWDOMLA4irBj4Kvm6s X-Google-Smtp-Source: AGHT+IGTu9xdPCRBJlFbRHegd6Xyp4UDrX/YIXUIDxaC3+Jb94GTMDjckF9lM49VwilT9480EVlfVg== X-Received: by 2002:a05:6358:d386:b0:1ca:90da:3c1e with SMTP id e5c5f4694b2df-1ca90da3ce2mr516421655d.19.1732638027057; Tue, 26 Nov 2024 08:20:27 -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-85b4e8205fdsm346532241.1.2024.11.26.08.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:26 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:53 +0000 Subject: [PATCH 3/9] media: uvcvideo: Keep streaming state in the file handle Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-3-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda X-Mailer: b4 0.13.0 Add a variable in the file handle state to figure out if a camera is in the streaming state or not. This variable will be used in the future for power management policies. Now that we are at it, make use of guards to simplify the code. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 15 +++++++++++---- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index b425306a3b8c..712a531e52f9 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -888,11 +888,17 @@ static int uvc_ioctl_streamon(struct file *file, void *fh, if (!uvc_has_privileges(handle)) return -EBUSY; - mutex_lock(&stream->mutex); + guard(mutex)(&stream->mutex); + + if (handle->is_streaming) + return 0; + ret = uvc_queue_streamon(&stream->queue, type); - mutex_unlock(&stream->mutex); + if (!ret) + handle->is_streaming = true; return ret; + } static int uvc_ioctl_streamoff(struct file *file, void *fh, @@ -904,9 +910,10 @@ static int uvc_ioctl_streamoff(struct file *file, void *fh, if (!uvc_has_privileges(handle)) return -EBUSY; - mutex_lock(&stream->mutex); + guard(mutex)(&stream->mutex); + uvc_queue_streamoff(&stream->queue, type); - mutex_unlock(&stream->mutex); + handle->is_streaming = false; return 0; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index 2f8a9c48e32a..b63194a9c64e 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -613,6 +613,7 @@ struct uvc_fh { struct uvc_streaming *stream; enum uvc_handle_state state; unsigned int pending_async_ctrls; /* Protected by ctrl_mutex. */ + bool is_streaming; }; struct uvc_driver { From patchwork Tue Nov 26 16:18:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886170 Received: from mail-oo1-f41.google.com (mail-oo1-f41.google.com [209.85.161.41]) (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 C4C441D9A76 for ; Tue, 26 Nov 2024 16:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638031; cv=none; b=llxrZ0B51G5T595L1u42ZhaQBmphPVlcDICtu0ljWlO8fglxcQN957QMs9gpANYAl60JQ2NWmALfcd32w3q2ZbAt+yoARFGE3BzNM8dY9jeJrqwJZpJtay/PpGPj807oFUMqu2jT1kX/AHtVNgMVYgrfYuW0PSmHkoI7Hx1xKB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638031; c=relaxed/simple; bh=fXeP6hP7d8DZLK/SqBOauBVNxZJD+zSrN3SPVgFuloQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AcVlpBsgBYRPLAMX9/a0UpkECIkgwUPMC8wYlnfYlqf6UBJCev9yR7e0Z1w70XYVTe0Dc+BGhHNTEwt6vdpAjnnplwJMCYvufzmILerbKYKmre4D5zm436PX0XZIgzFu5n0p2TnAOxkid3Yfc/h/mJ2ExKvUVubzky569s4rZ2k= 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=DmSxJ0aU; arc=none smtp.client-ip=209.85.161.41 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="DmSxJ0aU" Received: by mail-oo1-f41.google.com with SMTP id 006d021491bc7-5f1e573f365so898721eaf.1 for ; Tue, 26 Nov 2024 08:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638029; x=1733242829; 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=oM5gW83DYtkyi5mVaIPybDtzyFce7hGSIn88DXzP1bc=; b=DmSxJ0aUTJE88jjHa7rYqcK3D8fHKMEgdaV3YR8oskWrS11RSeRQYWYzOZ/WBRX95N PyGO83C/ye+5pnCOQn3iWPqqjatS2P4XoAnwIPHjGPqp7k9LGtP68FgfxYVvYDKYxIrY uNFjvv4zFtOuoXbIWeoj0KkmleYzwdqatjwmk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638029; x=1733242829; 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=oM5gW83DYtkyi5mVaIPybDtzyFce7hGSIn88DXzP1bc=; b=haa3kNxO4Oe6YiTJNM9CzTZKOtWRU6N+u0QyClwt/Pn9X2/polM4TF1K+dBhHvcVwl ia7AmpySiH3kL3K7bgYOQSXt1TOcVkR3C//QtRlkWjEOt3M5UmtZ0tYCLx4dl9V0UFYY WINqjaFT/Ql76wvkNmeXoUHEb6Xe458Ka/GfZUCR7W4YJeAO4UCZOx2je8Bal+F+desG 14y8+qtA/QDS/BVzmh4vZf+PW8lu0vqMaZU3hfuB+F/usH+A7nbkwQBaLbQUEPj4jrZ8 PbC1EYGM9PRZZI6kxBJBg3DaJhK81WBtUTHSGazHFB0u4LHAxXQ+XmZAtjDecq+d9X6t PK5g== X-Gm-Message-State: AOJu0Yznv7z/yg1UJaJLkhhXQ2px2BorBxrSejokpwm/RGW+Wf5Jban9 F6unBs1IQHFaaBvvnGnmQxFhdpk9aDKH/95zBoF9o5Mx5Q7kLq4NF3XHPD6OeA== X-Gm-Gg: ASbGnctR6TAM2kZpYE9F8yqDlOXtBoPPukeQXj3Jp70IF2ay8pE/B/IwNkARavBAx/h X091jI1H3i844d+rzYQb8PAoJAnCl1PaN0aE9F7xErSE9kmZ1c3Ni1NmJO2KSP1qx5jcDjnQGa/ pQVKoqjTSQZK0k/4H2ltE/vLMciw3nR7YXVdPkLntGzucO8bx4sI4TKZvuQ2jcOs3Ac0vlZ+6ab CMGrrvwp1+JAQhI+4loWKg50wM53WP2t7l5jY1P6oMzqXw69uUReRnVktGnLdV+K3kzVe6y8/qg syGcLbqWmzoTWgxclxGcWJrP X-Google-Smtp-Source: AGHT+IEx0/z2upzwZa1v2tR9ixIeTv9UvY1/QA26N8uIiVqTdq7qHENYY8qRduqIG+j0i0J9NC7t4A== X-Received: by 2002:a05:6358:5699:b0:1c3:84de:4d5c with SMTP id e5c5f4694b2df-1ca797bb7d5mr904727555d.23.1732638028680; Tue, 26 Nov 2024 08:20: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 a1e0cc1a2514c-85b4e8205fdsm346532241.1.2024.11.26.08.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:28 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:54 +0000 Subject: [PATCH 4/9] media: uvcvideo: Move usb_autopm_(get|put)_interface to status_get Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-4-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda X-Mailer: b4 0.13.0 Right now PM operations are always called at the same locations as uvc_status_(get|put). Combine them into uvc_status_(get|put). This simplifies the current code and future PM changes in the driver. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_status.c | 38 +++++++++++++++++++++++++++++++++----- drivers/media/usb/uvc/uvc_v4l2.c | 11 +---------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_status.c b/drivers/media/usb/uvc/uvc_status.c index 06c867510c8f..f7531ed0fa84 100644 --- a/drivers/media/usb/uvc/uvc_status.c +++ b/drivers/media/usb/uvc/uvc_status.c @@ -378,7 +378,7 @@ void uvc_status_suspend(struct uvc_device *dev) uvc_status_stop(dev); } -int uvc_status_get(struct uvc_device *dev) +static int _uvc_status_get(struct uvc_device *dev) { int ret; @@ -395,13 +395,41 @@ int uvc_status_get(struct uvc_device *dev) return 0; } -void uvc_status_put(struct uvc_device *dev) +int uvc_status_get(struct uvc_device *dev) +{ + int ret; + + ret = usb_autopm_get_interface(dev->intf); + if (ret) + return ret; + + ret = _uvc_status_get(dev); + + if (ret) + usb_autopm_put_interface(dev->intf); + + return ret; +} + +static int _uvc_status_put(struct uvc_device *dev) { guard(mutex)(&dev->status_lock); if (dev->status_users == 1) uvc_status_stop(dev); - WARN_ON(!dev->status_users); - if (dev->status_users) - dev->status_users--; + + if (WARN_ON(!dev->status_users)) + return -EIO; + + dev->status_users--; + return 0; +} + +void uvc_status_put(struct uvc_device *dev) +{ + int ret; + + ret = _uvc_status_put(dev); + if (!ret) + usb_autopm_put_interface(dev->intf); } diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 712a531e52f9..1d4db712137e 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -617,20 +617,13 @@ static int uvc_v4l2_open(struct file *file) stream = video_drvdata(file); uvc_dbg(stream->dev, CALLS, "%s\n", __func__); - ret = usb_autopm_get_interface(stream->dev->intf); - if (ret < 0) - return ret; - /* Create the device handle. */ handle = kzalloc(sizeof(*handle), GFP_KERNEL); - if (handle == NULL) { - usb_autopm_put_interface(stream->dev->intf); + if (!handle) return -ENOMEM; - } ret = uvc_status_get(stream->dev); if (ret) { - usb_autopm_put_interface(stream->dev->intf); kfree(handle); return ret; } @@ -666,8 +659,6 @@ static int uvc_v4l2_release(struct file *file) file->private_data = NULL; uvc_status_put(stream->dev); - - usb_autopm_put_interface(stream->dev->intf); return 0; } From patchwork Tue Nov 26 16:18:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886173 Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.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 3DF051DACBF for ; Tue, 26 Nov 2024 16:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638033; cv=none; b=g3Sqq0GpOlLO4ExKrQ5f6uqqj4NsxOfdJeX2YGKywa+sNd8J5lhj5WBlGHZYCz5B+O4SGrA34X4Cavn+WXgSUVhQQAverhjkg1OJJVkWxGx3tIy+ZupIUc/EInojcDPF5YFiQCM/T4knawbRd8VdSwU4igBnS929YuYNJpEh7I0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638033; c=relaxed/simple; bh=HyqCzaymRik4He7GN3tEcdLeiRbjJnfCdIYBk4WebLk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FGADII4TbrGruShDBfTB6zcHpC4IMrweRqrnKGUaifHu9D1/m30VITF5u7zsLViBZwSsE69t0wkhvsNb8vomKLGC6encZPB9Kd/0156rrO9fLd1YvihUQvVDhJMsmWw/IIsjiRY5PkZ+r4VSv6aWw4FQDQGZMrIQK4ywDYscLAc= 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=HIvJtrmV; arc=none smtp.client-ip=209.85.161.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="HIvJtrmV" Received: by mail-oo1-f48.google.com with SMTP id 006d021491bc7-5f1cec20a77so1142991eaf.1 for ; Tue, 26 Nov 2024 08:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638029; x=1733242829; 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=oqSWPss0imTjEBvgoF+O3/N5JaCFfxEYIjh5jyzakaE=; b=HIvJtrmVAwGkxd67/HmMmk6/2TZfIMvu60ERUNIt/x1wZ7BQT1jFskbWfHuvlfgq/I TZP28N353+K2rKyksjfJw8qiCQAMYF7ONIpTTVJQx5eMe17xUb5iD9TIqaWdMd8ytU41 HkN+7IisnUfqA1uz4qlewA2na3kGXoIRonSZ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638029; x=1733242829; 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=oqSWPss0imTjEBvgoF+O3/N5JaCFfxEYIjh5jyzakaE=; b=d+5kC4B15cbuLYf+dx6YoPqaAVKWPDpQgStSlEdRBWCjT+eoICajALKEL/UAkwUTvh FNlgXwkm4LPr/Af95EiTBnVPEzFloM5c8p/ZegTlWHOM24GIR/ns+GP+mW0n4gslqwSD /DKKHL8Vz8+u8Zb24Auj61NbTSTdF4eiYpUv0h47wihQz5nlyPg+dMahIKYN+hW883BK FceXFYdcOrzWBmK2ZjMXwJ8wuIxayTCFcI9jkvsGZjQ6NY9E4KOLZ+RYWZEj/i662xoE 5XTZKSQj4QVjyn8ttfnEIisBY1PyH6CtWpeKLPAkCC5zVTM8oinou3cRVQ6GgIcbjRNc vWbg== X-Gm-Message-State: AOJu0YwT5TFfOR39oWTIpYjPIGJl/vFJvdqgMHjvw2fDpA9WJTQNKY2m bhjDu9SqhHNIu7I4BxbB4+60J1XH/9cOi1kGtfmikX6H3WDNiki8pdgzqwIK9g== X-Gm-Gg: ASbGnctn5yS9y/wqrZJsjZ3ovKpg3jRfg3XwFg2/Ut3xn1B9Ne3eX9T7Ejvdm/ddFXl miZxD7MpNYcswidKbIq8xZIzTC+dLCFu5ebxmWVKVHp435jjD7GZ5uLbvcFiM0l2HLoMGzM0VTW xJr/o2JT6rRJOYTHobLhhnU7UpPV+T1WbwJElEgE0CxnkacCAaVhPO1sXDUBpFJwHZMpEvSZNbt ts/YkOipG+X6Nm7OOI/6At/jRI2a2YsDyOyXpM3OEyRev2yfpQptPPuWydknPUHZ9StQG4VFVfL CNnomaeFtLmkwJRDv+85vQjt X-Google-Smtp-Source: AGHT+IFSeCLAxLBaIb6/TUqzxFH7lB3SI+CE6KSiFU+YQRWCA4HwT+r88u630f7asyH+jTHjbUh/lA== X-Received: by 2002:a05:6358:9209:b0:1b8:f18:3e6e with SMTP id e5c5f4694b2df-1ca79724369mr996360055d.12.1732638029389; Tue, 26 Nov 2024 08: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-85b4e8205fdsm346532241.1.2024.11.26.08.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:29 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:55 +0000 Subject: [PATCH 5/9] media: uvcvideo: Add a uvc_status guard Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-5-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda X-Mailer: b4 0.13.0 It helps will help will the error handling of PM functions. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvcvideo.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index b63194a9c64e..c38ddd10307c 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -759,6 +759,8 @@ void uvc_status_suspend(struct uvc_device *dev); int uvc_status_get(struct uvc_device *dev); void uvc_status_put(struct uvc_device *dev); +DEFINE_GUARD(uvc_status, struct uvc_device *, uvc_status_get(_T), uvc_status_put(_T)) + /* Controls */ extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; From patchwork Tue Nov 26 16:18:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886171 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.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 119D31DAC88 for ; Tue, 26 Nov 2024 16:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638032; cv=none; b=Ww8RugstalyB+3V0neo8i3DeoGuKiNpQPhc0S49+W1Y4nCGrKkUPSud9noBhKXZlXIU7SIpyf2V6glVjcG30aeQxS1jWenOSpHRb0A9VBj5Q4KmeP6RUXLSKgJYQinOFYo4z73OfTY1m87rxWSX+HxhOAM1LZzQvGEY0/FJpxIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638032; c=relaxed/simple; bh=IVh0R9nGIq7LQxrxeUzuHltM/Lda0LYF+qcuGJP4GWg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S/Gv0eLRxspbx9JnZsQTHVW0b08ZA8tblT6Qb/4GNSaO++Uvq1qcE6P7/UKi8cBNN4rq6oYAO2VkFd1oUd+2KepDtpiCSPvZ779Lf++j1v9mZNXyRvDljvUd6xcGRUTOrxtg19YFjy+UccIJ9/udyc90XxakTriFupGJkKosCdU= 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=oeuDtTxO; arc=none smtp.client-ip=209.85.161.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="oeuDtTxO" Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5f1f1da0c8eso1000704eaf.1 for ; Tue, 26 Nov 2024 08:20:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638030; x=1733242830; 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=85TfWs0jEmA8k141RAfWvOKiiPy4fhc+Ar2L/ksYixU=; b=oeuDtTxOIJIBx4K92ClrNlMWu7iquec/UZ3pJ8kc0qTwVYIkEUG0Cu1MHMh0acL9f3 Ue1sL9C3EL33xadY//+cwJxeb2nV9K4sIGmKK9dV0t9E5Y83WnMcJEIQiyYWuVjccTgB 853ZpEjLtXlyf9HSW3Cw0a0Zg3S1D4qE/tnyA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638030; x=1733242830; 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=85TfWs0jEmA8k141RAfWvOKiiPy4fhc+Ar2L/ksYixU=; b=QM5VAGq8fxzSEX4FtDxOMmr85miOsAl0lFE173MRm1rciRuSJC51kIr9AhgjnqyVTb Jtz5Y3zbX7enXDooza/jgE76X25bMIN6JsrbetBpAgW/1deJKTR4ceFjSzPprs0jIL+J W7tafJkgihiWhMxSA59TIyFYNhZYzR2+u8nQ15gSTQHQSi4XWl4j6GztOyM1wi3iBTjI BwFbguH/PJNVjtAN802xcXkDD56zvuWuFo4yYiKQbB/mTTFnThktrncBHFQn/PpkbgbR qYiTG3ifAfDIBpJ/l3QTKC5USvjj7yPGCncHx81+8u4rAF4j5HfEL722RmGnhz+L35dK G2gQ== X-Gm-Message-State: AOJu0YxBStHf4TptS+ifBfJugfSCNCYNeYYGrlfy54Tj9JUVgkAKj66/ nRnyGflhTaOrT1QuLR4vTrTLvcwCw95fLB8S+lerq9/Hp9/5HA2BzKokxKMHGw== X-Gm-Gg: ASbGncuJez55rO+l+A5sFTxoq2k1Anzq7dv4it6T1wQMFLHJMU2HqOOTuC9MEVPzFHY Evmsy0z32+6w9M26s6DoxvxEYK70ZIL/6V/IKQUof8skcQ+wPwEF0P4E1QG7TqS/56ErqfRDPYl CjH6MF3VTTSM3BnlGESdAixvuh6FUn0j4rxKQuB2BO4rkXhgbknTBlQvlLAAg1HY3gM0urOG3J7 +obFvRlCVoNqlTr0ym7cwzIf72ciMZ+vSAcxxV57thTllTI0JnYy7NbmGkk3YZH5WpnFgSGHTld CB4tbEN6rOrrWFPkZ60Afj4r X-Google-Smtp-Source: AGHT+IGHcqzY+WUpuzKBkzRidLiPH4hUJ9H+BZBkHvQLlWb2ivbtOxMoXrTejhoPwoNuH+vicDxvPg== X-Received: by 2002:a05:6358:988b:b0:1c6:204b:c5a7 with SMTP id e5c5f4694b2df-1ca7972f8aamr942012555d.10.1732638030198; Tue, 26 Nov 2024 08:20: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 a1e0cc1a2514c-85b4e8205fdsm346532241.1.2024.11.26.08.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:29 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:56 +0000 Subject: [PATCH 6/9] media: uvcvideo: Increase/decrease the PM counter per IOCTL Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-6-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda X-Mailer: b4 0.13.0 Now we call uvc_status_get/put from the device open/close. This low level of granularity might leave the camera powered on in situations where it is not needed. Increase the granularity by increasing and decreasing the Power Management counter per ioctl. There are two special cases where the power management outlives the ioctl: async controls and streamon. Handle those cases as well. In a future patch, we will remove the uvc_status_get/put from open/close. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_ctrl.c | 18 +++++++++++++----- drivers/media/usb/uvc/uvc_v4l2.c | 26 +++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 11287e81d91c..2e2aa1b2f53d 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1592,8 +1592,10 @@ void uvc_ctrl_status_event(struct uvc_video_chain *chain, if (handle) { ctrl->handle = NULL; WARN_ON(!handle->pending_async_ctrls) - if (handle->pending_async_ctrls) + if (handle->pending_async_ctrls) { handle->pending_async_ctrls--; + uvc_status_put(chain->dev); + } } list_for_each_entry(mapping, &ctrl->info.mappings, list) { @@ -2056,8 +2058,10 @@ int uvc_ctrl_set(struct uvc_fh *handle, uvc_ctrl_data(ctrl, UVC_CTRL_DATA_CURRENT)); if (ctrl->info.flags & UVC_CTRL_FLAG_ASYNCHRONOUS) { - if (!ctrl->handle) + if (!ctrl->handle) { handle->pending_async_ctrls++; + uvc_status_get(chain->dev); + } ctrl->handle = handle; } @@ -2785,6 +2789,7 @@ int uvc_ctrl_init_device(struct uvc_device *dev) void uvc_ctrl_cleanup_fh(struct uvc_fh *handle) { struct uvc_entity *entity; + int i; guard(mutex)(&handle->chain->ctrl_mutex); @@ -2792,8 +2797,6 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle) return; list_for_each_entry(entity, &handle->chain->dev->entities, list) { - int i; - for (i = 0; i < entity->ncontrols; ++i) { struct uvc_control *ctrl = &entity->controls[i]; @@ -2804,10 +2807,15 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle) if (WARN_ON(!handle->pending_async_ctrls)) continue; handle->pending_async_ctrls--; + uvc_status_put(handle->stream->dev); } } - WARN_ON(handle->pending_async_ctrls); + if (!WARN_ON(handle->pending_async_ctrls)) + return; + + for (i = 0; i < handle->pending_async_ctrls; i++) + uvc_status_put(handle->stream->dev); } /* diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 1d4db712137e..1972ede38c70 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -651,6 +651,9 @@ static int uvc_v4l2_release(struct file *file) if (uvc_has_privileges(handle)) uvc_queue_release(&stream->queue); + if (handle->is_streaming) + uvc_status_put(stream->dev); + /* Release the file handle. */ uvc_dismiss_privileges(handle); v4l2_fh_del(&handle->vfh); @@ -885,8 +888,10 @@ static int uvc_ioctl_streamon(struct file *file, void *fh, return 0; ret = uvc_queue_streamon(&stream->queue, type); - if (!ret) + if (!ret) { handle->is_streaming = true; + uvc_status_get(stream->dev); + } return ret; @@ -904,7 +909,10 @@ static int uvc_ioctl_streamoff(struct file *file, void *fh, guard(mutex)(&stream->mutex); uvc_queue_streamoff(&stream->queue, type); - handle->is_streaming = false; + if (handle->is_streaming) { + handle->is_streaming = false; + uvc_status_put(stream->dev); + } return 0; } @@ -1450,6 +1458,16 @@ static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp, return 0; } +static long uvc_v4l2_video_ioctl2(struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct uvc_fh *handle = file->private_data; + + guard(uvc_status)(handle->stream->dev); + + return video_ioctl2(file, cmd, arg); +} + #define UVCIOC_CTRL_MAP32 _IOWR('u', 0x20, struct uvc_xu_control_mapping32) #define UVCIOC_CTRL_QUERY32 _IOWR('u', 0x21, struct uvc_xu_control_query32) @@ -1464,6 +1482,8 @@ static long uvc_v4l2_compat_ioctl32(struct file *file, void __user *up = compat_ptr(arg); long ret; + guard(uvc_status)(handle->stream->dev); + switch (cmd) { case UVCIOC_CTRL_MAP32: ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up); @@ -1583,7 +1603,7 @@ const struct v4l2_file_operations uvc_fops = { .owner = THIS_MODULE, .open = uvc_v4l2_open, .release = uvc_v4l2_release, - .unlocked_ioctl = video_ioctl2, + .unlocked_ioctl = uvc_v4l2_video_ioctl2, #ifdef CONFIG_COMPAT .compat_ioctl32 = uvc_v4l2_compat_ioctl32, #endif From patchwork Tue Nov 26 16:18:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886172 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.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 217111DB924 for ; Tue, 26 Nov 2024 16:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638033; cv=none; b=gd4VLrhyEHwWpE+e4dc7f2WoJK9CqjPitu0kkWMeHI0kCFONvzTJ9hQo4VzN7R+Z7ckq8r3kyhHIYUjQo3SDQ5BzZz+rgC6iRa+sGCnVdT8SB3huoUYkiZrCbxmE4ppQmIUANUt51+BZ5dObPHiMga5Ho5wlVthV93NNMjs1GMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638033; c=relaxed/simple; bh=3Dzgzh4yU33ztM7bLdskr2zw4uRmtMH9ym8FV6irr3o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NLy7gEeQpmrzyAzwqOEgcsbf+kJTXprouS7IL0brANddVwYov2HJN7I3Tf7QCq5QhKdbKC1xs0UxE8FxKVQBZf7B6LL7ve1i1BuFgTCE5oqs4gwWYs5Ewb+hYz63Bn+VlNQ/C6NaG8zfJaz/ZX2lUBwpXy+APpe1+UrlE6WTAAE= 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=cGVCOFTA; arc=none smtp.client-ip=209.85.161.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="cGVCOFTA" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5f1d1fdb328so1250227eaf.3 for ; Tue, 26 Nov 2024 08:20:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638031; x=1733242831; 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=j/lu/EGVVDXuMSIzdRCxVlnfxSM4yuT3W6HrMPORjdo=; b=cGVCOFTAmJgqnFtFVRgf0nmNWSofQXtS1eTM85jrTLPQ2LrLa3KCDgBcGKiPRor7pB 3mEUg5dO7E4dBDzwuAyUm9c7rXNTJ+yIc+g+nW5F40S0P4Ld6y0iu6WPwnFxoRMHW1TN KundA9BsmwBPjYx1YoxQWFtmESbXHur5EkwAU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638031; x=1733242831; 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=j/lu/EGVVDXuMSIzdRCxVlnfxSM4yuT3W6HrMPORjdo=; b=XZHM5haeHUR09/puxV0+sPg3dPwCu0hdK6nuNM/H6O9Cf7xEo8X+15OWxpVPvgMsu8 g1z7ZCppVgJASiboOMCvOxd68TJwgHziNpQlrx8PGrM6Bl+CAqB+wZwOlLrMU/d7bLcN WZCynZbR2K+PXDpx7neAn91g9VjvkbiFh7jR990T3zadtgl7uBSi117zhYEW9re5Cmts gvrlWl18I/zT0EXM0E/MeNexLkklzg9lDGqdeDwVNkmyXJb9QUrJbXZuxPojotk3cFzk g+oVyAyuMnlEjzM0XOudFxJcdjrZqxDq9/wYxo9ZZsLrx0pZKQf9tWh+jcOC2Gay93hp kkDA== X-Gm-Message-State: AOJu0Yw5DTDqpjvKlp7OC58S3OXCkyy7UuH54RTWJIKWZd9iBO28aB4Y 1eyZ8YIIw6fc0QHnS+AKd1my5KUmMlS27ikaqbd4W4qfCCm/amvzJXhwpSQdoQ== X-Gm-Gg: ASbGncsuiDKzhKYEOdfvbJNGvxLkO8TiR2xq1fdfwtuoVFTxX+g0hqKSGF1BAOAH19y BpyZ0VB0H3OT9G6iNkcv/cAdpAdpK6lYQg9jfQoCTN7+nY5yFCs4UI7Se6Pds0Bnj3O7ae1aGUh oJGcOBZYInHV5pPFjl1uY6lI14JfX6OWOU78Qo/mSZwtImNa/6sA7toGG5i6j7oVYec8XnSBhg3 M/PHO5R0ciiXYajdiaMcpqcdzos3KyIhIGAy+Vs0xjqrR/kqJJ6paJX/gEr5MrlUydmMED5rMU8 za9ODR3nVtZQJdmmPCe7CuLD X-Google-Smtp-Source: AGHT+IFPBjhCNlx/WOQpP/DrR9JEp90XgxFyirfWiypz7tV1QsQQ+4YXuQ598fwfKwMo0jUvpfnh+Q== X-Received: by 2002:a05:6359:5cc2:b0:1ca:a77a:e9b8 with SMTP id e5c5f4694b2df-1caa77aeac9mr318229855d.17.1732638030982; Tue, 26 Nov 2024 08:20: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 a1e0cc1a2514c-85b4e8205fdsm346532241.1.2024.11.26.08.20.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:30 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:57 +0000 Subject: [PATCH 7/9] media: uvcvideo: Make power management granular Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-7-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda X-Mailer: b4 0.13.0 Now that every ioctl takes care of their power management we can remove the "global" power management. Despite its size, this is a relatively big change. We hope that there are no size effects of it. If there are some specific devices that miss-behave, we can add a small quirk for them. This patch introduces a behavioral change for the uvc "trigger" button. It will not work unless the camera is streaming. We consider that this the most common (if not the only) usecase and therefore we do not consider it a regression. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 1972ede38c70..3595f67fd7e2 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -612,7 +612,6 @@ static int uvc_v4l2_open(struct file *file) { struct uvc_streaming *stream; struct uvc_fh *handle; - int ret = 0; stream = video_drvdata(file); uvc_dbg(stream->dev, CALLS, "%s\n", __func__); @@ -622,12 +621,6 @@ static int uvc_v4l2_open(struct file *file) if (!handle) return -ENOMEM; - ret = uvc_status_get(stream->dev); - if (ret) { - kfree(handle); - return ret; - } - v4l2_fh_init(&handle->vfh, &stream->vdev); v4l2_fh_add(&handle->vfh); handle->chain = stream->chain; @@ -661,7 +654,6 @@ static int uvc_v4l2_release(struct file *file) kfree(handle); file->private_data = NULL; - uvc_status_put(stream->dev); return 0; } From patchwork Tue Nov 26 16:18:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886174 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (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 CC2A91DD543 for ; Tue, 26 Nov 2024 16:20:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638035; cv=none; b=XCjsEOmvU9K6NoPzZfRK1OLebvb8Ul0HchWeFWbP1m1S9gH4JlqwRNZujt80PLRgm8OW0dEpJ0J2ZrQgbyNpf0Fd+zZ5mn6BEjrF50o+ubFccQDsJBsiAPTMlhJJ3v4/r8QpgbVNyuk/5rX6f2x9XuljtLWLjBxKGleI0/juMpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638035; c=relaxed/simple; bh=3AS4904ZrJWWmtzo+XQDjxmA+Exv2p0QUHnWYejIDuM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UZRMp+M4xyjyUNWpwTK/kU7PoFIoz4KNGl8ktRIOZAFMcK7/Y59JMqBoUQFOPwMlV0gKw/XDLjpz0NYpI6bZSqgilepYge++GMKfGoJ+AOeLY/EsfpWi/kYqQ7H0uVcYdSX4RM5Bgk+wG2cqZIau/5iGkbvlmtLNUgDXXB8kpm8= 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=jtS5RrYw; arc=none smtp.client-ip=209.85.219.43 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="jtS5RrYw" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6d3e9e854b8so60485116d6.1 for ; Tue, 26 Nov 2024 08:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638032; x=1733242832; 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=38DVVdNZ+9OXPNjKWQaX+5zY7dH2BnytoxnJmJsLz5s=; b=jtS5RrYw9EeCtS2ZR2MwAnH1UDCU407zwTtDCQKj3ekRSvqxLdi6ftIBIOwPrZBZq4 0VDChiwy+jBjcz7V5VIzhsL6AHlxXjBza4rzkDdCyIv9YlC75i7jLswYisWdcMlgb19U 8QHMY0f9AK0qy7RTvtP4CsB2oYjcBcTlThnxs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638032; x=1733242832; 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=38DVVdNZ+9OXPNjKWQaX+5zY7dH2BnytoxnJmJsLz5s=; b=MxAXPsFAiFshq/v+AkYEaDntUZsClRArVn0YEPR9l13ZVNnbENPXKKJOl1Wm6oLIFm qPPD1P3lBGq9MjEugF3myTKE2RMKK06FH+06ZgBsalLhLNaPSX430rZAbnVzYH62/Fj1 kyLEMyQW2b2NWiLutqx8wIMJPGYS1D8/RkFUfRgsJS8W8cRpiyfCdPFGXGn1LsS4l8M0 D/12JBf6pwznq7ueZJTS7vL/LrzHwnFy0xdlMUbSwPegSULycDM7S5P8iFhUjQ8ifZfI cM3RHBf1ksqKgFjfwhlL5QBCWdDRhtNUKCM/JuTYbB0/DnVe31muqf+XdOcNDEqo9Cy0 r+sA== X-Gm-Message-State: AOJu0YxCvVra6cI+g8ilYo2K4duKj1rG0P3UwAOURW9H514/13jluuAn FaGV0uRhh3cS6XbGNAK0N27ezYdCp7aIaKwdmyDjccnT1gpdS2B5hwOYI4J8kQ== X-Gm-Gg: ASbGncs1/UyGULzf60hAE8/L9oc2ilN8+trUCOnKkLQ9pzbLP5TdcyCAOf27c2X1o6l yppIQbLFGIb9PJkSGUxKCoNF5AWKdcrsQHPp1TBydZZPABifKSzzDbd2tcJlIc6FPi8WRbidmPP s7cwylLuPq8qzAthdNpipnzP3LVsDo/OMTNyDfL8+ImMc+QKuV5RXfBA1YvyRrPI5CaTwu9xnVx E55jEXI5BbQECvoR+lwX8xw+zVEXXG52FZ6Le0CMypEMBBJuzs7RkegxYn4tfrl3jPQlcvoJuJ8 8V/BH8RlB8x7gkYn+8INTxIg X-Google-Smtp-Source: AGHT+IGr/+2B6+LJ1kyUP+IBLvQ2LLQlOOS30Ru02Ofx3ziT/PGCoQW+M+Ou9DSuWC6URGy5iQFp+g== X-Received: by 2002:a05:6214:268f:b0:6cb:c9cf:cd40 with SMTP id 6a1803df08f44-6d856bd1e51mr59641196d6.8.1732638031784; Tue, 26 Nov 2024 08:20:31 -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-85b4e8205fdsm346532241.1.2024.11.26.08.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:31 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:58 +0000 Subject: [PATCH 8/9] media: uvcvideo: Do not turn on the camera for some ioctls Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-8-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda X-Mailer: b4 0.13.0 There are some ioctls that do not need to turn on the camera. Do not call uvc_status_get in those cases. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 3595f67fd7e2..0a058798d075 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1455,6 +1455,26 @@ static long uvc_v4l2_video_ioctl2(struct file *file, { struct uvc_fh *handle = file->private_data; + /* The following IOCTLs do not need to turn on the camera. */ + switch (cmd) { + case VIDIOC_CREATE_BUFS: + case VIDIOC_DQBUF: + case VIDIOC_ENUM_FMT: + case VIDIOC_ENUM_FRAMEINTERVALS: + case VIDIOC_ENUM_FRAMESIZES: + case VIDIOC_ENUMINPUT: + case VIDIOC_EXPBUF: + case VIDIOC_G_FMT: + case VIDIOC_G_PARM: + case VIDIOC_G_SELECTION: + case VIDIOC_QBUF: + case VIDIOC_QUERYCAP: + case VIDIOC_REQBUFS: + case VIDIOC_SUBSCRIBE_EVENT: + case VIDIOC_UNSUBSCRIBE_EVENT: + return video_ioctl2(file, cmd, arg); + } + guard(uvc_status)(handle->stream->dev); return video_ioctl2(file, cmd, arg); From patchwork Tue Nov 26 16:18:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13886175 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 191241DDC2B for ; Tue, 26 Nov 2024 16:20:33 +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=1732638036; cv=none; b=uytBiQiBvGfzDXNfE/lBFqcX9JKkU6n8eaPixdfA19b+XWAwsMcqaH2oHJDeqZbCQ07RWUQtmaWsBkVYQLRddaaitd4QY2KO+vMKW6vcoyBbZQ0ykFMRF3nnYIndKg/0JY3PCubtKnbsZTcJqBReAaacNy+R4xQ7aelMq/NeKxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732638036; c=relaxed/simple; bh=x5kYRVcSK4regsPtlTEktgdS6fXUdjiyw9Jv/VfqSKI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Lbxt4zdfW5yEWjY5OpC+5za0SGHux6B5R6HdWE5LHJb06+uzcX/IwqDnL9G1FCPeHgwbv1Y6NI+SAsL3kIh/8JmH+2e9yHTeoOM8lqvTYByuYL9mePPlb9VCgssjjkB3ircmXGqIyb0oZKjF2BGbKmboZuNIftnfPE8A/yPa85Y= 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=BhwTGNUp; 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="BhwTGNUp" Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5f1e79c2f81so1082678eaf.2 for ; Tue, 26 Nov 2024 08:20:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732638033; x=1733242833; 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=yxOLHw2VBQB5L41d2F/BZfaylw/KjmpdZ2BT3uiOSdE=; b=BhwTGNUporFl25ZPpR1NvU06BawTuoW47fC+3eZQpOZVhREAMB029UbplE7PMG0lTB Gbu0rWMp6oZyb15A3wnbi+hYJqtF1SXdOm4at+dXs3Vsxaj/yGgU+52W9V0XdRQTPJfM YGLYZDdy2O5GdW7O9mJlwGvu3nCZO5dEQ60VY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732638033; x=1733242833; 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=yxOLHw2VBQB5L41d2F/BZfaylw/KjmpdZ2BT3uiOSdE=; b=mYRKweYbA97mzE4WWwN1ZM3bkAGE8Sro5KVPdCrSEmptAtPW2jKHkB7+Gx0EHa7sHy +UGvFxpNj8HSAc8gylhaVNpsuDkjG2Wok7dpiNo+FdrZ0IDiKA1+3mNc9nrKw62/iT1z yjHxISlzG5WSFhOoB3exVIHzMXMXfruR5T/Bjt4k5N54Jeyl+Xz5/K0vKE4iPtIq4yU0 rAaHk94/aWvCE39sruGpcF2MWLiLGFBE9mtxn1RmW6yIQSZP8FR0PmXIr/Xb8DM8caf2 nolqj1omwnjCf8Wgz6neZlC/MHCHm03IKiqshwvs0xYivTmg6yzq5X3Tg669hekXaZwz maaw== X-Gm-Message-State: AOJu0YxPZK/GPrb8Ld0MJny/oxWBrtSoGD/cjqBu24m6Bg0RT9ezJm69 lDF4miLea4Cg3jP59cYQhDp3N2wOfyiZrinwCS7KlcBdzW5zQlHjZSctGVBDNlKjl78fQB5uRsE = X-Gm-Gg: ASbGncvLVouRhFrMWmojxWWaXK9UUFIWIMxGTxpOA3WuLgCKU0Yp9ILrzIvOjTd96yW RrHGSgEW1hDeQSG41g6NouL+bTNnvncAG5XFROEzxrGOHCle9zptEyM+h/RzB+zTdKw1o0imTSD d2PquTED1Ro+kkaTmlHitUZPAHCzUJGkKh1YIMV/qyCb21nIAkPHaxJOEg4kQnfnLmtprLn9Fxv qE5hhhBWPouCV6u4ftt3RxOnCR6glgWavv+rDpIBN26GlmB/vmiAupc1XHxNeA7Cn+xFq+xULDk k2AssnSt8i+x+b2R96PgaTLC X-Google-Smtp-Source: AGHT+IH9UXCX+Ay1aMbd9HmFc/mZX4tEK6BZIIou4isklRZcLG+NWhVRDKABiscK2ZTOUwj4/Pc5Ow== X-Received: by 2002:a05:6358:52c7:b0:1ca:adf1:2e98 with SMTP id e5c5f4694b2df-1caadf1307bmr111624355d.1.1732638033244; Tue, 26 Nov 2024 08:20: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 a1e0cc1a2514c-85b4e8205fdsm346532241.1.2024.11.26.08.20.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Nov 2024 08:20:32 -0800 (PST) From: Ricardo Ribalda Date: Tue, 26 Nov 2024 16:18:59 +0000 Subject: [PATCH 9/9] media: uvcvideo: Remove duplicated cap/out code Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241126-uvc-granpower-ng-v1-9-6312bf26549c@chromium.org> References: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> In-Reply-To: <20241126-uvc-granpower-ng-v1-0-6312bf26549c@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Mauro Carvalho Chehab , Ricardo Ribalda X-Mailer: b4 0.13.0 The *_vid_cap and *_vid_out helpers seem to be identical. Remove all the duplicated code. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_v4l2.c | 112 ++++++++------------------------------- 1 file changed, 22 insertions(+), 90 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 0a058798d075..cc32ce3275da 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -361,9 +361,11 @@ static int uvc_v4l2_try_format(struct uvc_streaming *stream, return ret; } -static int uvc_v4l2_get_format(struct uvc_streaming *stream, - struct v4l2_format *fmt) +static int uvc_ioctl_g_fmt(struct file *file, void *fh, + struct v4l2_format *fmt) { + struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; const struct uvc_format *format; const struct uvc_frame *frame; int ret = 0; @@ -395,9 +397,11 @@ static int uvc_v4l2_get_format(struct uvc_streaming *stream, return ret; } -static int uvc_v4l2_set_format(struct uvc_streaming *stream, - struct v4l2_format *fmt) +static int uvc_ioctl_s_fmt(struct file *file, void *fh, + struct v4l2_format *fmt) { + struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; struct uvc_streaming_control probe; const struct uvc_format *format; const struct uvc_frame *frame; @@ -673,11 +677,13 @@ static int uvc_ioctl_querycap(struct file *file, void *fh, return 0; } -static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream, +static int uvc_ioctl_enum_fmt(struct file *file, void *fh, struct v4l2_fmtdesc *fmt) { - const struct uvc_format *format; + struct uvc_fh *handle = fh; + struct uvc_streaming *stream = handle->stream; enum v4l2_buf_type type = fmt->type; + const struct uvc_format *format; u32 index = fmt->index; if (fmt->type != stream->type || fmt->index >= stream->nformats) @@ -695,82 +701,8 @@ static int uvc_ioctl_enum_fmt(struct uvc_streaming *stream, return 0; } -static int uvc_ioctl_enum_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_fmtdesc *fmt) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - return uvc_ioctl_enum_fmt(stream, fmt); -} - -static int uvc_ioctl_enum_fmt_vid_out(struct file *file, void *fh, - struct v4l2_fmtdesc *fmt) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - return uvc_ioctl_enum_fmt(stream, fmt); -} - -static int uvc_ioctl_g_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - return uvc_v4l2_get_format(stream, fmt); -} - -static int uvc_ioctl_g_fmt_vid_out(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - - return uvc_v4l2_get_format(stream, fmt); -} - -static int uvc_ioctl_s_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - int ret; - - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_v4l2_set_format(stream, fmt); -} - -static int uvc_ioctl_s_fmt_vid_out(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - int ret; - - ret = uvc_acquire_privileges(handle); - if (ret < 0) - return ret; - - return uvc_v4l2_set_format(stream, fmt); -} - -static int uvc_ioctl_try_fmt_vid_cap(struct file *file, void *fh, - struct v4l2_format *fmt) -{ - struct uvc_fh *handle = fh; - struct uvc_streaming *stream = handle->stream; - struct uvc_streaming_control probe; - - return uvc_v4l2_try_format(stream, fmt, &probe, NULL, NULL); -} - -static int uvc_ioctl_try_fmt_vid_out(struct file *file, void *fh, - struct v4l2_format *fmt) +static int uvc_ioctl_try_fmt(struct file *file, void *fh, + struct v4l2_format *fmt) { struct uvc_fh *handle = fh; struct uvc_streaming *stream = handle->stream; @@ -1576,14 +1508,14 @@ static unsigned long uvc_v4l2_get_unmapped_area(struct file *file, const struct v4l2_ioctl_ops uvc_ioctl_ops = { .vidioc_querycap = uvc_ioctl_querycap, - .vidioc_enum_fmt_vid_cap = uvc_ioctl_enum_fmt_vid_cap, - .vidioc_enum_fmt_vid_out = uvc_ioctl_enum_fmt_vid_out, - .vidioc_g_fmt_vid_cap = uvc_ioctl_g_fmt_vid_cap, - .vidioc_g_fmt_vid_out = uvc_ioctl_g_fmt_vid_out, - .vidioc_s_fmt_vid_cap = uvc_ioctl_s_fmt_vid_cap, - .vidioc_s_fmt_vid_out = uvc_ioctl_s_fmt_vid_out, - .vidioc_try_fmt_vid_cap = uvc_ioctl_try_fmt_vid_cap, - .vidioc_try_fmt_vid_out = uvc_ioctl_try_fmt_vid_out, + .vidioc_enum_fmt_vid_cap = uvc_ioctl_enum_fmt, + .vidioc_enum_fmt_vid_out = uvc_ioctl_enum_fmt, + .vidioc_g_fmt_vid_cap = uvc_ioctl_g_fmt, + .vidioc_g_fmt_vid_out = uvc_ioctl_g_fmt, + .vidioc_s_fmt_vid_cap = uvc_ioctl_s_fmt, + .vidioc_s_fmt_vid_out = uvc_ioctl_s_fmt, + .vidioc_try_fmt_vid_cap = uvc_ioctl_try_fmt, + .vidioc_try_fmt_vid_out = uvc_ioctl_try_fmt, .vidioc_reqbufs = uvc_ioctl_reqbufs, .vidioc_querybuf = uvc_ioctl_querybuf, .vidioc_qbuf = uvc_ioctl_qbuf,