From nobody Mon Dec 1 22:35:46 2025 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (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 B2A4D30B525 for ; Mon, 1 Dec 2025 12:19:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591568; cv=none; b=dvcGVnS8W3HV604gls0+HJm01B5pe2eF4PYrmlAd+q5UGsgKbfoKr3md7TVAqLr8X0kmaVT6crl1NoViQzh6gG+UD77Nog+evfSGpL3HCFIK5dc+Hk2aZlMDa4px5VMKwblaavtmfnUt1ORS7DUPbEMwnNYfwA0ahDmgVanrSfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764591568; c=relaxed/simple; bh=0+4PliZFZn2ZEL7NwkuBYPphIbKpznlW8ky3nnE+a14=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N9eIvfsFihCnSFwSVN2l1mq3vH06Sgjiw+WFJ6A7aQjk3BjPdMtVimWdTSLIv2Wu2zCq++1VKARUNw5vqOmzM0GIxSgN3e/TEZyRd/Pqb2w3WthlHFQlSO+kdFUNMVQgz3hh8jcfa6/AeG7J3bCfF/gAYv9ip+7S6lyRakB3hus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=o/Nq1J2D; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="o/Nq1J2D" Received: from [127.0.1.1] (91-158-153-178.elisa-laajakaista.fi [91.158.153.178]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B553C176E; Mon, 1 Dec 2025 13:17:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764591427; bh=0+4PliZFZn2ZEL7NwkuBYPphIbKpznlW8ky3nnE+a14=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=o/Nq1J2DeNIItyGvxpknG+Es2gMm4K5JMfFrN4r/rcr/j+F+VmIbEPNrRuFMUVR4A fTtzv1SAh2Vc+KTsYTNl21x9OvQiAIghxpa8zFkWmuKMLPWMrQkBuoj3YPPjBCv4dE mUC0OffqRe9UUfoFBE2DKbc8+4y3iRJm2i/dwqJM= From: Tomi Valkeinen Date: Mon, 01 Dec 2025 14:18:43 +0200 Subject: [PATCH v7 01/11] drm/fourcc: Add warning for bad bpp Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251201-xilinx-formats-v7-1-1e1558adfefc@ideasonboard.com> References: <20251201-xilinx-formats-v7-0-1e1558adfefc@ideasonboard.com> In-Reply-To: <20251201-xilinx-formats-v7-0-1e1558adfefc@ideasonboard.com> To: Vishal Sagar , Anatoliy Klymenko , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Laurent Pinchart , Michal Simek Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Geert Uytterhoeven , Dmitry Baryshkov , Pekka Paalanen , Tomi Valkeinen X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1814; i=tomi.valkeinen@ideasonboard.com; h=from:subject:message-id; bh=0+4PliZFZn2ZEL7NwkuBYPphIbKpznlW8ky3nnE+a14=; b=owEBbQKS/ZANAwAIAfo9qoy8lh71AcsmYgBpLYfCrz0osWNnioWxJ+pRazxkcDm1Y6wFOSqoG VxQ+vrQCVWJAjMEAAEIAB0WIQTEOAw+ll79gQef86f6PaqMvJYe9QUCaS2HwgAKCRD6PaqMvJYe 9XxGD/9CK7bNaaDU9xQvVBPvD9PhicflAfu2lrfT2pb0kbeKPAGTHNyuGCyqyT7tBGKk1aAk/+a /erKLy/3MiMyid4xBUuKnwXICHkzCwFragfhL/3TCmUQ1MMH9WYOp6gmtPUrkMEcmPuBqtfLFHA 7jBp53da1pm1x2jaRmD7scAnlkdIwgfFZy1Tq7v8nixz/eDXHyAwnAPuFUovmo0Xr0dnE67e60I atWpXj+BRuOXmg/EmVfOyajuxb2kuiFlmTcqOog8CGfYPcBv9PiOMiWjfeUS6TfrMuR9JctivHs SNTsiVzcBD3wg4oCpH0IL0KIWI3V/AQvNYCF+DijSHe9PhH3pTbQ2WcboI0xV6jh6JibKIppMTb +6MBB+gdhNTbRQsug1Jkb/rvbC2NoYpgLWoS3qMZK1tm/es8iuHflIfp7eyTqPP3Pc7gWJ7rGA4 3ij4wl/6BK4V7KtIg+OLm6NrA6/8dKkQ23adxfUXz6eSOfpQ8vYHBCU1WWVk+ft83B3Ovo8G5nE iDoQnvzRKZYMR9GwDZTGATxWe36NWQiucPQOGKnu/F9P6LskikMa4dyQf0nuJEgBW+LAs+4WimO cC0mcyzk749W/7M4f46SpvU8bcazBoSb+uvodXK701S/LfGXCEIgxwToSfd9ueBsb02AcsobBlH UhsURqHox0d9rnQ== X-Developer-Key: i=tomi.valkeinen@ideasonboard.com; a=openpgp; fpr=C4380C3E965EFD81079FF3A7FA3DAA8CBC961EF5 drm_format_info_bpp() cannot be used for formats which do not have an integer bits-per-pixel in a pixel block. E.g. DRM_FORMAT_XV15's (not yet in upstream) plane 0 has three 10-bit pixels (Y components), and two padding bits, in a 4 byte block. That is 10.666... bits per pixel when considering the whole 4 byte block, which is what drm_format_info_bpp() does. Thus a driver that supports such formats cannot use drm_format_info_bpp(), It is a driver bug if this happens, but so handle wrong calls by printing a warning and returning 0. Reviewed-by: Laurent Pinchart Reviewed-by: Dmitry Baryshkov Signed-off-by: Tomi Valkeinen --- drivers/gpu/drm/drm_fourcc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index e0d533611040..e662aea9d105 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -491,12 +491,20 @@ EXPORT_SYMBOL(drm_format_info_block_height); */ unsigned int drm_format_info_bpp(const struct drm_format_info *info, int p= lane) { + unsigned int block_size; + if (!info || plane < 0 || plane >=3D info->num_planes) return 0; =20 - return info->char_per_block[plane] * 8 / - (drm_format_info_block_width(info, plane) * - drm_format_info_block_height(info, plane)); + block_size =3D drm_format_info_block_width(info, plane) * + drm_format_info_block_height(info, plane); + + if (info->char_per_block[plane] * 8 % block_size) { + pr_warn("unable to return an integer bpp\n"); + return 0; + } + + return info->char_per_block[plane] * 8 / block_size; } EXPORT_SYMBOL(drm_format_info_bpp); =20 --=20 2.43.0