From patchwork Fri Apr 4 06:37:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14038153 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (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 6F5331624CE for ; Fri, 4 Apr 2025 06:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748662; cv=none; b=iDRSAsyvfH2LqSnA2R6lqkTJjqcakfmemN++m7AnL2mLnHZSkNLMInew7RzO6pX+s/sZhf5sDYY6WSjLEmxCe0lJ/XL2sZhoZKIcXUcjYcxPV9Lqses/w/pt0ZFgzbOQPMmYmZCBi/Mq6uMAaVpBTa2JtxcjsSR2o5I8/RAFV2U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748662; c=relaxed/simple; bh=LA7uZ6q3Sc7Jg4Eh7U3qdrnVOUP1fZHPRdVwZ90iFbI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FYLbxJPMlX+JScEmhLH9WIXnheaDp8beaco7vb/P5ESoxKoqUY/sD7YKCQ6WwcxXCJF9dGtpy0IW9zlhaGJA8aapKxivjtesb386mLYddxe3MKCfavH9m1F7ouGaYxUUVD1rRXEAcc/FSg6gHsUiWPowY20Z77sJ7axi81iglEM= 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=hZYMBiVr; arc=none smtp.client-ip=209.85.167.50 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="hZYMBiVr" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-54af20849adso1633128e87.1 for ; Thu, 03 Apr 2025 23:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743748658; x=1744353458; 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=ptSauccsQCiihyTIqD40ILfoZlJ+Jkp9zzyDCujSkmg=; b=hZYMBiVrrwl2CFEk8rfiWYylTtD/p2JsPLOGY6mf6Q3UzPXvkOPtWIdwE/At620zTq fRM23lm5+R+RywGZn77dPzhbJJtAth1z+ef6DNYVmwPMCoaSgWZ6C7TX2AXYwtWrLoJy KDfabVhNO0ER34CsCT68BadegARW8jPrfy3UA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743748658; x=1744353458; 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=ptSauccsQCiihyTIqD40ILfoZlJ+Jkp9zzyDCujSkmg=; b=hbH8cI2tJklKiyqwcoD9xo4cU7CK3Gl+oWBt9f4+dke4j8L1DBLlA8vE2arNjxTsW3 X5sbQ4Msqzbo+gCBQH3dsokACdH6pPUVdJvJiRs8aiybHpVyBuAoPibxYffavGV7+ltl jys10AuKeOwUMdjMC4/oOuw2GHZLVs3ztvvtvFbMR/WrdACPpdNTLrinV2Oc0Rz630FN h4TONCVnv6s5cFjnfpcZYH1klJyymlsSyXvHoaEYHzpXAKL5S62gp+phQ/rRq4F83L4W 1qM7xt9UWwJ7WtmrHaGXbskvIzxo90SKm7GyTrYAeUVrnbNNYbNgK7s4IZWAKXlf1aXG Youw== X-Gm-Message-State: AOJu0Yx8f9lu3XaUHBK1qh8X9HipPwRMuWSjR/DnwlSVedRr2QtF4rnk fxOwM1kwFQfVrlN4EyCXQM++AXsHn8F8YGR2IZzAPMw0B8vBJGkymzOySE+6bg== X-Gm-Gg: ASbGncuFYT2Iaf164aXhKxpJDZfyaI9iK8j46wUYXvjhgrK1tRMWk4QLZF1S5ddF4+9 /567Gzjxb1N7pzLvFJMMkoyQIiUjapCeoDeFTwHmdMsBy8+rVXkH28W9rdXTWcYXNg1xQEI1dnM 8O28tb7C5maQAzCGQDfNjgaoHKRaI8Qbn9grP4PdPabwD4/iOQqFIU6EpNCHOae5nJRSYJvL90s rxKDJUIT6jWb53zWcQyU6EMIztDlYRKDkK7ZCYfUgP47bZfSMiyYZYgry2IZ0FHRalmZMyzNAI1 NANkQ8aNy7ReyT5SX8e7g+uoM6ffMjzn6gUMHzZLHua6RXGt+RnBO8ZEXdGaTa/7TtblSZVPaHx 56C/7N8Zux5mnfFhAZQhttQ9w X-Google-Smtp-Source: AGHT+IFe0yc7cU3i1TuFDXhwgGxvVCCEnVSWjWSy8bq9xJ+B6v2LXYpgvddwkI0CUCf2TzgjhXvGGg== X-Received: by 2002:a05:6512:1281:b0:545:a70:74c5 with SMTP id 2adb3069b0e04-54c225d560cmr612312e87.13.1743748658431; Thu, 03 Apr 2025 23:37:38 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e672444sm338275e87.251.2025.04.03.23.37.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 23:37:37 -0700 (PDT) From: Ricardo Ribalda Date: Fri, 04 Apr 2025 06:37:34 +0000 Subject: [PATCH v5 1/4] media: uvcvideo: Do not mark valid metadata as invalid Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250404-uvc-meta-v5-1-f79974fc2d20@chromium.org> References: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> In-Reply-To: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda , stable@vger.kernel.org X-Mailer: b4 0.14.2 Currently, the driver performs a length check of the metadata buffer before the actual metadata size is known and before the metadata is decided to be copied. This results in valid metadata buffers being incorrectly marked as invalid. Move the length check to occur after the metadata size is determined and is decided to be copied. Cc: stable@vger.kernel.org Fixes: 088ead255245 ("media: uvcvideo: Add a metadata device node") Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_video.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c index e3567aeb0007c1f0a766f331e4e744359e95a863..b113297dac61f1b2eecd72c36ea61ef2c1e7d28a 100644 --- a/drivers/media/usb/uvc/uvc_video.c +++ b/drivers/media/usb/uvc/uvc_video.c @@ -1433,12 +1433,6 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream, if (!meta_buf || length == 2) return; - if (meta_buf->length - meta_buf->bytesused < - length + sizeof(meta->ns) + sizeof(meta->sof)) { - meta_buf->error = 1; - return; - } - has_pts = mem[1] & UVC_STREAM_PTS; has_scr = mem[1] & UVC_STREAM_SCR; @@ -1459,6 +1453,12 @@ static void uvc_video_decode_meta(struct uvc_streaming *stream, !memcmp(scr, stream->clock.last_scr, 6))) return; + if (meta_buf->length - meta_buf->bytesused < + length + sizeof(meta->ns) + sizeof(meta->sof)) { + meta_buf->error = 1; + return; + } + meta = (struct uvc_meta_buf *)((u8 *)meta_buf->mem + meta_buf->bytesused); local_irq_save(flags); time = uvc_video_get_time(); From patchwork Fri Apr 4 06:37:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14038154 Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9398018FC92 for ; Fri, 4 Apr 2025 06:37:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748666; cv=none; b=Lb9k6OenLLbhxFBfgQV8H4jrzcqU9e0wsaWLlv1gFOAXyAzwMBcNDL609Y2HKbcvnGsswE5V1xV0OJA3SSh4MHd55UJCKFq0+wJKMLUdEEPMi8AMtgcnKRtHVM8HqkSL9gJlaipBP+ocddzhwASP1PyzqVjgTWq8XI/0H+85QcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748666; c=relaxed/simple; bh=A+EYzZLGQHIPJ5VAoM/+3fe53Af6CgodqviiAM/ONBM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LOkq1AKqJTVs637+LFYEDiA80A0iPRYdOY5y5QxCmQgGdnsjBtlPFEZAI2KRntpNYtYEzNu1irypbAuwH1SRhwGrkq+i8EHYzk7bbpHT81/Yj+W67U/8zqPy/1zDGo2i6Gva2+3aCV5rJ3MKwHgzjENiax0nZKg+Af2s57N0khA= 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=SuJ/HdOA; arc=none smtp.client-ip=209.85.167.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SuJ/HdOA" Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-54991d85f99so2784366e87.1 for ; Thu, 03 Apr 2025 23:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743748662; x=1744353462; 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=uAivlvh8Vrg1UGAUIkAMwQONWXUXc2TvgNk5knB4y0c=; b=SuJ/HdOAi0xoPXS9rZe+WQUKD8sk6tvc60gxsdCvKk6yPyRLSIriLfMCYqg4Pj5QCk bRBW8dADviYbrFIXdIk4B4pfV60J/Iya7N81NGyV6cqaVM3rPuDVWu0owhzQrEN0AfaZ mgs2n3FNuXkaStTViPf0gEZOm9Kty5v1kr11Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743748662; x=1744353462; 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=uAivlvh8Vrg1UGAUIkAMwQONWXUXc2TvgNk5knB4y0c=; b=YckuFQN4H90VQULwPKuVCyx/wqUFLCOY/4OBaD00zCpG39AilCavfLVyMat55JMndn R0I9oUdwLn11z0tLOEflurTM9GYE8ivSyk/ENushEg+Sy1CcT1oHxz+Edt1+Xertw6Vf COawL82F2JVRBIvHDN0WD/Hj9y7PKwSj7JE4QCaqcyR3tb/T54P25INLQscgXLhl/PD1 24Ddnmt9CXsWafDqNvbBXHu7pEItlOf6YnyrbKdXWE4gQ+53o15Xm4isztEWDR0Xm1Hn B74i5m6f4+CGIX4AteLtKVkt+rj9MvWejvYWeGJLPFREvSpym6MAdyqD6PfMmPMyqI96 FP7Q== X-Gm-Message-State: AOJu0Yyr3TyV9wLEZ5jIlY5gN0ElFixj+6Xl5iAdjIPZBzAoXQ+HCq20 ZPDYIEx+wbdYYxx4ECL1sQ3vb8wTTC2DJa9RjMCdXs+nY/1MW4mohuCjsnQz8g== X-Gm-Gg: ASbGncuc95nZCHlZVwbxp40FGmlNsi/UYvC0nCGR1iIrVzm5rD++QiPe4vhr8U2hOKZ 9U/1OfO/D92unwVC9KD14xCYTNehY8lk4VUBx0Qzd9G408qj2zEEkCLdcmzSUd6HzBlAcQlG4J/ s9vbDFh7AcQTt+yEmmz1c7DWtaBd95Q9UWn6yXJ4S9EvsoSiTAIxJowgKR4sTnV9i3BQwpS7BDA wr6CbBQfe4aImKvc/eH6cy74I5KKyCY8UdEOTfPrJQPzXUncIFkzmFee5+U9Bq6135eCCypOdmn YtCbL1LT3n4TsQ5A0Duzt45Aa5TYrm7Qmk0VlHM+KplFvakIVzTzH6zu58yYrTfe0QhK4/IcR6B YXgZSGuEVA4XdPchGb5/wIdstvP3LQplzNmA= X-Google-Smtp-Source: AGHT+IF/wt1Uxur7keuKQbSIAvPFmsIoQlSPiqbrU44NDcgTLn1iSIA3tNK/AaEw+pgVlogdaFQe2w== X-Received: by 2002:a05:6512:3501:b0:545:4ca:d395 with SMTP id 2adb3069b0e04-54c225afc3fmr610345e87.2.1743748659727; Thu, 03 Apr 2025 23:37:39 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e672444sm338275e87.251.2025.04.03.23.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 23:37:38 -0700 (PDT) From: Ricardo Ribalda Date: Fri, 04 Apr 2025 06:37:35 +0000 Subject: [PATCH v5 2/4] media: Documentation: Add note about UVCH length field Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250404-uvc-meta-v5-2-f79974fc2d20@chromium.org> References: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> In-Reply-To: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 The documentation currently describes the UVC length field as the "length of the rest of the block", which can be misleading. The driver limits the data copied to a maximum of 12 bytes. This change adds a clarifying sentence to the documentation to make this restriction explicit. Signed-off-by: Ricardo Ribalda --- Documentation/userspace-api/media/v4l/metafmt-uvc.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst index 784346d14bbdbf28348262084d5b0646d30bd1da..42599875331c0066cf529153caccb731148023b9 100644 --- a/Documentation/userspace-api/media/v4l/metafmt-uvc.rst +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc.rst @@ -44,7 +44,9 @@ Each individual block contains the following fields: them * - :cspan:`1` *The rest is an exact copy of the UVC payload header:* * - __u8 length; - - length of the rest of the block, including this field + - length of the rest of the block, including this field. Please note that + regardless of the this value, for V4L2_META_FMT_UVC the kernel will + never copy more than 2-12 bytes. * - __u8 flags; - Flags, indicating presence of other standard UVC fields * - __u8 buf[]; From patchwork Fri Apr 4 06:37:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14038156 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60B9C1917CD for ; Fri, 4 Apr 2025 06:37:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748668; cv=none; b=AzmveGbrG/DNUaMaZzFO2SC0RomHqQ6EHQOxZ6xD32GaO21BgIsAXOfmKoL+WfN7QXdV9b0qN6AYtaVpm0bqTh8KVAEyPUrZLDNKz4AHxAMKSmGPq+3X03noWspyUiM9dp02olsXneUFGTtIOBW+BhaqtDSbTsn3yz2YGUoELXE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748668; c=relaxed/simple; bh=b7Zu7FXe5Yk8VGSP7zeuJTUbCpv87TetJKqJT0JTgig=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MFGP9FsuXX20IGtT1MaT410ciESukc5Q2bLloeX3WxZF2zL51LNRO9+oglbueIljw2wbXCtZQ2KtZStittm4w9ENdkTHrEpJkm6CHuwCuK+zf6sQ6wqM7z7A4wTJwDbQyY3lvEIG18STZIngTS/YBGwQqVRUi5FJCl0B8F4U7zg= 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=aN/WiZmE; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aN/WiZmE" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-54954fa61c9so2015060e87.1 for ; Thu, 03 Apr 2025 23:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743748662; x=1744353462; 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=Yet+7EChC7n/+00JGsTh9/MSwH5sjxZLzKQLC8/d9K0=; b=aN/WiZmEVo6lxXUGqzzyylI5g+hYTIvUE+dg47VWflEizIzvNT3gtDXUOTGdMUe5gd vz3tdi7ygi5s3yroc9E4rScgYDhjaq43uXW74ulW1RSmpQybLUl7yAKxtQkyE17h1qTT QfpviigFrMCTqszWrd6pdjpt+uD1OVcwIdVjw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743748662; x=1744353462; 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=Yet+7EChC7n/+00JGsTh9/MSwH5sjxZLzKQLC8/d9K0=; b=URokdGzrOgJIuI7ReS9UjU6YzrvVBkZw0a4ODOg/+xAfnowpwsr+mfJf6LEcEq4bIv aSE4mO+TiY8eJqLnYZLQk3vlOQNs4+Ap76J9Ovq+7GcgroPhShOGuWPMW7UtWkK+aqVq 2adm50JrcX3SXyygTuCR5k1a0WaGkBOkpDHOhVKLoILvjHRumSmZe4VPqa0rkTmCFtKX cyEOQFFeEAe6i4+ErIkzAL79mEcqpPuKPBztayrEEuBy0cJV6JC138n9TlZd8RFBx29e 5S44OMK/jUoVPYUFxndyCdGkpA+0mQPb/VvrZB4jeU6IgYwFXWIDaMKB42sOl+Qulg4Q owkA== X-Gm-Message-State: AOJu0YzYDbFeVe9zvmns1dmoIc746RREVwk2nOMvU3TfJBcRUMWHEugP w59OLRs8qYprRk4wZ68fR31GCfuNV9MvqQr1ojSRK6ijLVaINOebzFGwpDd62w== X-Gm-Gg: ASbGncu4m1ObCABoj73Wr25eTjgg13Lh+2vwEwIhwwDItt39if2ZnSboaPnAPqqkLVA Wnan+fMeYTcOwhzuf54tJaaycp+atWvMfqlp4/Sn9zsdeqx+vuAIA7nD2/LKuqxXE9oJeOdkhpJ 8YB4iXdbNYP++oYDJw3gRLvyBRpmbUa0tdHVgau1vk+d/HlaRw1Azkqt6IHSMhsNGM+asDbY6qx 43NqxXCMTSrXXj9KrNZqcwAhm12QGU2HrZf9O08/k51LCb4fl+GT4WNiYx89H0a4mZoS3OBd0Dn w0tDpTTIdcliNQ6owJ2OmqQQJ4ADFTs+mcxCSWQUXop1/Mas+6TeTXFerTR0ESu/hHAQaIXvG/y s4CBXGBtmBHl3oJKIe7I1L1L+ X-Google-Smtp-Source: AGHT+IEaIXZCTW3rwp+tjJpUHC5vgWNe4ojs3y5woCDSlLDDC7F6zt9didrHAHJIBVs7/ngkZEewng== X-Received: by 2002:a05:6512:3e03:b0:54b:117c:1354 with SMTP id 2adb3069b0e04-54c22808e8bmr472555e87.54.1743748662450; Thu, 03 Apr 2025 23:37:42 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e672444sm338275e87.251.2025.04.03.23.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 23:37:41 -0700 (PDT) From: Ricardo Ribalda Date: Fri, 04 Apr 2025 06:37:36 +0000 Subject: [PATCH v5 3/4] media: uvcvideo: Introduce V4L2_META_FMT_UVC_MSXU_1_5 Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250404-uvc-meta-v5-3-f79974fc2d20@chromium.org> References: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> In-Reply-To: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 The UVC driver provides two metadata types V4L2_META_FMT_UVC, and V4L2_META_FMT_D4XX. The only difference between the two of them is that V4L2_META_FMT_UVC only copies PTS, SCR, size and flags, and V4L2_META_FMT_D4XX copies the whole metadata section. Now we only enable V4L2_META_FMT_D4XX for the Intel D4xx family of devices, but it is useful to have the whole metadata section for any device where vendors include other metadata, such as the one described by Microsoft: https://learn.microsoft.com/en-us/windows-hardware/drivers/stream/mf-capture-metadata This patch introduces a new format V4L2_META_FMT_UVC_MSXU_1_5, that is identical to V4L2_META_FMT_D4XX. For now, flag this format with a new quirk. Suggested-by: Hans de Goede Signed-off-by: Ricardo Ribalda --- .../userspace-api/media/v4l/meta-formats.rst | 1 + .../media/v4l/metafmt-uvc-msxu-1-5.rst | 23 ++++++++++++ MAINTAINERS | 1 + drivers/media/usb/uvc/uvc_metadata.c | 43 +++++++++++++++++++--- drivers/media/usb/uvc/uvcvideo.h | 1 + drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 1 + 7 files changed, 65 insertions(+), 6 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/meta-formats.rst b/Documentation/userspace-api/media/v4l/meta-formats.rst index 86ffb3bc8ade2e0c563dd84441572ecea1a571a6..4de0d094e0702068be0c59154458c9dfecbfe28d 100644 --- a/Documentation/userspace-api/media/v4l/meta-formats.rst +++ b/Documentation/userspace-api/media/v4l/meta-formats.rst @@ -19,6 +19,7 @@ These formats are used for the :ref:`metadata` interface only. metafmt-pisp-fe metafmt-rkisp1 metafmt-uvc + metafmt-uvc-msxu-1-5 metafmt-vivid metafmt-vsp1-hgo metafmt-vsp1-hgt diff --git a/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst new file mode 100644 index 0000000000000000000000000000000000000000..e6f95a88c0ff061df0b066b12cefc30f946b60aa --- /dev/null +++ b/Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst @@ -0,0 +1,23 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later + +.. _v4l2-meta-fmt-uvc-msxu-1-5: + +*********************************** +V4L2_META_FMT_UVC_MSXU_1_5 ('UVCM') +*********************************** + +Microsoft(R)'s UVC Payload Metadata. + + +Description +=========== + +V4L2_META_FMT_UVC_MSXU_1_5 buffers follow the metadata buffer layout of +V4L2_META_FMT_UVC with the only difference that it includes all the UVC +metadata, not just the first 2-12 bytes. + +For more details check the documentation from Microsoft(R) [1]. + +.. _1: + +[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/stream/uvc-extensions-1-5 diff --git a/MAINTAINERS b/MAINTAINERS index 306b1384eb6d4cb7a310ada44605eaeb88cc732f..a07ed31ab057b98cf801d919b5bbec5ee334c9ac 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -25059,6 +25059,7 @@ S: Maintained W: http://www.ideasonboard.org/uvc/ T: git git://linuxtv.org/media.git F: Documentation/userspace-api/media/drivers/uvcvideo.rst +F: Documentation/userspace-api/media/v4l/metafmt-uvc-msxu-1-5.rst F: Documentation/userspace-api/media/v4l/metafmt-uvc.rst F: drivers/media/common/uvc.c F: drivers/media/usb/uvc/ diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c index 82de7781f5b6b70c5ba16bcba9e0741231231904..fe2678fc795d7fd5a64e8113199012f34c419176 100644 --- a/drivers/media/usb/uvc/uvc_metadata.c +++ b/drivers/media/usb/uvc/uvc_metadata.c @@ -63,15 +63,21 @@ static int uvc_meta_v4l2_try_format(struct file *file, void *fh, struct uvc_streaming *stream = video_get_drvdata(vfh->vdev); struct uvc_device *dev = stream->dev; struct v4l2_meta_format *fmt = &format->fmt.meta; - u32 fmeta = fmt->dataformat; + u32 fmeta; + + if (fmt->dataformat == dev->info->meta_format) + fmeta = dev->info->meta_format; + else if (fmt->dataformat == V4L2_META_FMT_UVC_MSXU_1_5) + fmeta = V4L2_META_FMT_UVC_MSXU_1_5; + else + fmeta = V4L2_META_FMT_UVC; if (format->type != vfh->vdev->queue->type) return -EINVAL; memset(fmt, 0, sizeof(*fmt)); - fmt->dataformat = fmeta == dev->info->meta_format - ? fmeta : V4L2_META_FMT_UVC; + fmt->dataformat = fmeta; fmt->buffersize = UVC_METADATA_BUF_SIZE; return 0; @@ -106,6 +112,27 @@ static int uvc_meta_v4l2_set_format(struct file *file, void *fh, return ret; } +static u32 uvc_meta_idx_to_fmeta(struct uvc_device *dev, u32 index) +{ + switch (index) { + case 0: + return V4L2_META_FMT_UVC; + case 1: + if (dev->info->meta_format) + return dev->info->meta_format; + if (dev->quirks & UVC_QUIRK_MSXU_META) + return V4L2_META_FMT_UVC_MSXU_1_5; + return 0; + case 2: + if (dev->info->meta_format && + dev->quirks & UVC_QUIRK_MSXU_META) + return V4L2_META_FMT_UVC_MSXU_1_5; + return 0; + } + + return 0; +} + static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh, struct v4l2_fmtdesc *fdesc) { @@ -113,16 +140,20 @@ static int uvc_meta_v4l2_enum_formats(struct file *file, void *fh, struct uvc_streaming *stream = video_get_drvdata(vfh->vdev); struct uvc_device *dev = stream->dev; u32 index = fdesc->index; + u32 fmeta; + + if (fdesc->type != vfh->vdev->queue->type) + return -EINVAL; - if (fdesc->type != vfh->vdev->queue->type || - index > 1U || (index && !dev->info->meta_format)) + fmeta = uvc_meta_idx_to_fmeta(dev, fdesc->index); + if (!fmeta) return -EINVAL; memset(fdesc, 0, sizeof(*fdesc)); fdesc->type = vfh->vdev->queue->type; fdesc->index = index; - fdesc->pixelformat = index ? dev->info->meta_format : V4L2_META_FMT_UVC; + fdesc->pixelformat = fmeta; return 0; } diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h index b4ee701835fc016474d2cd2a0b67b2aa915c1c60..123446683e22589f23b5228a00240e54f00ae6f1 100644 --- a/drivers/media/usb/uvc/uvcvideo.h +++ b/drivers/media/usb/uvc/uvcvideo.h @@ -77,6 +77,7 @@ #define UVC_QUIRK_DISABLE_AUTOSUSPEND 0x00008000 #define UVC_QUIRK_INVALID_DEVICE_SOF 0x00010000 #define UVC_QUIRK_MJPEG_NO_EOF 0x00020000 +#define UVC_QUIRK_MSXU_META 0x00040000 /* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index a16fb44c7246e35f3710306fde5dfc15329b4d95..12f1232e5ca3acdefede8f9751f9e7191eeae58b 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1457,6 +1457,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_META_FMT_VSP1_HGO: descr = "R-Car VSP1 1-D Histogram"; break; case V4L2_META_FMT_VSP1_HGT: descr = "R-Car VSP1 2-D Histogram"; break; case V4L2_META_FMT_UVC: descr = "UVC Payload Header Metadata"; break; + case V4L2_META_FMT_UVC_MSXU_1_5: descr = "UVC MSXU Metadata"; break; case V4L2_META_FMT_D4XX: descr = "Intel D4xx UVC Metadata"; break; case V4L2_META_FMT_VIVID: descr = "Vivid Metadata"; break; case V4L2_META_FMT_RK_ISP1_PARAMS: descr = "Rockchip ISP1 3A Parameters"; break; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index c8cb2796130f8d1b864d669267d2b31f73b839aa..0cf6885a5dc8752326bd10a893d5d09d47993c21 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -851,6 +851,7 @@ struct v4l2_pix_format { #define V4L2_META_FMT_VSP1_HGT v4l2_fourcc('V', 'S', 'P', 'T') /* R-Car VSP1 2-D Histogram */ #define V4L2_META_FMT_UVC v4l2_fourcc('U', 'V', 'C', 'H') /* UVC Payload Header metadata */ #define V4L2_META_FMT_D4XX v4l2_fourcc('D', '4', 'X', 'X') /* D4XX Payload Header metadata */ +#define V4L2_META_FMT_UVC_MSXU_1_5 v4l2_fourcc('U', 'V', 'C', 'M') /* UVC MSXU metadata */ #define V4L2_META_FMT_VIVID v4l2_fourcc('V', 'I', 'V', 'D') /* Vivid Metadata */ /* Vendor specific - used for RK_ISP1 camera sub-system */ From patchwork Fri Apr 4 06:37:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda X-Patchwork-Id: 14038155 Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.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 93A82191F95 for ; Fri, 4 Apr 2025 06:37:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748667; cv=none; b=CH5lu0+fU9soQWOYd5PzfIvSmjL3N1dpLJpLKexMzJO1Mq2B3D220jTcJEEaWfYr8/mdayHEYtNdz0zslgoF3OXOuCzRCX6Q42GR1qO9QAKZ2QmZaR9GL5YJQSqI8W3+H/bIsAI3mD9GxtJI6Qx0QwUeX3qeRepVyUgnsDCS5eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743748667; c=relaxed/simple; bh=+KkdZxdqvHIlFaUxnw0T/2vUmNZjxcvggpVmgCAVYT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gLBGPynJ85fPRY4ehtk4YOjFoBW8EMjAS4NgSrg7JOiVpmTEhz5Wpfq1jmovfqsJq8favCBMvcOXenphQbCbT/mFebyrLUbvJJNv9393mww9jgul1dDs5wnrynBqIfqA1w+FbGYXfSpfXec5HWgz7uD8JfuZpj6FcUodZeowxJQ= 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=Ivw09rEs; arc=none smtp.client-ip=209.85.167.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="Ivw09rEs" Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5499bd3084aso1501607e87.0 for ; Thu, 03 Apr 2025 23:37:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1743748664; x=1744353464; 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=jfKei41NeiW8d42lUMUhoCILXY12OhST2R+tJl7Txyg=; b=Ivw09rEsNhTPbGfMN+6Geejw3Q802OsZA1khp0IBkRAmpKdoAmk2HFu3eldwrvCX/R dCoUrZDs/g/Rz7lIvc8N9w/CxUqgNlmyJCZfNnVBkvRX6fqIZm/OYHQqm/PGtEZwyynF 0cWFp36qnWUrTFHtBv14OdYQOaak+BKZUA59Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743748664; x=1744353464; 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=jfKei41NeiW8d42lUMUhoCILXY12OhST2R+tJl7Txyg=; b=Z8ZPrOqtqwoFjU2I3fzqrcXs7M0cnSGw85wdIGnLZXt07j+N+gacnzl7yKGV5n7tKd G304zovqV7NBZWusuFYTJdRTxC9Bhg3mNniO10Ew7IBeFK7vvqQts3gZpIwC6OWi3UTR df9b/DJyhWFFwJ5mxkjKgIE/uTx4oNZ3yYyQRyfNo1M6RCGNBENYNXpLO0/rzsipBNda KT/zoA0IflvSZq2ybKH2v6gvd0T9WMqq2l7oANZbwozNlH3NmKhSV/um8EeljXGm5Udh GuON5pwNKgCCyZsNS3LAxTdYxeAAP/+NH9tlzAsTjqlEdrFrWk1+cYIya8fFCaC0EhO2 zj0w== X-Gm-Message-State: AOJu0YzzImbGIFxL7/++9LE7CuF9SadcbBZ320GUNVII/exUh3Ylx3Nm QLDRVoDZjU8X19uMZgxHXZA/pUwdfhB27G9LgzirJHWTsY2kJDetcgImbNT7mMWzXPwvxcb9BQM = X-Gm-Gg: ASbGncuoOrHnqGEBShoaKhesP0wUwfZfBafyJ2zQSlORwofKXHEd5nhAKYrwfdGKG+W N/3MuLhkU10gKAxQGQ3CRD4t9htQmzSNoVxCQ07DqXfRDRVVsJFJ1EJSvqUMYKyWmr2UHOQ5SX0 1LaC7ZaNDw3PtCdiZ1CQ/wgx/ZQoGl3RgzhhFp9tkvWp7w08DKgpynG7cDdvFlDSQUQE6U9ieqU QcxpkpyXDtppNIVssWzXnwnMKmXxL5NdFatgo9wKxcSwP1RHGWnYlpccuOeWk2G3ixZVKLs5Qy8 jjizMKFIH+R4b4b75UxnmPm0FSt4gZc2UisivGDt/OiSdQGHHnUitwKqYRHWvWIufY2vfDYgXN1 VlPoya3xdUz1zyus1hdiKG6+9tWAWKIZdsGU= X-Google-Smtp-Source: AGHT+IGiEq5HAfK9gznqpOik3UfipLmtacM6oeNSqlOetaI/lji+MiW2P1IKEgszzXgZO7Lyb2+qvQ== X-Received: by 2002:a05:6512:3da1:b0:545:2871:7cd5 with SMTP id 2adb3069b0e04-54c22776fc6mr564255e87.15.1743748663628; Thu, 03 Apr 2025 23:37:43 -0700 (PDT) Received: from ribalda.c.googlers.com (216.148.88.34.bc.googleusercontent.com. [34.88.148.216]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-54c1e672444sm338275e87.251.2025.04.03.23.37.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Apr 2025 23:37:42 -0700 (PDT) From: Ricardo Ribalda Date: Fri, 04 Apr 2025 06:37:37 +0000 Subject: [PATCH v5 4/4] media: uvcvideo: Auto-set UVC_QUIRK_MSXU_META Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250404-uvc-meta-v5-4-f79974fc2d20@chromium.org> References: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> In-Reply-To: <20250404-uvc-meta-v5-0-f79974fc2d20@chromium.org> To: Laurent Pinchart , Hans de Goede , Mauro Carvalho Chehab , Guennadi Liakhovetski Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Ribalda X-Mailer: b4 0.14.2 If the camera supports the MSXU_CONTROL_METADATA control, auto set the MSXU_META quirk. Signed-off-by: Ricardo Ribalda --- drivers/media/usb/uvc/uvc_metadata.c | 54 ++++++++++++++++++++++++++++++++++++ include/linux/usb/uvc.h | 3 ++ 2 files changed, 57 insertions(+) diff --git a/drivers/media/usb/uvc/uvc_metadata.c b/drivers/media/usb/uvc/uvc_metadata.c index fe2678fc795d7fd5a64e8113199012f34c419176..776d280f34afad515594a873acf075acf0438304 100644 --- a/drivers/media/usb/uvc/uvc_metadata.c +++ b/drivers/media/usb/uvc/uvc_metadata.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -187,11 +188,64 @@ static const struct v4l2_file_operations uvc_meta_fops = { .mmap = vb2_fop_mmap, }; +static const u8 uvc_msxu_guid[16] = UVC_GUID_MSXU_1_5; + +#define MSXU_CONTROL_METADATA 0x9 +static int uvc_enable_msxu(struct uvc_device *dev) +{ + u32 *data __free(kfree) = NULL; + struct uvc_entity *entity; + + list_for_each_entry(entity, &dev->entities, list) { + int ret; + + if (memcmp(entity->guid, uvc_msxu_guid, sizeof(entity->guid))) + continue; + + if (!data) + data = kmalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret = uvc_query_ctrl(dev, UVC_GET_CUR, entity->id, + dev->intfnum, MSXU_CONTROL_METADATA, + data, sizeof(*data)); + if (ret) + continue; + + if (*data) { + dev->quirks |= UVC_QUIRK_MSXU_META; + return 0; + } + + ret = uvc_query_ctrl(dev, UVC_GET_MAX, entity->id, + dev->intfnum, MSXU_CONTROL_METADATA, + data, sizeof(*data)); + if (ret || !*data) + continue; + + ret = uvc_query_ctrl(dev, UVC_SET_CUR, entity->id, + dev->intfnum, MSXU_CONTROL_METADATA, + data, sizeof(*data)); + if (!ret) { + dev->quirks |= UVC_QUIRK_MSXU_META; + return 0; + } + } + + return 0; +} + int uvc_meta_register(struct uvc_streaming *stream) { struct uvc_device *dev = stream->dev; struct video_device *vdev = &stream->meta.vdev; struct uvc_video_queue *queue = &stream->meta.queue; + int ret; + + ret = uvc_enable_msxu(dev); + if (ret) + return ret; stream->meta.format = V4L2_META_FMT_UVC; diff --git a/include/linux/usb/uvc.h b/include/linux/usb/uvc.h index bce95153e5a65613a710d7316fc17cf5462b5bce..ee19e9f915b8370c333c426dc1ee4202c7b75c5b 100644 --- a/include/linux/usb/uvc.h +++ b/include/linux/usb/uvc.h @@ -29,6 +29,9 @@ #define UVC_GUID_EXT_GPIO_CONTROLLER \ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03} +#define UVC_GUID_MSXU_1_5 \ + {0xdc, 0x95, 0x3f, 0x0f, 0x32, 0x26, 0x4e, 0x4c, \ + 0x92, 0xc9, 0xa0, 0x47, 0x82, 0xf4, 0x3b, 0xc8} #define UVC_GUID_FORMAT_MJPEG \ { 'M', 'J', 'P', 'G', 0x00, 0x00, 0x10, 0x00, \