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

drm/fb-helper: Make load_lut and gamma_set/gamma_get hooks optional

Check whether the crtc provides the load_lut callback before calling it.
This allows the driver to provide the hook only for those CRTCs that
actually have the hardware support for it.

Also check whether the driver provided the fb_helper gamma_set/gamma_get
hooks. It's a driver bug if it allows non-truecolor fbdev visuals w/o
these hooks, but auditing all the drivers is too tedious. So just slap
a big WARN_ON() there and bail out before things start to explode.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@gmail.com>

authored by

Ville Syrjälä and committed by
Dave Airlie
04c0c569 8391a3d5

+13 -1
+13 -1
drivers/gpu/drm/drm_fb_helper.c
··· 168 168 uint16_t *r_base, *g_base, *b_base; 169 169 int i; 170 170 171 + if (helper->funcs->gamma_get == NULL) 172 + return; 173 + 171 174 r_base = crtc->gamma_store; 172 175 g_base = r_base + crtc->gamma_size; 173 176 b_base = g_base + crtc->gamma_size; ··· 600 597 return 0; 601 598 } 602 599 600 + /* 601 + * The driver really shouldn't advertise pseudo/directcolor 602 + * visuals if it can't deal with the palette. 603 + */ 604 + if (WARN_ON(!fb_helper->funcs->gamma_set || 605 + !fb_helper->funcs->gamma_get)) 606 + return -EINVAL; 607 + 603 608 pindex = regno; 604 609 605 610 if (fb->bits_per_pixel == 16) { ··· 688 677 if (rc) 689 678 goto out; 690 679 } 691 - crtc_funcs->load_lut(crtc); 680 + if (crtc_funcs->load_lut) 681 + crtc_funcs->load_lut(crtc); 692 682 } 693 683 out: 694 684 drm_modeset_unlock_all(dev);