Skip to contentSkip to conversation

fbdev: hyperv_fb: fix uninitialized local variable use

PATCH Applied Arnd Bergmann 2 participants 2 messages Nov 8, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fbdev: hyperv_fb: fix uninitialized local variable use

From: Arnd Bergmann <[email protected]>

When CONFIG_SYSFB is disabled, the hyperv_fb driver can now run into undefined behavior on a gen2 VM, as indicated by this smatch warning:

drivers/video/fbdev/hyperv_fb.c:1077 hvfb_getmem() error: uninitialized symbol 'base'. drivers/video/fbdev/hyperv_fb.c:1077 hvfb_getmem() error: uninitialized symbol 'size'.

Since there is no way to know the actual framebuffer in this configuration, just return an allocation failure here, which should avoid the build warning and the undefined behavior.

Fixes a07b50d80ab6 ("hyperv: avoid dependency on screen_info")
---
 drivers/video/fbdev/hyperv_fb.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/video/fbdev/hyperv_fb.c +2 -0
index bf59daf862fc..a80939fe2ee6 100644
@@ -1013,6 +1013,8 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
 	} else if (IS_ENABLED(CONFIG_SYSFB)) {
 		base = screen_info.lfb_base;
 		size = screen_info.lfb_size;
+	} else {
+		goto err1;
 	}
 
 	/*
Signature · 1 line
2.39.2
maintainer Applied
#1 lore raw
Quoted 12 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

When CONFIG_SYSFB is disabled, the hyperv_fb driver can now run into undefined behavior on a gen2 VM, as indicated by this smatch warning:

drivers/video/fbdev/hyperv_fb.c:1077 hvfb_getmem() error: uninitialized symbol 'base'. drivers/video/fbdev/hyperv_fb.c:1077 hvfb_getmem() error: uninitialized symbol 'size'.

Since there is no way to know the actual framebuffer in this configuration, just return an allocation failure here, which should avoid the build warning and the undefined behavior.

Quoted 5 lines
Fixes a07b50d80ab6 ("hyperv: avoid dependency on screen_info")

applied.

Thanks!
Helge

Quoted 17 lines
---
  drivers/video/fbdev/hyperv_fb.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/video/fbdev/hyperv_fb.c +2 -0
index bf59daf862fc..a80939fe2ee6 100644
@@ -1013,6 +1013,8 @@ static int hvfb_getmem(struct hv_device *hdev, struct fb_info *info)
  	} else if (IS_ENABLED(CONFIG_SYSFB)) {
  		base = screen_info.lfb_base;
  		size = screen_info.lfb_size;
+	} else {
+		goto err1;
  	}
 
  	/*