Skip to contentSkip to conversation

video: A couple of fixes for the vga16fb driver

PATCH Superseded Javier Martinez Canillas 3 participants 7 messages Jan 7, 2022 – Jan 10, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover video: A couple of fixes for the vga16fb driver

This patch series contains two fixes for the vga16fb driver. I looked at the driver due a regression reported [0], caused by commit d391c5827107 ("drivers/firmware: move x86 Generic System Framebuffers support").

The mentioned commit didn't change any logic but just moved the platform device registration that matches the vesafb and efifb drivers to happen later. And this caused the vga16fb driver to be probed even in machines that don't have an EGA or VGA video adapter.

Patch #1 is fixing the wrong check to determine if either EGA or VGA is used and patch #2 adds a check to the driver to only be loaded for EGA and VGA 16 color graphic cards.

[0]: https://bugzilla.kernel.org/show_bug.cgi?id=215001

Best regards,
Javier

Javier Martinez Canillas (2):
video: vga16fb: Fix logic that checks for the display standard
video: vga16fb: Only probe for EGA and VGA 16 color graphic cards

 drivers/video/fbdev/vga16fb.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/2 video: vga16fb: Fix logic that checks for the display standard

The vga16fb framebuffer driver supports both Enhanced Graphics Adapter (EGA) and Video Graphics Array (VGA) 16 color graphic cards.

But the logic to check whether the EGA or VGA standard are used is not correct. It just checks if screen_info.orig_video_isVGA is set, but it should check if is set to VIDEO_TYPE_VGAC instead.

This means that it assumes to be VGA even if is set to VIDEO_TYPE_EGAC.

---

 drivers/video/fbdev/vga16fb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/vga16fb.c +1 -1
index e2757ff1c23d..3347c9b6a332 100644
@@ -1332,7 +1332,7 @@ static int vga16fb_probe(struct platform_device *dev)
 	printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base);
 	par = info->par;
 
-	par->isVGA = screen_info.orig_video_isVGA;
+	par->isVGA = screen_info.orig_video_isVGA == VIDEO_TYPE_VGAC;
 	par->palette_blanked = 0;
 	par->vesa_blanked = 0;
 
Signature · 1 line
2.33.1
#5 lore raw

PATCH 2/2 video: vga16fb: Only probe for EGA and VGA 16 color graphic cards

In reply to Javier Martinez Canillas

The vga16fb framebuffer driver only supports Enhanced Graphics Adapter (EGA) and Video Graphics Array (VGA) 16 color graphic cards.

But it doesn't check if the adapter is one of those or if a VGA16 mode is used. This means that the driver will be probed even if a VESA BIOS Extensions (VBE) or Graphics Output Protocol (GOP) interface is used.

This issue has been present for a long time but it was only exposed by commit d391c5827107 ("drivers/firmware: move x86 Generic System Framebuffers support") since the platform device registration to match the {vesa,efi}fb drivers is done later as a consequence of that change.

Fixes d391c5827107 ("drivers/firmware: move x86 Generic System Framebuffers support")
Cc <[email protected]> # 5.15.x

---

 drivers/video/fbdev/vga16fb.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/video/fbdev/vga16fb.c +12 -0
index 3347c9b6a332..72b6aeceeff8 100644
@@ -1422,6 +1422,18 @@ static int __init vga16fb_init(void)
 
 	vga16fb_setup(option);
 #endif
