From: Zou Jianqiang <jq.zou@outlook.com>
To: Helge Deller <deller@gmx.de>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>,
"linux-fbdev@vger.kernel.org" <linux-fbdev@vger.kernel.org>,
"dri-devel@lists.freedesktop.org"
<dri-devel@lists.freedesktop.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"byu@xidian.edu.cn" <byu@xidian.edu.cn>,
"25181214217@stu.xidian.edu.cn" <25181214217@stu.xidian.edu.cn>
Subject: [PATCH] fbdev: radeonfb: match a display mode for a zero pixel period
Date: Wed, 25 Nov 2026 13:52:39 +0000 [thread overview]
Message-ID: <20261125135233.26656-1-jq.zou@outlook.com> (raw)
From: Jianqiang Zou <jq.zou@outlook.com>
A zero pixclock was rejected in radeonfb_check_var() by commit
b3f1631d3625 ("fbdev: radeonfb: reject a zero pixclock in
radeonfb_check_var()"). That works around a division by zero, but it
violates the fbdev API: a value that does not fit has to be rounded up
by the driver, and -EINVAL is only for values that are too large. A
zero pixel period does not fit, so it has to be rounded up as well.
The check was added because a zero pixel period reaches
radeonfb_set_par() and makes it divide by zero:
dotClock = 1000000000 / pixClock;
radeon_match_mode() already has the timings that can replace the
unusable value, but it never gets that far. With FB_ACTIVATE_NOW or
FB_ACTIVATE_TEST it copies the request unchanged and only validates it
against an EDID-derived mode database, and that database does not exist
when no EDID was read - which is exactly the case that divides by zero.
Drop that check and let radeon_match_mode() round the request up
instead. A zero pixel period no longer takes the short path, so it is
matched against the mode database and a complete set of timings is
returned to the caller. radeonfb_check_var() then hands a nonzero
pixel period back to fb_set_var(), so what reaches radeonfb_set_par()
is usable; how the mode is programmed still depends on the output.
The lookup needed a fix of its own to produce a usable mode. Both VESA
searches stopped after the first 34 entries, a limit that predates the
widescreen modes at the end of vesa_modes[]; the other fbdev drivers
already use VESA_MODEDB_SIZE for the same loop. Use it here as well,
as 1920x1200 is otherwise rounded up to 1920x1440 and 2560x1600 is
rejected although the table has an entry for it. Entries
without a pixel period are skipped, so an unusable timing is never
handed back. Requests with a pixel period and FB_ACTIVATE_NOW or
FB_ACTIVATE_TEST still return from the short path above; the ones that
reach the lookup see the added widescreen entries as well.
When the request had no pixel period, the requested virtual dimensions
are kept, so rounding up does not shrink the panning area; a request
that does specify a period keeps the previous behaviour. The panning
offsets come from the selected mode, so a stale offset is not returned
either. The first equally close mode in database order wins, so a
request without a pixel period does not end up at the highest refresh
rate.
A request that matches no mode is rejected with -EINVAL. For a
zero-period request this now includes outputs with a scaler, because a
scaler cannot invent a pixel period. An output with a scaler still
accepts a request that carries a period and uses those timings.
Tested on 7.3.0 with a QEMU stub device for 1002:5955. It has no EDID,
so mon1_modedb is NULL and has_rmx is 0, which is the configuration
that reaches the division. FBIOPUT_VSCREENINFO with pixclock = 0 for
640x480 now returns 0 and reports a rounded up period of 39682 ps,
while the same request on the stock Linux 7.3 driver, before
b3f1631d3625, still triggers "divide error" in radeonfb_set_par(). A
request larger than any table entry, e.g. 4096x3072, returns -EINVAL.
Fixes: b3f1631d3625 ("fbdev: radeonfb: reject a zero pixclock in radeonfb_check_var()")
Suggested-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/r/20261101104107.33909-1-jq.zou@outlook.com
Link: https://lore.kernel.org/r/CAMuHMdWyrdpVKvs=8Q+B-Syo1ZdAJvfJXFv0qiNtR9z4VnwnBQ@mail.gmail.com
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
Signed-off-by: Mingyu Wang <25181214217@stu.xidian.edu.cn>
Signed-off-by: Jianqiang Zou <jq.zou@outlook.com>
---
drivers/video/fbdev/aty/radeon_base.c | 3 ---
drivers/video/fbdev/aty/radeon_monitor.c | 21 ++++++++++++++-------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index a69e58914..b6b058cee 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -836,9 +836,6 @@ static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *in
int nom, den;
unsigned int pitch;
- if (!var->pixclock)
- return -EINVAL;
-
if (radeon_match_mode(rinfo, &v, var))
return -EINVAL;
diff --git a/drivers/video/fbdev/aty/radeon_monitor.c b/drivers/video/fbdev/aty/radeon_monitor.c
index 621d13a1a..c929476d9 100644
--- a/drivers/video/fbdev/aty/radeon_monitor.c
+++ b/drivers/video/fbdev/aty/radeon_monitor.c
@@ -975,7 +975,7 @@ int radeon_match_mode(struct radeonfb_info *rinfo,
const struct fb_var_screeninfo *src)
{
const struct fb_videomode *db = vesa_modes;
- int i, dbsize = 34;
+ int i, dbsize = VESA_MODEDB_SIZE;
int has_rmx, native_db = 0;
int distance = INT_MAX;
const struct fb_videomode *candidate = NULL;
@@ -997,8 +997,9 @@ int radeon_match_mode(struct radeonfb_info *rinfo,
* FB_ACTIVATE_NOW, just do basic checking and return if the
* mode match
*/
- if ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST ||
- (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
+ if (src->pixclock &&
+ ((src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST ||
+ (src->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW)) {
/* We don't have an RMX, validate timings. If we don't have
* monspecs, we should be paranoid and not let use go above
* 640x480-60, but I assume userland knows what it's doing here
@@ -1010,11 +1011,13 @@ int radeon_match_mode(struct radeonfb_info *rinfo,
return 0;
}
- /* Now look for a mode in the database */
+ /* Look up complete timings when the requested pixel period is zero. */
while (db) {
for (i = 0; i < dbsize; i++) {
int d;
+ if (!db[i].pixclock)
+ continue;
if (db[i].yres < src->yres)
continue;
if (db[i].xres < src->xres)
@@ -1032,7 +1035,7 @@ int radeon_match_mode(struct radeonfb_info *rinfo,
/* If we have a scaler, we allow any mode from the database */
if (native_db && has_rmx) {
db = vesa_modes;
- dbsize = 34;
+ dbsize = VESA_MODEDB_SIZE;
native_db = 0;
}
}
@@ -1040,11 +1043,15 @@ int radeon_match_mode(struct radeonfb_info *rinfo,
/* If we have found a match, return it */
if (candidate != NULL) {
radeon_videomode_to_var(dest, candidate);
+ if (!src->pixclock) {
+ dest->xres_virtual = max(dest->xres, src->xres_virtual);
+ dest->yres_virtual = max(dest->yres, src->yres_virtual);
+ }
return 0;
}
- /* If we haven't and don't have a scaler, fail */
- if (!has_rmx)
+ /* A scaler can use the requested timings if they include a clock. */
+ if (!has_rmx || !src->pixclock)
return -EINVAL;
return 0;
--
2.43.0
reply other threads:[~2026-11-25 13:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261125135233.26656-1-jq.zou@outlook.com \
--to=jq.zou@outlook.com \
--cc=25181214217@stu.xidian.edu.cn \
--cc=benh@kernel.crashing.org \
--cc=byu@xidian.edu.cn \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=geert@linux-m68k.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®