Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/sysfb: Find screen_info format with helpers

Convert drm_sysfb_get_format_si() to lookup the screen_info color
format as struct pixel_format with screen_info_pixel_format(). Then
search the list of given formats for the screen_info format with
pixel_format_equal().

Replaces custom code with helpers. The pixel-compare helper
pixel_format_equal() also handles indexed color formats. Prepares
for sysfb drivers to support color palettes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20250714151513.309475-4-tzimmermann@suse.de

+8 -11
+8 -11
drivers/gpu/drm/sysfb/drm_sysfb_screen_info.c
··· 79 79 const struct screen_info *si) 80 80 { 81 81 const struct drm_format_info *format = NULL; 82 - u32 bits_per_pixel; 82 + struct pixel_format pixel; 83 83 size_t i; 84 + int ret; 84 85 85 - bits_per_pixel = __screen_info_lfb_bits_per_pixel(si); 86 + ret = screen_info_pixel_format(si, &pixel); 87 + if (ret) 88 + return NULL; 86 89 87 90 for (i = 0; i < nformats; ++i) { 88 - const struct pixel_format *f = &formats[i].pixel; 91 + const struct drm_sysfb_format *f = &formats[i]; 89 92 90 - if (bits_per_pixel == f->bits_per_pixel && 91 - si->red_size == f->red.length && 92 - si->red_pos == f->red.offset && 93 - si->green_size == f->green.length && 94 - si->green_pos == f->green.offset && 95 - si->blue_size == f->blue.length && 96 - si->blue_pos == f->blue.offset) { 97 - format = drm_format_info(formats[i].fourcc); 93 + if (pixel_format_equal(&pixel, &f->pixel)) { 94 + format = drm_format_info(f->fourcc); 98 95 break; 99 96 } 100 97 }