Skip to content

Commit 615cc42

Browse files
author
Thomas Zimmermann
committed
drm/vesadrm: Avoid NULL-ptr deref in vesadrm_pmi_cmap_write()
Only set PMI fields if the screen_info's Vesa PM segment has been set. Vesa PMI is the power-management interface. It also provides means to set the color palette. The interface is optional, so not all VESA graphics cards support it. Print vesafb's warning [1] if the hardware palette cannot be set at all. If unsupported the field PrimaryPalette in struct vesadrm.pmi is NULL, which results in a segmentation fault. Happens with qemu's Cirrus emulation. Signed-off-by: Thomas Zimmermann <[email protected]> Fixes: 814d270 ("drm/sysfb: vesadrm: Add gamma correction") Link: https://elixir.bootlin.com/linux/v6.15/source/drivers/video/fbdev/vesafb.c#L375 # 1 Cc: Thomas Zimmermann <[email protected]> Cc: Javier Martinez Canillas <[email protected]> Cc: [email protected] Acked-by: Javier Martinez Canillas <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f6faebc commit 615cc42

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/gpu/drm/sysfb/vesadrm.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,19 @@ static struct vesadrm_device *vesadrm_device_create(struct drm_driver *drv,
362362

363363
if (!__screen_info_vbe_mode_nonvga(si)) {
364364
vesa->cmap_write = vesadrm_vga_cmap_write;
365-
#if defined(CONFIG_X86_32)
366365
} else {
366+
#if defined(CONFIG_X86_32)
367367
phys_addr_t pmi_base = __screen_info_vesapm_info_base(si);
368-
const u16 *pmi_addr = phys_to_virt(pmi_base);
369368

370-
vesa->pmi.PrimaryPalette = (u8 *)pmi_addr + pmi_addr[2];
371-
vesa->cmap_write = vesadrm_pmi_cmap_write;
369+
if (pmi_base) {
370+
const u16 *pmi_addr = phys_to_virt(pmi_base);
371+
372+
vesa->pmi.PrimaryPalette = (u8 *)pmi_addr + pmi_addr[2];
373+
vesa->cmap_write = vesadrm_pmi_cmap_write;
374+
} else
372375
#endif
376+
if (format->is_color_indexed)
377+
drm_warn(dev, "hardware palette is unchangeable, colors may be incorrect\n");
373378
}
374379

375380
#ifdef CONFIG_X86

0 commit comments

Comments
 (0)