+
+	/* only EGA and VGA in 16 color graphic mode are supported */
+	if (screen_info.orig_video_isVGA != VIDEO_TYPE_EGAC &&
+	    screen_info.orig_video_isVGA != VIDEO_TYPE_VGAC)
+		return -ENODEV;
+
+	if (screen_info.orig_video_mode != 0x0D &&	/* 320x200/4 (EGA) */
+	    screen_info.orig_video_mode != 0x0E &&	/* 640x200/4 (EGA) */
+	    screen_info.orig_video_mode != 0x10 &&	/* 640x350/4 (EGA) */
+	    screen_info.orig_video_mode != 0x12)	/* 640x480/4 (VGA) */
+		return -ENODEV;
+
 	ret = platform_driver_register(&vga16fb_driver);
 
 	if (!ret) {
Signature · 1 line
2.33.1
#6 lore raw

Re: [PATCH 2/2] video: vga16fb: Only probe for EGA and VGA 16 color graphic cards

Hi Javier,

Quoted 12 lines · Javier Martinez Canillas

The vga16fb framebuffer driver only supports Enhanced Graphics Adapter (EGA) and Video Graphics Array (VGA) 16 color graphic cards.

But it doesn't check if the adapter is one of those or if a VGA16 mode is used. This means that the driver will be probed even if a VESA BIOS Extensions (VBE) or Graphics Output Protocol (GOP) interface is used.

This issue has been present for a long time but it was only exposed by commit d391c5827107 ("drivers/firmware: move x86 Generic System Framebuffers support") since the platform device registration to match the {vesa,efi}fb drivers is done later as a consequence of that change.

Quoted 6 lines
Fixes d391c5827107 ("drivers/firmware: move x86 Generic System Framebuffers support")
Cc <[email protected]> # 5.15.x

Thanks for your patch!

drivers/video/fbdev/vga16fb.c static int __init vga16fb_init(void) · line 1429

Quoted 11 lines
drivers/video/fbdev/vga16fb.c +5 -0
@@ -1422,6 +1422,18 @@ static int __init vga16fb_init(void)
 
        vga16fb_setup(option);
 #endif
+
+       /* only EGA and VGA in 16 color graphic mode are supported */
+       if (screen_info.orig_video_isVGA != VIDEO_TYPE_EGAC &&
+           screen_info.orig_video_isVGA != VIDEO_TYPE_VGAC)
+               return -ENODEV;

Probably these checks should be wrapped inside a check for CONFIG_X86?

All non-x86 architectures (except for 2 MIPS platforms) treat orig_video_isVGA as a boolean flag, and just assign 1 to it.

drivers/video/fbdev/vga16fb.c static int __init vga16fb_init(void) · line 1436

Quoted 7 lines
drivers/video/fbdev/vga16fb.c +7 -0
+
+       if (screen_info.orig_video_mode != 0x0D &&      /* 320x200/4 (EGA) */
+           screen_info.orig_video_mode != 0x0E &&      /* 640x200/4 (EGA) */
+           screen_info.orig_video_mode != 0x10 &&      /* 640x350/4 (EGA) */
+           screen_info.orig_video_mode != 0x12)        /* 640x480/4 (VGA) */
+               return -ENODEV;
+

Likewise.

A long time ago, I used vga16fb on a PPC box to use a standard PC graphics card (initialized using an emulator for the card's BIOS ROM), as a second display. The above changes would break such a use case.

drivers/video/fbdev/vga16fb.c static int __init vga16fb_init(void) · line 1439

Quoted 3 lines
drivers/video/fbdev/vga16fb.c +0 -0
        ret = platform_driver_register(&vga16fb_driver);
 
        if (!ret) {

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#2 lore raw

Re: [PATCH 1/2] video: vga16fb: Fix logic that checks for the display standard

In reply to Javier Martinez Canillas

Hi Javier,

Quoted 10 lines · Javier Martinez Canillas

The vga16fb framebuffer driver supports both Enhanced Graphics Adapter (EGA) and Video Graphics Array (VGA) 16 color graphic cards.

But the logic to check whether the EGA or VGA standard are used is not correct. It just checks if screen_info.orig_video_isVGA is set, but it should check if is set to VIDEO_TYPE_VGAC instead.

This means that it assumes to be VGA even if is set to VIDEO_TYPE_EGAC.

Thanks for your patch!

drivers/video/fbdev/vga16fb.c static int vga16fb_probe(struct platform_device *dev) · line 1335

Quoted 8 lines
drivers/video/fbdev/vga16fb.c +1 -1
@@ -1332,7 +1332,7 @@ static int vga16fb_probe(struct platform_device *dev)
        printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base);
        par = info->par;
 
-       par->isVGA = screen_info.orig_video_isVGA;
+       par->isVGA = screen_info.orig_video_isVGA == VIDEO_TYPE_VGAC;

All non-x86 architectures (except for 2 MIPS platforms) treat orig_video_isVGA as a boolean flag, and just assign 1 to it. Hence this change would break them.

drivers/video/fbdev/vga16fb.c static int vga16fb_probe(struct platform_device *dev) · line 1338

Quoted 3 lines
drivers/video/fbdev/vga16fb.c +0 -0
        par->palette_blanked = 0;
        par->vesa_blanked = 0;
 

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw

Re: [PATCH 1/2] video: vga16fb: Fix logic that checks for the display standard

Groetje, Geert,

Quoted 6 lines · Geert Uytterhoeven

drivers/video/fbdev/vga16fb.c static int vga16fb_probe(struct platform_device *dev) · line 1335

Quoted 3 lines
drivers/video/fbdev/vga16fb.c +1 -1
-       par->isVGA = screen_info.orig_video_isVGA;
+       par->isVGA = screen_info.orig_video_isVGA == VIDEO_TYPE_VGAC;

All non-x86 architectures (except for 2 MIPS platforms) treat orig_video_isVGA as a boolean flag, and just assign 1 to it. Hence this change would break them.

I see a bit of a conflict with using orig_video_isVGA as a boolean. All the modern architecture-agnostic driver code, such as sysfb, sysfb_simplefb, and efifb, all use and expect orig_video_isVGA to be an integer.  On the other hand, the VGA driver for XEN first sets orig_video_isVGA  = 1 (boolean), and then VIDEO_TYPE_VLFB or VIDEO_TYPE_EFI (integer).  Overloading the definition for orig_video_isVGA to be both boolean and integer - within the same file - seems like a recipe for bugs to me.

That said, I think that wrapping the par->isVGA code, above, within a check for CONFIG_X86 seems safe and expedient.  But I would be much happier if the non-x86 architectures would set it to a proper integer value (even if fake) that coincidentally satisfies boolean "true", say VIDEO_TYPE_VGAC; that way, there would be no confusion as to data type in all the more recent architecture-agnostic framebuffer code.

Kris

#4 lore raw

Re: [PATCH 1/2] video: vga16fb: Fix logic that checks for the display standard

Hello Geert and Kara,

Quoted 10 lines · Kris Karas (Bug reporting)

Groetje, Geert,

Quoted 6 lines · Geert Uytterhoeven

drivers/video/fbdev/vga16fb.c static int vga16fb_probe(struct platform_device *dev) · line 1335

Quoted 3 lines
drivers/video/fbdev/vga16fb.c +1 -1
-       par->isVGA = screen_info.orig_video_isVGA;
+       par->isVGA = screen_info.orig_video_isVGA == VIDEO_TYPE_VGAC;

All non-x86 architectures (except for 2 MIPS platforms) treat orig_video_isVGA as a boolean flag, and just assign 1 to it. Hence this change would break them.

Quoted 9 lines

I see a bit of a conflict with using orig_video_isVGA as a boolean. All the modern architecture-agnostic driver code, such as sysfb, sysfb_simplefb, and efifb, all use and expect orig_video_isVGA to be an integer.  On the other hand, the VGA driver for XEN first sets orig_video_isVGA  = 1 (boolean), and then VIDEO_TYPE_VLFB or VIDEO_TYPE_EFI (integer).  Overloading the definition for orig_video_isVGA to be both boolean and integer - within the same file - seems like a recipe for bugs to me.

Agreed with Kara on this. I believe the non-x86 arches should be fixed to set it to the correct value.

Quoted 7 lines

That said, I think that wrapping the par->isVGA code, above, within a check for CONFIG_X86 seems safe and expedient.  But I would be much happier if the non-x86 architectures would set it to a proper integer value (even if fake) that coincidentally satisfies boolean "true", say VIDEO_TYPE_VGAC; that way, there would be no confusion as to data type in all the more recent architecture-agnostic framebuffer code.

Yes, I'll post a v2 to do that but hopefully the CONFIG_X86 guard could be dropped in the future once all the architectures are fixed.

Quoted 2 lines

Kris

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat