From: Ana Bobillo <anabobillo3@gmail.com>
To: u-boot@lists.u-boot-project.org
Cc: "Tom Rini" <trini@konsulko.com>,
"Anatolij Gustschin" <ag.dev.uboot@gmail.com>,
"Simon Glass" <sjg@chromium.org>,
"Kever Yang" <kever.yang@rock-chips.com>,
"Quentin Schulz" <u-boot@0leil.net>,
"Andre Przywara" <andre.przywara@arm.com>,
"Thierry Reding" <treding@nvidia.com>,
"Svyatoslav Ryhel" <clamor95@gmail.com>,
"Tom Warren" <twarren@nvidia.com>,
"Patrick Delaunay" <patrick.delaunay@foss.st.com>,
"Patrice Chotard" <patrice.chotard@foss.st.com>,
uboot-stm32@st-md-mailman.stormreply.com,
"Neil Armstrong" <neil.armstrong@linaro.org>,
"Jonas Schwöbel" <jonasschwoebel@yahoo.de>
Subject: [PATCH 02/11] video: Check that the mode fits in the reserved frame buffer
Date: Mon, 09 Nov 2026 17:29:04 +0000 [thread overview]
Message-ID: <9f6b44af-cfdc-49ae-8d90-11b7dcdd1a48@gmail.com> (raw)
In-Reply-To: <2399d63c-ddd0-44b0-bb81-d5d9d2a8a8b4@gmail.com>
From: Ana Bobillo <anabobillo3@gmail.com>
The video uclass reserves plat->size bytes for the frame buffer of each
video device when it is bound, but many drivers only learn the mode
when the device is probed, some of them from the display's EDID
(rk_vop, sunxi DE2 and the Tegra drivers). video_post_probe() works out
the frame buffer size from that mode and clears the frame buffer, and
the console then draws on it, without checking it against the
reservation. A display announcing a larger mode than the driver allows
for makes U-Boot write past the reserved memory, into the memory
reserved above it, which on ARM holds the MMU page tables.
Refuse to probe a video device whose frame buffer is larger than the
memory reserved for it. The following patches have the drivers skip
such modes, so that a smaller one is used instead.
Add a test which grows the sandbox display after its frame buffer has
been reserved.
Signed-off-by: Ana Bobillo <anabobillo3@gmail.com>
---
drivers/video/video-uclass.c | 12 ++++++++++++
test/dm/video.c | 29 +++++++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 22183d00d97..68712f6f039 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -640,6 +640,18 @@ static int video_post_probe(struct udevice *dev)
priv->fb_size = priv->line_length * priv->ysize;
+ /*
+ * The mode can come from the display itself (e.g. its EDID), so check
+ * that the frame buffer fits in the memory reserved for it before
+ * anything is drawn
+ */
+ if (plat->size && priv->fb_size > plat->size) {
+ log_err("Video device '%s': %dx%d needs %#x bytes but only %#x are reserved\n",
+ dev->name, priv->xsize, priv->ysize, priv->fb_size,
+ plat->size);
+ return -ENOSPC;
+ }
+
/*
* Set up video handoff fields for passing video blob to next stage
* NOTE:
diff --git a/test/dm/video.c b/test/dm/video.c
index cc854d0e042..8b62ac77657 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -15,6 +15,7 @@
#include <video_console.h>
#include <asm/test.h>
#include <asm/sdl.h>
+#include <dm/device-internal.h>
#include <dm/test.h>
#include <dm/uclass-internal.h>
#include <test/lib.h>
@@ -46,6 +47,34 @@ static int dm_test_video_base(struct unit_test_state *uts)
}
DM_TEST(dm_test_video_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+/* Test that a mode larger than the reserved frame buffer is refused */
+static int dm_test_video_fb_size(struct unit_test_state *uts)
+{
+ struct video_uc_plat *uc_plat;
+ struct sandbox_sdl_plat *plat;
+ struct udevice *dev;
+ int line_length;
+
+ ut_assertok(uclass_find_first_device(UCLASS_VIDEO, &dev));
+ ut_assertnonnull(dev);
+ ut_assert(!device_active(dev));
+ uc_plat = dev_get_uclass_plat(dev);
+
+ /*
+ * Change the mode after the frame buffer has been reserved, as drivers
+ * do with a mode read from the display, so that it needs one line more
+ * than the reserved memory holds
+ */
+ plat = dev_get_plat(dev);
+ line_length = plat->xres * VNBYTES(plat->bpix);
+ plat->yres = uc_plat->size / line_length + 1;
+ ut_asserteq(-ENOSPC, device_probe(dev));
+ ut_assert(!device_active(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_video_fb_size, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
int video_compress_fb(struct unit_test_state *uts, struct udevice *dev,
bool use_copy)
{
next prev parent reply other threads:[~2026-11-09 17:29 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 17:28 [PATCH 00/11] video: Keep EDID modes and DP lane counts within what is reserved Ana Bobillo
2026-11-09 17:28 ` [PATCH 01/11] configs: stm32mp23/stm32mp25: Size the frame buffer for the LVDS panel Ana Bobillo
2026-11-12 8:46 ` Patrice CHOTARD
2026-11-09 17:29 ` Ana Bobillo [this message]
2026-11-09 17:29 ` [PATCH 03/11] edid: Leave the timing alone when no mode is valid Ana Bobillo
2026-11-09 18:16 ` Tom Rini
2026-11-09 19:28 ` Ana Bobillo
2026-11-09 17:29 ` [PATCH 04/11] video: display: Skip modes which do not fit in the source frame buffer Ana Bobillo
2026-11-10 8:41 ` Svyatoslav Ryhel
2026-11-09 17:29 ` [PATCH 05/11] video: rockchip: vop: Tell the display the frame buffer size Ana Bobillo
2026-11-09 18:30 ` Tom Rini
2026-11-09 19:28 ` Ana Bobillo
2026-11-09 17:29 ` [PATCH 06/11] video: sunxi: de2: " Ana Bobillo
2026-11-09 18:21 ` Tom Rini
2026-11-09 19:28 ` Ana Bobillo
2026-11-09 19:44 ` Tom Rini
2026-11-09 17:29 ` [PATCH 07/11] video: tegra124: " Ana Bobillo
2026-11-09 17:29 ` [PATCH 08/11] sunxi: display: Skip EDID modes larger than the frame buffer Ana Bobillo
2026-11-09 17:29 ` [PATCH 09/11] video: tegra: hdmi: Skip modes larger than the DC " Ana Bobillo
2026-11-10 8:46 ` Svyatoslav Ryhel
2026-11-09 17:30 ` [PATCH 10/11] video: rockchip: edp: Limit the lane count to four Ana Bobillo
2026-11-09 17:30 ` [PATCH 11/11] video: tegra124: dp: " Ana Bobillo
2026-11-10 8:51 ` Svyatoslav Ryhel
2026-11-10 18:01 ` [PATCH 00/11] video: Keep EDID modes and DP lane counts within what is reserved Tom Rini
2026-11-10 18:16 ` Ana Bobillo
2026-11-10 18:24 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f6b44af-cfdc-49ae-8d90-11b7dcdd1a48@gmail.com \
--to=anabobillo3@gmail.com \
--cc=ag.dev.uboot@gmail.com \
--cc=andre.przywara@arm.com \
--cc=clamor95@gmail.com \
--cc=jonasschwoebel@yahoo.de \
--cc=kever.yang@rock-chips.com \
--cc=neil.armstrong@linaro.org \
--cc=patrice.chotard@foss.st.com \
--cc=patrick.delaunay@foss.st.com \
--cc=sjg@chromium.org \
--cc=treding@nvidia.com \
--cc=trini@konsulko.com \
--cc=twarren@nvidia.com \
--cc=u-boot@0leil.net \
--cc=u-boot@lists.u-boot-project.org \
--cc=uboot-stm32@st-md-mailman.stormreply.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.