On 11/25/26 14:52, Zou Jianqiang wrote:
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. Fixes: b3f1631d3625 ("fbdev: radeonfb: reject a zero pixclock in radeonfb_check_var()") Suggested-by: Geert Uytterhoeven <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/CAMuHMdWyrdpVKvs=8q+b-syo1zdajvfjxfv0qintr9z4vnw...@mail.gmail.com Co-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]> --- 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
