[PATCH] drm/fb-helper: Fix drm_fb_helper_hotplug_event() NULL ptr argument

Daniel Vetter daniel at ffwll.ch
Wed May 15 13:40:14 UTC 2019


On Wed, May 15, 2019 at 03:29:25PM +0200, Noralf Trønnes wrote:
> drm_fb_helper_hotplug_event() should tolerate the fb_helper argument being
> NULL. Commit 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace")
> introduced a fb_helper dereference before the NULL check.
> Fixup by moving the dereference after the NULL check.
> 
> Fixes: 03a9606e7fee ("drm/fb-helper: Avoid race with DRM userspace")
> Reported-by: kbuild test robot <lkp at intel.com>
> Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
> Signed-off-by: Noralf Trønnes <noralf at tronnes.org>

Ah the classic "I spotted a deref before your NULL check, I'm going to
optimize this all away because you got it wrong" nonsense from gcc. I
thought the kernel uses a special compile flag to avoid this optimization
...

Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>

> ---
>  drivers/gpu/drm/drm_fb_helper.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index c259a28522f8..a52b48fafbd7 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -3031,7 +3031,6 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
>   */
>  int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
>  {
> -	struct drm_device *dev = fb_helper->dev;
>  	int err = 0;
>  
>  	if (!drm_fbdev_emulation || !fb_helper)
> @@ -3044,13 +3043,13 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
>  		return err;
>  	}
>  
> -	if (!fb_helper->fb || !drm_master_internal_acquire(dev)) {
> +	if (!fb_helper->fb || !drm_master_internal_acquire(fb_helper->dev)) {
>  		fb_helper->delayed_hotplug = true;
>  		mutex_unlock(&fb_helper->lock);
>  		return err;
>  	}
>  
> -	drm_master_internal_release(dev);
> +	drm_master_internal_release(fb_helper->dev);
>  
>  	DRM_DEBUG_KMS("\n");
>  
> -- 
> 2.20.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list