| Message ID | 20260518102451.417971-6-paulk@sys-base.io (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-23456-sunxi=pue.re@lists.linux.dev> X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mxe881.netcup.net (Postfix) with ESMTPS id 8E6B31C07A5 for <noreply@patchwork.local>; Mon, 18 May 2026 12:28:36 +0200 (CEST) Authentication-Results: mxe881; spf=pass (sender IP is 172.105.105.114) smtp.mailfrom=linux-sunxi+bounces-23456-noreply=patchwork.local@lists.linux.dev smtp.helo=tor.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.105.105.114 as permitted sender) client-ip=172.105.105.114; envelope-from=linux-sunxi+bounces-23456-noreply=patchwork.local@lists.linux.dev; helo=tor.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by tor.lore.kernel.org (Postfix) with ESMTP id 7734D3025A58 for <noreply@patchwork.local>; Mon, 18 May 2026 10:28:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D9A63E9C12; Mon, 18 May 2026 10:28:00 +0000 (UTC) X-Original-To: linux-sunxi@lists.linux.dev Received: from leonov.paulk.fr (leonov.paulk.fr [185.233.101.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82B123E8C79; Mon, 18 May 2026 10:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.233.101.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779100079; cv=none; b=Ahg3Ma/E4C/71EgMcDaQhBZ//6JSiiSu9xPnbuaQRf/rPCjSsaCuEwYw9SypKvWxYRpdBpk/m2b8fscPP4m8gttIDy7bACrWSC2dZz6Xcnn/yrbEGVM95uw3YGvBygUgOVPr4V5ebDZ30T2D1hwx+/aYZIOatLtVXX+a9yFpbvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779100079; c=relaxed/simple; bh=rOPLs8ziQTXtf4yGzefCGTBcEtcsiUtr3cFFKYF7g8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U9YjgYCaVbLrpfiBF46qdw8uHlK+19wFWpYHWKxlOTxl4gRmhZN4hUYkGMmX/XutoQoxlZzze872Q6pQcG8KjaxxpsAkWoC14eiZlsTS0N0DrVK0K9fKZLXwoPFqr4z9ljoV//6sgshwg4nIdQNLcxbW/pHsuXS9dpQ6T4K7OKk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sys-base.io; spf=pass smtp.mailfrom=sys-base.io; arc=none smtp.client-ip=185.233.101.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=sys-base.io Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sys-base.io Received: from laika.paulk.fr (12.234.24.109.rev.sfr.net [109.24.234.12]) by leonov.paulk.fr (Postfix) with ESMTPS id BD1D31F80044; Mon, 18 May 2026 10:27:44 +0000 (UTC) Received: by laika.paulk.fr (Postfix, from userid 65534) id 20F4DB4080B; Mon, 18 May 2026 10:27:44 +0000 (UTC) X-Spam-Level: * Received: from collins (unknown [192.168.1.64]) by laika.paulk.fr (Postfix) with ESMTP id A3E79B407F2; Mon, 18 May 2026 10:24:54 +0000 (UTC) From: Paul Kocialkowski <paulk@sys-base.io> To: linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, linux-staging@lists.linux.dev Cc: Paul Kocialkowski <paulk@sys-base.io>, Mauro Carvalho Chehab <mchehab@kernel.org>, Chen-Yu Tsai <wens@kernel.org>, Jernej Skrabec <jernej.skrabec@gmail.com>, Samuel Holland <samuel@sholland.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Arash Golgol <arash.golgol@gmail.com>, Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Nicolas Dufresne <nicolas.dufresne@collabora.com> Subject: [PATCH 05/16] media: v4l2-common: Fix NV15_4L4 format info block height Date: Mon, 18 May 2026 12:24:40 +0200 Message-ID: <20260518102451.417971-6-paulk@sys-base.io> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260518102451.417971-1-paulk@sys-base.io> References: <20260518102451.417971-1-paulk@sys-base.io> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: <linux-sunxi.lists.linux.dev> List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev> List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-0.66 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.105.105.114:from]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; MAILLIST(-0.15)[generic]; MIME_GOOD(-0.10)[text/plain]; BAD_REP_POLICIES(0.10)[]; HAS_LIST_UNSUB(-0.01)[]; FREEMAIL_CC(0.00)[sys-base.io,kernel.org,gmail.com,sholland.org,linuxfoundation.org,ideasonboard.com,collabora.com]; DMARC_NA(0.00)[sys-base.io]; MIME_TRACE(0.00)[0:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[tor.lore.kernel.org:rdns,tor.lore.kernel.org:helo,sys-base.io:email]; RCPT_COUNT_TWELVE(0.00)[14]; FUZZY_BLOCKED(0.00)[rspamd.com]; TAGGED_RCPT(0.00)[]; PRECEDENCE_BULK(0.00)[]; FROM_HAS_DN(0.00)[]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; RCVD_TLS_LAST(0.00)[]; R_SPF_ALLOW(0.00)[+ip4:172.105.105.114]; TO_DN_SOME(0.00)[]; RCVD_COUNT_SEVEN(0.00)[7]; R_DKIM_NA(0.00)[]; TAGGED_FROM(0.00)[bounces-23456-noreply=patchwork.local]; ASN(0.00)[asn:63949, ipnet:172.105.96.0/20, country:SG]; FROM_NEQ_ENVFROM(0.00)[paulk@sys-base.io,linux-sunxi@lists.linux.dev]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1]; FORGED_SENDER_MAILLIST(0.00)[] X-Rspamd-Queue-Id: 8E6B31C07A5 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= |
| Series |
media: sun6i-csi/isp MC-centric support and cleanups
|
|
Commit Message
Paul Kocialkowski
May 18, 2026, 10:24 a.m. UTC
The NV15_4L4 format is specified as a 4x4 format, not 4x1.
In addition the block size should not take subsampling in account,
so specify it as 4x4 for both luma and chroma.
Signed-off-by: Paul Kocialkowski <paulk@sys-base.io>
---
drivers/media/v4l2-core/v4l2-common.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Other tiled formats (MT2110T, MT2110R, NV12MT, NV12MT_16X16) incorrectly take subsampling into account in their block_w and block_h definitions, causing chroma plane under-allocation.
- [High] Formats with bpp_div > 1 (e.g., NV15, NV20, Bayer 10P) lack block_w definitions, causing integer truncation in stride calculations.
--
(Note: The format of this report is altered due to recitation restrictions.
The original patch code is not quoted inline; instead, a free-form summary
of the findings is provided.)
Commit: 04995fa68d4b9c2dd80539724de182a617de7bac
Author: Paul Kocialkowski <paulk@sys-base.io>
Subject: media: v4l2-common: Fix NV15_4L4 format info block height
This commit corrects the NV15_4L4 format info by specifying it as a 4x4
format and ensuring the block size does not take subsampling into account
for luma and chroma.
You noted in the commit message that block size should not take subsampling
into account. Does this mean other tiled formats like MT2110T, MT2110R,
NV12MT, and NV12MT_16X16 are currently incorrect?
Looking at their definitions in v4l2_format_info(), they seem to divide
their chroma block dimensions by the subsampling factor. For instance,
MT2110T defines block_w as { 16, 8, 0, 0 } and block_h as { 32, 16, 0, 0 }.
Because v4l2_format_plane_stride() and v4l2_format_plane_height() apply
these alignments to the luma width and height before dividing by hdiv and
vdiv, an unaligned dimension like width 8 and height 16 would correctly
align the luma plane to 16x32. However, for the chroma plane, it would
align the luma dimensions to 8x16 before dividing by the subsampling
factors.
Could this result in the chroma plane being allocated only half of a
macroblock's required dimensions, leading to out-of-bounds memory writes
when the hardware writes full tiles?
Related to the macroblock sizing logic, do formats with bpp_div greater
than 1 need explicit block_w definitions to prevent integer truncation
during stride calculations?
Linear packed formats like NV15, NV20, SBGGR10P, and the RAW_CRU variants
pack multiple pixels into a fractional number of bytes. For example, NV15
has a bpp_div of 4. Because they currently lack a block_w definition, they
default to an alignment of 1.
If an unaligned width is passed to v4l2_format_plane_stride(), the formula
(aligned_width / hdiv) * bpp / bpp_div truncates. Using NV15 with a width
of 2 calculates a stride of (2 * 5) / 4 = 2 bytes. However, two 10-bit
pixels require 20 bits (2.5 bytes), so the stride rounds down.
Could this allocate less memory per line than the requested pixels require,
potentially causing buffer overflows since hardware typically writes in
multiples of bpp_div blocks?
Le lundi 18 mai 2026 à 12:24 +0200, Paul Kocialkowski a écrit : > The NV15_4L4 format is specified as a 4x4 format, not 4x1. > In addition the block size should not take subsampling in account, > so specify it as 4x4 for both luma and chroma. > > Signed-off-by: Paul Kocialkowski <paulk@sys-base.io> > --- > drivers/media/v4l2-core/v4l2-common.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c > index 554c591e1113..77a0daa92c2b 100644 > --- a/drivers/media/v4l2-core/v4l2-common.c > +++ b/drivers/media/v4l2-core/v4l2-common.c > @@ -309,7 +309,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) > /* Tiled YUV formats */ > { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, > { .format = V4L2_PIX_FMT_NV15_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2, > - .block_w = { 4, 2, 0, 0 }, .block_h = { 1, 1, 0, 0 }}, > + .block_w = { 4, 4, 0, 0 }, .block_h = { 4, 4, 0, 0 }}, Only the block_h is broken. The block_w is in "pixels" which for the UV plane is component pairs. So both set of tiles have 5bytes stride. But since the second set, the UV tiles, are interleaved, they only have 2 pairs of UV per row. So to me the correct fix is: + .block_w = { 4, 2, 0, 0 }, .block_h = { 4, 4, 0, 0 }}, If its not the case for the camera pipeline, then a new format is needed, since this format should perfectly match NV15 + VIVANTE_TILED in the DRM world. regards, Nicolas > { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, > > /* YUV planar formats, non contiguous variant */
Hi Nicolas, Thanks for the review! Le Tue 19 May 26, 11:16, Nicolas Dufresne a écrit : > Le lundi 18 mai 2026 à 12:24 +0200, Paul Kocialkowski a écrit : > > The NV15_4L4 format is specified as a 4x4 format, not 4x1. > > In addition the block size should not take subsampling in account, > > so specify it as 4x4 for both luma and chroma. > > > > Signed-off-by: Paul Kocialkowski <paulk@sys-base.io> > > --- > > drivers/media/v4l2-core/v4l2-common.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c > > index 554c591e1113..77a0daa92c2b 100644 > > --- a/drivers/media/v4l2-core/v4l2-common.c > > +++ b/drivers/media/v4l2-core/v4l2-common.c > > @@ -309,7 +309,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) > > /* Tiled YUV formats */ > > { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, > > { .format = V4L2_PIX_FMT_NV15_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2, > > - .block_w = { 4, 2, 0, 0 }, .block_h = { 1, 1, 0, 0 }}, > > + .block_w = { 4, 4, 0, 0 }, .block_h = { 4, 4, 0, 0 }}, > > Only the block_h is broken. The block_w is in "pixels" which for the UV plane is > component pairs. So both set of tiles have 5bytes stride. But since the second > set, the UV tiles, are interleaved, they only have 2 pairs of UV per row. So to > me the correct fix is: > > + .block_w = { 4, 2, 0, 0 }, .block_h = { 4, 4, 0, 0 }}, > > If its not the case for the camera pipeline, then a new format is needed, since > this format should perfectly match NV15 + VIVANTE_TILED in the DRM world. Ah yes I think you're right, I lost sight that these are semi-planar formats with two components per chroma memory plane. Good catch, thanks! All the best, Paul > regards, > Nicolas > > > { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, > > > > /* YUV planar formats, non contiguous variant */
diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c index 554c591e1113..77a0daa92c2b 100644 --- a/drivers/media/v4l2-core/v4l2-common.c +++ b/drivers/media/v4l2-core/v4l2-common.c @@ -309,7 +309,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format) /* Tiled YUV formats */ { .format = V4L2_PIX_FMT_NV12_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, { .format = V4L2_PIX_FMT_NV15_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 5, 10, 0, 0 }, .bpp_div = { 4, 4, 1, 1 }, .hdiv = 2, .vdiv = 2, - .block_w = { 4, 2, 0, 0 }, .block_h = { 1, 1, 0, 0 }}, + .block_w = { 4, 4, 0, 0 }, .block_h = { 4, 4, 0, 0 }}, { .format = V4L2_PIX_FMT_P010_4L4, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 2, 4, 0, 0 }, .bpp_div = { 1, 1, 1, 1 }, .hdiv = 2, .vdiv = 2 }, /* YUV planar formats, non contiguous variant */