[PATCH v2 1/8] drm/fb-helper: Handle function NULL argument

Daniel Vetter daniel at ffwll.ch
Tue Oct 17 12:38:55 UTC 2017


On Sun, Oct 15, 2017 at 06:30:35PM +0200, Noralf Trønnes wrote:
> Make functions tolerate that the drm_fb_helper argument is NULL.
> This is useful for drivers that continue probing when fbdev emulation
> fails and not having to do this check themselves.
> Update docs for functions that already handles this.
> 
> Signed-off-by: Noralf Trønnes <noralf at tronnes.org>

Is there callsites that we can now simplify? Should we add a todo.rst
entry if there's too many?

Patch itself looks good.

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

> ---
>  drivers/gpu/drm/drm_fb_helper.c | 28 +++++++++++++++++-----------
>  1 file changed, 17 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
> index 116d1f1337c7..954cdd48de92 100644
> --- a/drivers/gpu/drm/drm_fb_helper.c
> +++ b/drivers/gpu/drm/drm_fb_helper.c
> @@ -150,6 +150,9 @@ int drm_fb_helper_add_one_connector(struct drm_fb_helper *fb_helper,
>  {
>  	int err;
>  
> +	if (!fb_helper)
> +		return 0;
> +
>  	mutex_lock(&fb_helper->lock);
>  	err = __drm_fb_helper_add_one_connector(fb_helper, connector);
>  	mutex_unlock(&fb_helper->lock);
> @@ -161,7 +164,7 @@ EXPORT_SYMBOL(drm_fb_helper_add_one_connector);
>  /**
>   * drm_fb_helper_single_add_all_connectors() - add all connectors to fbdev
>   * 					       emulation helper
> - * @fb_helper: fbdev initialized with drm_fb_helper_init
> + * @fb_helper: fbdev initialized with drm_fb_helper_init, can be NULL
>   *
>   * This functions adds all the available connectors for use with the given
>   * fb_helper. This is a separate step to allow drivers to freely assign
> @@ -179,7 +182,7 @@ int drm_fb_helper_single_add_all_connectors(struct drm_fb_helper *fb_helper)
>  	struct drm_connector_list_iter conn_iter;
>  	int i, ret = 0;
>  
> -	if (!drm_fbdev_emulation)
> +	if (!drm_fbdev_emulation || !fb_helper)
>  		return 0;
>  
>  	mutex_lock(&fb_helper->lock);
> @@ -245,6 +248,9 @@ int drm_fb_helper_remove_one_connector(struct drm_fb_helper *fb_helper,
>  {
>  	int err;
>  
> +	if (!fb_helper)
> +		return 0;
> +
>  	mutex_lock(&fb_helper->lock);
>  	err = __drm_fb_helper_remove_one_connector(fb_helper, connector);
>  	mutex_unlock(&fb_helper->lock);
> @@ -484,7 +490,7 @@ static int restore_fbdev_mode(struct drm_fb_helper *fb_helper)
>  
>  /**
>   * drm_fb_helper_restore_fbdev_mode_unlocked - restore fbdev configuration
> - * @fb_helper: fbcon to restore
> + * @fb_helper: driver-allocated fbdev helper, can be NULL
>   *
>   * This should be called from driver's drm &drm_driver.lastclose callback
>   * when implementing an fbcon on top of kms using this helper. This ensures that
> @@ -498,7 +504,7 @@ int drm_fb_helper_restore_fbdev_mode_unlocked(struct drm_fb_helper *fb_helper)
>  	bool do_delayed;
>  	int ret;
>  
> -	if (!drm_fbdev_emulation)
> +	if (!drm_fbdev_emulation || !fb_helper)
>  		return -ENODEV;
>  
>  	if (READ_ONCE(fb_helper->deferred_setup))
> @@ -883,7 +889,7 @@ EXPORT_SYMBOL(drm_fb_helper_alloc_fbi);
>  
>  /**
>   * drm_fb_helper_unregister_fbi - unregister fb_info framebuffer device
> - * @fb_helper: driver-allocated fbdev helper
> + * @fb_helper: driver-allocated fbdev helper, can be NULL
>   *
>   * A wrapper around unregister_framebuffer, to release the fb_info
>   * framebuffer device. This must be called before releasing all resources for
> @@ -898,7 +904,7 @@ EXPORT_SYMBOL(drm_fb_helper_unregister_fbi);
>  
>  /**
>   * drm_fb_helper_fini - finialize a &struct drm_fb_helper
> - * @fb_helper: driver-allocated fbdev helper
> + * @fb_helper: driver-allocated fbdev helper, can be NULL
>   *
>   * This cleans up all remaining resources associated with @fb_helper. Must be
>   * called after drm_fb_helper_unlink_fbi() was called.
> @@ -937,7 +943,7 @@ EXPORT_SYMBOL(drm_fb_helper_fini);
>  
>  /**
>   * drm_fb_helper_unlink_fbi - wrapper around unlink_framebuffer
> - * @fb_helper: driver-allocated fbdev helper
> + * @fb_helper: driver-allocated fbdev helper, can be NULL
>   *
>   * A wrapper around unlink_framebuffer implemented by fbdev core
>   */
> @@ -1138,7 +1144,7 @@ EXPORT_SYMBOL(drm_fb_helper_cfb_imageblit);
>  
>  /**
>   * drm_fb_helper_set_suspend - wrapper around fb_set_suspend
> - * @fb_helper: driver-allocated fbdev helper
> + * @fb_helper: driver-allocated fbdev helper, can be NULL
>   * @suspend: whether to suspend or resume
>   *
>   * A wrapper around fb_set_suspend implemented by fbdev core.
> @@ -1155,7 +1161,7 @@ EXPORT_SYMBOL(drm_fb_helper_set_suspend);
>  /**
>   * drm_fb_helper_set_suspend_unlocked - wrapper around fb_set_suspend that also
>   *                                      takes the console lock
> - * @fb_helper: driver-allocated fbdev helper
> + * @fb_helper: driver-allocated fbdev helper, can be NULL
>   * @suspend: whether to suspend or resume
>   *
>   * A wrapper around fb_set_suspend() that takes the console lock. If the lock
> @@ -2568,7 +2574,7 @@ EXPORT_SYMBOL(drm_fb_helper_initial_config);
>  /**
>   * drm_fb_helper_hotplug_event - respond to a hotplug notification by
>   *                               probing all the outputs attached to the fb
> - * @fb_helper: the drm_fb_helper
> + * @fb_helper: driver-allocated fbdev helper, can be NULL
>   *
>   * Scan the connectors attached to the fb_helper and try to put together a
>   * setup after notification of a change in output configuration.
> @@ -2590,7 +2596,7 @@ int drm_fb_helper_hotplug_event(struct drm_fb_helper *fb_helper)
>  {
>  	int err = 0;
>  
> -	if (!drm_fbdev_emulation)
> +	if (!drm_fbdev_emulation || !fb_helper)
>  		return 0;
>  
>  	mutex_lock(&fb_helper->lock);
> -- 
> 2.14.2
> 

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


More information about the dri-devel mailing list