fbdev: radeonfb: match a display mode for a zero pixel period
Subsystems (2)
PATCH 1/1 fbdev: radeonfb: match a display mode for a zero pixel period
From: Jianqiang Zou <[email protected]>
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.
--- drivers/video/fbdev/aty/radeon_base.c | 3 --- drivers/video/fbdev/aty/radeon_monitor.c | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-)
drivers/video/fbdev/aty/radeon_base.c +0 -3
@@ -836,9 +836,6 @@ static int radeonfb_check_var (struct fb_var_screeninfo *var, struct fb_info *inint nom, den;unsigned int pitch; -if (!var->pixclock) -return -EINVAL ; -if (radeon_match_mode (rinfo, &v, var))return -EINVAL ;
drivers/video/fbdev/aty/radeon_monitor.c +14 -7
@@ -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 ;
Signature · 1 line
2.43.0
Quoted 68 lines · Zou Jianqiang
From: Jianqiang Zou <[email protected]>
A zero pixclock was rejected in
radeonfb_check_var()by commitb3f1631d3625("fbdev: radeonfb: reject a zero pixclock inradeonfb_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-EINVALis 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. WithFB_ACTIVATE_NOWorFB_ACTIVATE_TESTit 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 tofb_set_var(), so what reachesradeonfb_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_SIZEfor 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 andFB_ACTIVATE_NOWorFB_ACTIVATE_TESTstill 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_modedbis NULL andhas_rmxis 0, which is the configuration that reaches the division.FBIOPUT_VSCREENINFOwith 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, beforeb3f1631d3625, still triggers "divide error" inradeonfb_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 <[email protected]>Link https://lore.kernel.org/r/CAMuHMdWyrdpVKvs=8Q+B-Syo1ZdAJvfJXFv0qiNtR9z4VnwnBQ@mail.gmail.com open hereCo-developed-by Bin Yu <[email protected]>Signed-off-by Bin Yu <[email protected]>Co-developed-by Mingyu Wang <[email protected]>Signed-off-by Mingyu Wang <[email protected]>Signed-off-by Jianqiang Zou <[email protected]>
Quoted 4 lines
--- drivers/video/fbdev/aty/radeon_base.c | 3 --- drivers/video/fbdev/aty/radeon_monitor.c | 21 ++++++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-)
applied.
Thanks!
Helge