From patchwork Wed Feb 26 14:23:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13992572 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.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 C3F16221735 for ; Wed, 26 Feb 2025 14:23:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579813; cv=none; b=V6pnjjxNq+piWU99S2kC43FqOAtpxO9IvD2PhRGoUG+iSqH58TlMiARNOn6p7Re/T1Lk8OooWwsbQ1D1wRSINj0LrPc3OCBEchx+wxw1N28x7q34ZgAsHp0CRCoBm8TVtNQnAOobidJ+vktSuBFyVD0FSaVvchDCpTNwcAdQwZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579813; c=relaxed/simple; bh=ri+j1q9HNTbPxqJ5PKx8hnKBR80LOJzmJuwIpKv0D6k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ToJPQrZH2T6BP/7puhIFonIn5f6kL3DgHl5SMoljKSMOc2X9QbGpsEohLJcXYhBnZ0oxJcS226O1w4fIhduqsELDPDdiaa/yEUu3kXzklUUvlRX739sj5GBE1dS42yFUBUELyaI5Gj16lNFLVSrkp0+2G+DCwtDa96lKQHI1Pd0= 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=ED5Bnt73; arc=none smtp.client-ip=209.85.222.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="ED5Bnt73" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7c0892e4b19so807700585a.3 for ; Wed, 26 Feb 2025 06:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1740579810; x=1741184610; 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=FR7Ypv0Sg+ewXBIGdoxyyeMv+vtDJwycIUjyx2MKkFY=; b=ED5Bnt73wpD3fChX3kqbJa3/XhmoG76Oyzv4FTfkR8UQR0x0iInvO6gv/vZp9HnW+E ++7HupKvm6+/9hlElPdS+ocGL/JEWZILR1TTtZ9mb1ufUgjklUru3tJAOj26yxZNg+A8 uIgIieCR+Z13WkyFwWno2Au6D0TdRjVwtlV0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740579810; x=1741184610; 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=FR7Ypv0Sg+ewXBIGdoxyyeMv+vtDJwycIUjyx2MKkFY=; b=SLu/kKoLYxh+V02u00wGHDPPa3tZ54qS0ACFwy6qgeoFtfyodf+iKBK/vcdlszYJPE Xo7FiwC0cOVjD0Mpk2Y9lyNu90n1m/VElsXuqdj9wY8vFT2jpXu7+8+dPUPq9l4S2hyg 7oa32kROrzAaWIme7u2ZnvEQ6Z7V3IqaO//VETtrRxIvYU7U5NbOTuez6yB4puIjYEXW VI3ZVi/zEvXlJf/uZMHHyAo8lSk3kEVKjp3fz4028hQDZ3TOJJjPpw8FcadI+fTOwAxc QZzqEOoWYIcmTL7FJLwthtHKPgtbOThq2cc7e0ASOZASagCjsKbx12Kjj7PSBgsZDhlG WeLQ== X-Gm-Message-State: AOJu0YydvcuvGtcPfwIzpZmZJHE8ThzygMULTecasmHEKrnjlsXEyjh6 rXD3Zg/i6eZhyjw6UR4R/g4wKUNyriKLkD/s8CaIXOWqX1rRk5kzsXsiJ8pML4kaiV9mxMq10r0 = X-Gm-Gg: ASbGncsDJUq83zLL8KdJKeGxBLu1Fl2kNF7K9VbKDi4xqovuT1dnhAjWTGlScIiS3hd 40zGsekJSOjuNx0EiDffXwb3KF1t/MrpQXau2Wa0IDCnfYwHk3C2b+46ZesfA2pwGq7yWmGWYX3 PhchP+Uknbt2lQzhFLMA2KzekoCDmTQPKvpEO+yUU8tCzcsVKma1SIuahGYfBkU+ORcQcpOHsQg KKTXAsJ7LSAqdN02Wx0VgwcqVBVbWR6cBCEaxF/GT8ugpCy3Nk4X4dAnkjP01msdqjgOXj4x2Wq wWBZ45IlgvZJVWdxVVwUqUKkyB3G5ESliW4YjC4KhnoyP1OEHhHpohApyoCe/qOVrHL2sGtiaHZ eEDM= X-Google-Smtp-Source: AGHT+IH79EX6T3W52JGBBGWui/gHd8e8j+HpD2LiLS0W30noVcOURaOisGZHFg886wnhbnBhazedTQ== X-Received: by 2002:a05:620a:404a:b0:7c0:808b:1c78 with SMTP id af79cd13be357-7c247fcb611mr700665085a.36.1740579810731; Wed, 26 Feb 2025 06:23:30 -0800 (PST) Received: from denia.c.googlers.com (15.237.245.35.bc.googleusercontent.com. [35.245.237.15]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c23c33cfb0sm246336085a.103.2025.02.26.06.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 06:23:29 -0800 (PST) From: Ricardo Ribalda Date: Wed, 26 Feb 2025 14:23:27 +0000 Subject: [PATCH v4 1/5] 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: <20250226-uvc-granpower-ng-v4-1-3ec9be906048@chromium.org> References: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@chromium.org> In-Reply-To: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@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.14.1 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. Reviewed-by: Laurent Pinchart Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- drivers/media/usb/uvc/uvc_v4l2.c | 18 +++++++++++++----- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index 93c6cdb23881..f9cd6db759c5 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -835,11 +835,18 @@ 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) + return ret; - return ret; + handle->is_streaming = true; + + return 0; } static int uvc_ioctl_streamoff(struct file *file, void *fh, @@ -851,9 +858,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 5e388f05f3fc..bc87e1f2c669 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -618,6 +618,7 @@ struct uvc_fh { struct uvc_streaming *stream; enum uvc_handle_state state; unsigned int pending_async_ctrls; + bool is_streaming; }; struct uvc_driver { From patchwork Wed Feb 26 14:23:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13992573 Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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 DC9AD22173F for ; Wed, 26 Feb 2025 14:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579814; cv=none; b=W/kKvXA4+vK9SUy0gtB7ZDM4Cw76qj4b//WpvSVGrWrWYqA0ZyGdl2qA+4ISRV/eJ/TQ3Mufb9ADVYKsfMj6+gmSt87gbdFdrgbHOB9JYXMlEFoI+AMBCj3WBLxkH3b8uqo74+tHOwH0OrSvJ+wuJJQWHpLWCENl4age4XHXYHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579814; c=relaxed/simple; bh=71qURUpKQyHqhn8hHrbpIZhkr9HtzexcGmxJCr00cjw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ey6iDClDVLTd3sFivI0j8IhFW4KeK6FoxZ8IILwdTdjbPVTEKsBsdWTBoBnAhMPz/gNx753vQ8re+6ewq7NaiY1kPUrNJ09QTIBj2ZzF9Hi9TL5KXQAJwaD32QVRmfNc7BPD9SChMAKr9Ia1mWTGyBWgV+hsZ9yqlqCoOB4YcgM= 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=VlTu6iqz; arc=none smtp.client-ip=209.85.222.175 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="VlTu6iqz" Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-7c0a4b030f2so884049185a.0 for ; Wed, 26 Feb 2025 06:23:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1740579812; x=1741184612; 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=I2vbUd0IkHjhLkq4YLUTxGcYI4X6Kojg8kTGYZFd8GM=; b=VlTu6iqzZGlq3ht1GCmuK1OelGevKydVcN2QJdKdOAsETpuWJ3JS5PyJ+K4LM2ffRR vSzZmrHPQU/HKIYwtyl2geSKkxVDygtH3ZIIlCvBkfL/xsd1DGrt7OHTsnhMQyq+vE27 t84hjsJdF9d4grfg6zgPj60bvKDm5Xnmpe2gY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740579812; x=1741184612; 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=I2vbUd0IkHjhLkq4YLUTxGcYI4X6Kojg8kTGYZFd8GM=; b=neE0dg/XkwkxAlE8O7vqlaBO8IFPmwtx8xo0+CM/W5pY4GskwNvpLZYDD74ouM4McL z2yPtjXEJF59cgQHBQSDbUHkoeZndS08wYWodnf//M3raYS7aoACgYLWnnlnt+I+/CPU RZfbaS+KUxrZ2BnHBLoIXS3MMwReSvNR23GE9G0aZkUtJmwLN+DNoUubXtYddlwJe1vm sb1xz7EbwpvKsLB2OphRYTGzfl0gc7ZepFhH0Ec8r0VJKlqfagpygipTr7lO2GHBxKZF VLA8GrbWIHIBVX83oG9RgBbrKT1YsJv2hbCvSi8Uy3BKfdZkdB+vs173y19iZznaG9mz 1t2Q== X-Gm-Message-State: AOJu0Yx/ZRrwEQICeDuiBiBq/hh/VxjBecf+k+wW+pus5YPLkLPQdBLM aSh/1V1wa4tY5629rYkDrq1Ytob1HOEDl7yKEmrh/cEn1rhJFhq1Qd/Q3u6vz6lZEF4qFe9gXAs = X-Gm-Gg: ASbGnctBBDor/iZNp3IbCtiRtkwUQlDGx8Ju3Co++qBn37lPPiTkcCV4LZThoQ/Vwy/ Ql77DA9+Pi7YiatOJf5s6x4b9LDGiI2s0mBoyTI2QsnwFQ/ZFhoWRLKYX8kjBW4EkusVcNx/KBu QGK9ADnogLwlliu/OBrZf1807AKYkXv11biPqveyiTmlmVFZ2SoEi+eMai+PUn9NBj025AkWsE9 jUlulKU7TMEL2wG7neUv5g+qEO1SRmiO4ghIUKlUbKD0clzuBeiVbpIW9nprS4vMOpjo0791W2H rjOf/VjukdFM8FP2Khjd38IfElvphtcsNqzqIyyhvQG5sOkGH5F9ew3CuuD6BP+m/eeUQysymmX kNyI= X-Google-Smtp-Source: AGHT+IEIjZIDI9MFFXd5K8qshi0fFF0mSwbprLeHtnyDrbye91YUoOAfrTDjrDmjYqtIPY5GIvRxrQ== X-Received: by 2002:a05:620a:31a8:b0:7c0:bb3f:e285 with SMTP id af79cd13be357-7c0cf8ce834mr2663166985a.24.1740579811861; Wed, 26 Feb 2025 06:23:31 -0800 (PST) Received: from denia.c.googlers.com (15.237.245.35.bc.googleusercontent.com. [35.245.237.15]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c23c33cfb0sm246336085a.103.2025.02.26.06.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 06:23:30 -0800 (PST) From: Ricardo Ribalda Date: Wed, 26 Feb 2025 14:23:28 +0000 Subject: [PATCH v4 2/5] media: uvcvideo: Create uvc_pm_(get|put) functions Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250226-uvc-granpower-ng-v4-2-3ec9be906048@chromium.org> References: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@chromium.org> In-Reply-To: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@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.14.1 Most of the times that we have to call uvc_status_(get|put) we need to call the usb_autopm_ functions. Create a new pair of functions that automate this for us. This simplifies the current code and future PM changes in the driver. Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- drivers/media/usb/uvc/uvc_v4l2.c | 36 ++++++++++++++++++++++++------------ drivers/media/usb/uvc/uvcvideo.h | 4 ++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index f9cd6db759c5..de1e105f7263 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -26,6 +26,27 @@ #include "uvcvideo.h" +int uvc_pm_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; +} + +void uvc_pm_put(struct uvc_device *dev) +{ + uvc_status_put(dev); + usb_autopm_put_interface(dev->intf); +} + static int uvc_acquire_privileges(struct uvc_fh *handle); static int uvc_control_add_xu_mapping(struct uvc_video_chain *chain, @@ -636,20 +657,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); + ret = uvc_pm_get(stream->dev); if (ret) { - usb_autopm_put_interface(stream->dev->intf); kfree(handle); return ret; } @@ -684,9 +698,7 @@ static int uvc_v4l2_release(struct file *file) kfree(handle); file->private_data = NULL; - uvc_status_put(stream->dev); - - usb_autopm_put_interface(stream->dev->intf); + uvc_pm_put(stream->dev); return 0; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index bc87e1f2c669..fbe3649c7cd6 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -763,6 +763,10 @@ void uvc_status_suspend(struct uvc_device *dev); int uvc_status_get(struct uvc_device *dev); void uvc_status_put(struct uvc_device *dev); +/* PM */ +int uvc_pm_get(struct uvc_device *dev); +void uvc_pm_put(struct uvc_device *dev); + /* Controls */ extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; From patchwork Wed Feb 26 14:23:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13992574 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 594EA221735 for ; Wed, 26 Feb 2025 14:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579816; cv=none; b=VT2vPdVmP0AfbMuvNa+vwUDNB+OiNATeHVQGfR1xn8S2e0/FWmv3CktvTowuJwf/jQu29/ggJtjAxtXg3e23Q3IbHyZ5+9Mwcw7s7nl7tkqkNRFomoIp+OZJ4rg2yBm43qzPyv7I2VRaRu+iihZcWVe75/sWEw7w1vRumUGaXM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579816; c=relaxed/simple; bh=rylK6f1QH5ynXpFEibP1x7WRxpQi7HVpYgi2w6TZTjg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hyYMlieKok9ax53e1aQPC5X5z4zP/b1plSlUt3R0tYb3sMcOx/phLD6AzebVs1pnhf0bChlv4etxBsU3EpVZhtRP5aHJZ5BYPFtRS91nBwgEi+4rXYIwzE7mpSt4FTFS+6K5TS0vthK42HJfxPBJEYBkxfYGhoMyDzxV8SzvPsY= 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=cVCGN5bi; arc=none smtp.client-ip=209.85.222.177 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="cVCGN5bi" Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-7be6fdeee35so1300087785a.1 for ; Wed, 26 Feb 2025 06:23:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1740579813; x=1741184613; 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=BnrHbOIeNyXFgC3ohSck6umf/PDQ1ndtYxjmn58DA5o=; b=cVCGN5biLc3Z6k+Ujn3n7oJEPeXrWGlSGj67YyL/nK/8ioJn575UKicejmg7+Z65Y+ HqzNeOnYQiqi05lAu/p4sqW8Jup3s2I15po1VjHPbnzUrY1Y387kRXcAXbiAD4f6Iepb pl44YiBGrsIfr/w1Xoyy1yiVT6pTvWnvw+ohU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740579813; x=1741184613; 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=BnrHbOIeNyXFgC3ohSck6umf/PDQ1ndtYxjmn58DA5o=; b=uLREHjH57/OTItpHSsm/aKo+XZerQSL0CXnowEtuXpyMtvHajkJ4PpwCt4wKS1bsvb ZkNeA0pK1o/ZScUrX/XlUfFS0iVq1YJ3NfBrMUPuZxTzbAzpxKvH7YJhu4D3sn3r+YrD RY2W3bxs1tN52PjlZuyTx8ZunKr6XlbCDMiVTx0l1GmS3zccs1nm68ZBOzV1xvu3N1Sb Ua2DsSU5oDAQPtHT1k+gKoelERSv8Y24n54MX0Fxh612tfmEXGVz2T1ZkKs9Q1XDN0S9 VCjQX3OC7RBuw3WkctpKj3k5Ka7umhAJolpK3KVpjjWRv5bcm3Uk+laq41yqpvfTiz4N IJGg== X-Gm-Message-State: AOJu0YxF5AZUjyNgTsqgquGNeGsqnbaL/I4nthEXz9Qq+cb4R0qrOL2V pnh7iTL213+MEjuBOCXBH7Vig6LpqhQDtlsPlZ/8bD11XX/eT72rTLUAlGmkrQ== X-Gm-Gg: ASbGncvLlzJxizlQdwwxSs8jaRAfNVODzyKob1ADPl47bnBhNm+4U/w21fRYcLBLHHe 1oSuTTu3QJT20tG+5bPw3DRdtoAEkULBSxUOMEzMK9YRyCIsdQ5tqec6tQlI9iOQk04G6Q1Sl5U C+kNJCyCz/SmZIg/53oHo6hEMkCPr11FZe+/5e5AE9BOHS+kXW3TG/qMtEDNa6gvtDvp/BQ//q/ UotScRmk5uR/uxmXLr0dt53VdlwyMf1/ADauxNVVfeE4iuQ8DOpwiAU5z4ZfclXnkzwwxCyfKTW CTgKNhGCq/BaPUroWYRAvzovxE2IgRPYeviQKucxceoaTgMKZ8SKiiNvu/Jc0CtBjmZHdXGTsD8 Wjno= X-Google-Smtp-Source: AGHT+IF2fi7OhvOIfrZBpLucCECiFhFVL1Q4iddsUtPiahTbS8VKT8yERMFERI4M5Nb7Ay79RtvcaA== X-Received: by 2002:a05:620a:4106:b0:7c0:a28e:4970 with SMTP id af79cd13be357-7c23be24c00mr740057185a.29.1740579813351; Wed, 26 Feb 2025 06:23:33 -0800 (PST) Received: from denia.c.googlers.com (15.237.245.35.bc.googleusercontent.com. [35.245.237.15]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c23c33cfb0sm246336085a.103.2025.02.26.06.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 06:23:32 -0800 (PST) From: Ricardo Ribalda Date: Wed, 26 Feb 2025 14:23:29 +0000 Subject: [PATCH v4 3/5] 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: <20250226-uvc-granpower-ng-v4-3-3ec9be906048@chromium.org> References: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@chromium.org> In-Reply-To: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@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.14.1 Now we call uvc_pm_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_pm_get/put from open/close. Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- drivers/media/usb/uvc/uvc_ctrl.c | 13 +++++++++++-- drivers/media/usb/uvc/uvc_v4l2.c | 23 +++++++++++++++++++++-- drivers/media/usb/uvc/uvcvideo.h | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 4e58476d305e..47188c7f96c7 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -1594,12 +1594,15 @@ static void uvc_ctrl_set_handle(struct uvc_fh *handle, struct uvc_control *ctrl, if (ctrl->handle) { WARN_ON(!ctrl->handle->pending_async_ctrls); - if (ctrl->handle->pending_async_ctrls) + if (ctrl->handle->pending_async_ctrls) { ctrl->handle->pending_async_ctrls--; + uvc_pm_put(handle->chain->dev); + } } ctrl->handle = new_handle; handle->pending_async_ctrls++; + uvc_pm_get(handle->chain->dev); return; } @@ -1611,6 +1614,7 @@ static void uvc_ctrl_set_handle(struct uvc_fh *handle, struct uvc_control *ctrl, if (WARN_ON(!handle->pending_async_ctrls)) return; handle->pending_async_ctrls--; + uvc_pm_put(handle->chain->dev); } void uvc_ctrl_status_event(struct uvc_video_chain *chain, @@ -2815,6 +2819,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); @@ -2829,7 +2834,11 @@ void uvc_ctrl_cleanup_fh(struct uvc_fh *handle) } } - WARN_ON(handle->pending_async_ctrls); + if (!WARN_ON(handle->pending_async_ctrls)) + return; + + for (i = 0; i < handle->pending_async_ctrls; i++) + uvc_pm_put(handle->stream->dev); } /* diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c index de1e105f7263..1c9ac72be58a 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -691,6 +691,9 @@ static int uvc_v4l2_release(struct file *file) if (uvc_has_privileges(handle)) uvc_queue_release(&stream->queue); + if (handle->is_streaming) + uvc_pm_put(stream->dev); + /* Release the file handle. */ uvc_dismiss_privileges(handle); v4l2_fh_del(&handle->vfh); @@ -857,6 +860,7 @@ static int uvc_ioctl_streamon(struct file *file, void *fh, return ret; handle->is_streaming = true; + uvc_pm_get(stream->dev); return 0; } @@ -873,7 +877,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_pm_put(stream->dev); + } return 0; } @@ -1410,6 +1417,8 @@ static long uvc_v4l2_compat_ioctl32(struct file *file, void __user *up = compat_ptr(arg); long ret; + guard(uvc_pm)(handle->stream->dev); + switch (cmd) { case UVCIOC_CTRL_MAP32: ret = uvc_v4l2_get_xu_mapping(&karg.xmap, up); @@ -1444,6 +1453,16 @@ static long uvc_v4l2_compat_ioctl32(struct file *file, } #endif +static long uvc_v4l2_video_ioctl2(struct file *file, + unsigned int cmd, unsigned long arg) +{ + struct uvc_fh *handle = file->private_data; + + guard(uvc_pm)(handle->stream->dev); + + return video_ioctl2(file, cmd, arg); +} + static ssize_t uvc_v4l2_read(struct file *file, char __user *data, size_t count, loff_t *ppos) { @@ -1529,7 +1548,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 diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index fbe3649c7cd6..eb8e374fa4c5 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -766,6 +766,7 @@ void uvc_status_put(struct uvc_device *dev); /* PM */ int uvc_pm_get(struct uvc_device *dev); void uvc_pm_put(struct uvc_device *dev); +DEFINE_GUARD(uvc_pm, struct uvc_device *, uvc_pm_get(_T), uvc_pm_put(_T)) /* Controls */ extern const struct v4l2_subscribed_event_ops uvc_ctrl_sub_ev_ops; From patchwork Wed Feb 26 14:23:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13992575 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7746E2288C0 for ; Wed, 26 Feb 2025 14:23:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579817; cv=none; b=HzapJSjAI/oMqOpW95rbhgXvTFR+qZ5T66l8iQ9a828x8W1M36gQbbW7+zbUhXa4deDTA+kPbkhRXb8K+sfUR7NNGdkWDz/0NNEKosfnSX/e5zGfvgGRjP+iIdZcFqwIftf5TTiedAzYAgi+I7LFGwwDLTGo9k9IZq1egQieMxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579817; c=relaxed/simple; bh=dw2qCpBVW0oF8+tSPBXZ2JZkiHmFw0P6jwMv0gbw+7c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Dgtc5T3+nAWH0nOutB5wHT/wrWkAJDQ7MzpMs0drqOPREpNvHuI+dNOgkC2EIzUnIbtJPQrxB+hrAt6l3NSWLtaMIg0TsPDzT/g44msVilS6a9gDk6TjRTdO0LMTkv5huqElcXGhPD1j1nvPXwp4GeX53bV421OqpXow6Zcn1pE= 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=fmhPMZj/; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fmhPMZj/" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7c0818add57so692148885a.3 for ; Wed, 26 Feb 2025 06:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1740579814; x=1741184614; 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=KYDs65iHnr/HrHNwFIq/xPxUuGa4QvYVvNxcsi3oCLs=; b=fmhPMZj/4voxDZ3TwZxuqRET5S+aTihXU8U326TydySd5BkZSu1Eu4sHVmBKNJ0uGy ZOTXD5LODMdyrDSBl1zpknffXr1qmdZ3CffcZi1bW35zv5LUGW4tnLSehYrSsw3epCAM oK2yjxf/FkAW6Ey6P08x9MMb09em6QKt1urls= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740579814; x=1741184614; 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=KYDs65iHnr/HrHNwFIq/xPxUuGa4QvYVvNxcsi3oCLs=; b=Uqv/Htwvdf1OsWS/SsTdMH8X+DwRWD5mkY7ALLGPcbmScYn24cfnyHS5wASeBsUsvm iaDdJKPejuu/XE7wo/zEYc0TFeT3sxkKbBnzUFzS3H1GaDoBWOeGXlGACO1nWQLowjWD X0VINudC8xjUBBLi4YlKikiAJ/U6cLUha9v9SGMCU1mbMGhSXxMNd3CJ3u35sI3oqHrJ zj7MQqJYUH/b+TBw0jpdEBrBQgSEA5dy3KNUK4Xrvatg0fqyLMpcIl6ouXSNcYlxp3ZB AumZ+Hp6s1uT071uPT1oUi+KblUD+ii779ifiZM6BfMBgouT6Vrhk1RFEODYBZnZVftq luJQ== X-Gm-Message-State: AOJu0YwbivBkIbggpAUinpaRJz5Xf2A0r/O0zq3La8RPYeXW257RqeSU v5OKxfW793vSSWBfN+ALW99indFHiTnHdIXUNDns1775KTHI4gTbdN8bbCcr1SR00eXlN6RKFSY = X-Gm-Gg: ASbGnctXVicP/PEaokCnJHTtBrNjKv/9xHJHYlDB/r5v90xDXlesKWJAzQwNQE3zheE STNXcQcl3TA6RtPba4ks2OkO6KG6AhM+7oCfxypwI3H+zE9J2vTH8jqggvBclOki484ODKOIvKi TqCCvFF8qErr7A+ESEHniZfga27ObZEc5GSoyMA8AdQ3fIXnuPTDCzkzwGAFDsrbDLKmGvCg8/F gXKhGKZ+DaKsVeTpPP8bHYabj8D04F4d14xfGDDXDe2teH+UH15jiwkLiuN9rs0ntv1s2sRjeTT nv2FdlsoV4pf6MPbsgxVxI0vZZF27no0J126yixtIXOSq1ae2BPOOv4ABGG6K0lLwLAMFbndoZW GOM0= X-Google-Smtp-Source: AGHT+IHuBFTmRowGPXy5shP9GSkIqBZ6nfFU0exVZOHDnxwl24falNaz1yGkMFwRvKIgYhyKtaXQxA== X-Received: by 2002:a05:620a:2a0f:b0:7c0:b76a:51d5 with SMTP id af79cd13be357-7c0cf7d816bmr2776159885a.0.1740579814399; Wed, 26 Feb 2025 06:23:34 -0800 (PST) Received: from denia.c.googlers.com (15.237.245.35.bc.googleusercontent.com. [35.245.237.15]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c23c33cfb0sm246336085a.103.2025.02.26.06.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 06:23:33 -0800 (PST) From: Ricardo Ribalda Date: Wed, 26 Feb 2025 14:23:30 +0000 Subject: [PATCH v4 4/5] 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: <20250226-uvc-granpower-ng-v4-4-3ec9be906048@chromium.org> References: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@chromium.org> In-Reply-To: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@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.14.1 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 Reviewed-by: Hans de Goede --- 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 1c9ac72be58a..6af93e00b304 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -652,7 +652,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__); @@ -662,12 +661,6 @@ static int uvc_v4l2_open(struct file *file) if (!handle) return -ENOMEM; - ret = uvc_pm_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; @@ -701,7 +694,6 @@ static int uvc_v4l2_release(struct file *file) kfree(handle); file->private_data = NULL; - uvc_pm_put(stream->dev); return 0; } From patchwork Wed Feb 26 14:23:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 13992576 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED676229B32 for ; Wed, 26 Feb 2025 14:23:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579819; cv=none; b=rCnFE3G6YY1AYMf+3AGwVhWLQgxa1ECeGlI/QMp7p7sVh73ZUT2JcsRJuGLZIkrX9GjVf9+EdDR+kmhCgvaloeY42q15v5xZhC8NpG0UWNo6hVwd0GVa0a7LFXOTty5u9yeXnPU8HOVOh0pXF73TwKCZV8XiW9/B9IqEtB/1p7I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740579819; c=relaxed/simple; bh=R9QrElg18QTPPLjHryDyJoCPAU+VfX0dGP/jT9Hqae0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HYN0u5yevy7cNnsw1FBhJ0uXSxYOlq2eJW3MGyCvJ7jY3bcvDCGf9reLp3z632lukp6T02nplqhtuqa5Hd0tJ2z/aRZYOu9yw/VRq3QlsljV916Xown5YWQ4TE2Ho15yNJehqAJAyrm9xM6mtFFjl14CkrVlqknpS68Ivb002F8= 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=V3KwENbW; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="V3KwENbW" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7c0b9f35dc7so933892785a.2 for ; Wed, 26 Feb 2025 06:23:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1740579816; x=1741184616; 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=9KEERa7N5D4CRNojIsTNdFIgtRBSnpqe9YJ9niy4368=; b=V3KwENbW4YPlMU9AqXfYm4P+ohsG9TPxKs7iobxygQiqcGWIFDclViut12mcBcLozV LqV64WuN4lu+7V0HB6yXPpL+0C50zLwMZnudWvKNrK2SeFNv7oluEmMkaragGqXhLTkZ KAUiGuWqeQA6EqvOYNC2lBK1PJ7YjULlpMVzY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740579816; x=1741184616; 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=9KEERa7N5D4CRNojIsTNdFIgtRBSnpqe9YJ9niy4368=; b=kVo0x99bM2tTg0N0kp30PD5rmxxqLgd8/XUPldWyZnltA7JKLD0RHYh0bBLJ0iIg7E z62hxUvwNMBUDEbNc9vXdLqMMt+VZrAbz4blagg8ljjDGQ89mbMvgewJOFniyqs+A3Eh dXqpcyN+1AU5hTC3L/kBKhCAGEcix5ifbbEVGYdh4+2/paCoRo5zCfBpJs7iAmlSD1+B isDCMZ7di+qcIf2QWceP0pZhASWJTSx44ocLTqOHL2DOmL/FbX/8aKSSNDpugMvFnd0l vDIJALDjpCKMC4/QET+88BBIxPDMhcLckLs+/d7u7yDxtA02nJEJPIPjUkA3pKc1iI4n KTdA== X-Gm-Message-State: AOJu0YxGC1QgCCa2aiQY/ob4DqpD/oCV+ya9FsMHhV3jHPI0I8BBQ+qT VKuXdjWRJ2auTSApBuaw5GPx4pRG5aRckhpobwJuEIOhgLfFZKN/VzveE/CLaw== X-Gm-Gg: ASbGncsTWOjiIVTWi8rCQ/BOfnZnMOEvbzx93VobjzVAO3LIFQkKWPCkPWlc2MFXHaH x5u9z7Jsfr7L/3LxGSYnPk+RkMQNTInEIGfmfJJDPxDaJ/gKfZ66d6fG5TfEmbtBKY2D602vn4j +Z0Bi/4XiTfwwjVAD9u5BhXBiAgHbhxPHj+0SlaIo0huN2jRZko4vsZ404opq3auO+8S0YDZn9A bvqPRewrVfJ4voxolmI9ZNrQEsv3MDei8vB3tn5HLldP7QXlUU5bU8zGRCDirTkCJ4Brd59A1bX G4vzkzhwpyifpZe+9rMV3J/9dgRXRhZidNFDZFYWcEM9TtDxW4WGSOSk+2P3rDLkVah2urtk4Ox lvDY= X-Google-Smtp-Source: AGHT+IFYWattDD81UWH54aS/cRKfe95cQMADw1AlcxpsVhbtQXOtLPwSz7HYmPnEqiQEI4Klm2FKVg== X-Received: by 2002:a05:620a:19a8:b0:7c0:874f:c87 with SMTP id af79cd13be357-7c247fcb77cmr516463985a.35.1740579815835; Wed, 26 Feb 2025 06:23:35 -0800 (PST) Received: from denia.c.googlers.com (15.237.245.35.bc.googleusercontent.com. [35.245.237.15]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c23c33cfb0sm246336085a.103.2025.02.26.06.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2025 06:23:35 -0800 (PST) From: Ricardo Ribalda Date: Wed, 26 Feb 2025 14:23:31 +0000 Subject: [PATCH v4 5/5] 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: <20250226-uvc-granpower-ng-v4-5-3ec9be906048@chromium.org> References: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@chromium.org> In-Reply-To: <20250226-uvc-granpower-ng-v4-0-3ec9be906048@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.14.1 There are some ioctls that do not need to turn on the camera. Do not call uvc_pm_get in those cases. Signed-off-by: Ricardo Ribalda Reviewed-by: Hans de Goede --- 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 6af93e00b304..de8d26164996 100644 --- a/drivers/media/usb/uvc/uvc_v4l2.c +++ b/drivers/media/usb/uvc/uvc_v4l2.c @@ -1450,6 +1450,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_pm)(handle->stream->dev); return video_ioctl2(file, cmd, arg);