diff mbox series

drm: log errors in drm_gem_fb_init_with_funcs

Message ID R359hIfrDhyN2VBgiSyQ1ogbifYmn7KwIuMUqS3u3A@cp4-web-032.plabs.ch (mailing list archive)
State New, archived
Headers show
Series drm: log errors in drm_gem_fb_init_with_funcs | expand

Commit Message

Simon Ser April 30, 2021, 2:40 p.m. UTC
Let the user know what went wrong in drm_gem_fb_init_with_funcs
failure paths.

Signed-off-by: Simon Ser <contact@emersion.fr>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Noralf Trønnes <noralf@tronnes.org>
Cc: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Michel Dänzer April 30, 2021, 2:46 p.m. UTC | #1
On 2021-04-30 4:40 p.m., Simon Ser wrote:
> Let the user know what went wrong in drm_gem_fb_init_with_funcs
> failure paths.
> 
> Signed-off-by: Simon Ser <contact@emersion.fr>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index 109d11fb4cd4..e4a3c7eb43b2 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -155,8 +155,10 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
>  	int ret, i;
>  
>  	info = drm_get_format_info(dev, mode_cmd);
> -	if (!info)
> +	if (!info) {
> +		drm_dbg_kms(dev, "Failed to get FB format info\n");
>  		return -EINVAL;
> +	}
>  
>  	for (i = 0; i < info->num_planes; i++) {
>  		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> @@ -175,6 +177,9 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
>  			 + mode_cmd->offsets[i];
>  
>  		if (objs[i]->size < min_size) {
> +			drm_dbg_kms(dev,
> +				    "GEM object size (%u) smaller than minimum size (%u) for plane %d\n",
> +				    objs[i]->size, min_size, i);
>  			drm_gem_object_put(objs[i]);
>  			ret = -EINVAL;
>  			goto err_gem_object_put;
> 

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>


I made almost the same change (except for the strings) for tracking down the issue fixed by https://patchwork.freedesktop.org/patch/431677/ (note my follow-up there!). :)
Ville Syrjala April 30, 2021, 3:28 p.m. UTC | #2
On Fri, Apr 30, 2021 at 02:40:02PM +0000, Simon Ser wrote:
> Let the user know what went wrong in drm_gem_fb_init_with_funcs
> failure paths.
> 
> Signed-off-by: Simon Ser <contact@emersion.fr>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Noralf Trønnes <noralf@tronnes.org>
> Cc: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index 109d11fb4cd4..e4a3c7eb43b2 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -155,8 +155,10 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
>  	int ret, i;
>  
>  	info = drm_get_format_info(dev, mode_cmd);
> -	if (!info)
> +	if (!info) {
> +		drm_dbg_kms(dev, "Failed to get FB format info\n");
>  		return -EINVAL;
> +	}

Assuming this thing gets plugged into .fb_create() getting
this far with a bogus format would be rather suprising.

>  
>  	for (i = 0; i < info->num_planes; i++) {
>  		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> @@ -175,6 +177,9 @@ int drm_gem_fb_init_with_funcs(struct drm_device *dev,
>  			 + mode_cmd->offsets[i];
>  
>  		if (objs[i]->size < min_size) {
> +			drm_dbg_kms(dev,
> +				    "GEM object size (%u) smaller than minimum size (%u) for plane %d\n",
> +				    objs[i]->size, min_size, i);
>  			drm_gem_object_put(objs[i]);
>  			ret = -EINVAL;
>  			goto err_gem_object_put;
> -- 
> 2.31.1
> 
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
kernel test robot April 30, 2021, 5:59 p.m. UTC | #3
Hi Simon,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on drm-tip/drm-tip drm-exynos/exynos-drm-next tegra-drm/drm/tegra/for-next linus/master v5.12 next-20210430]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Simon-Ser/drm-log-errors-in-drm_gem_fb_init_with_funcs/20210430-224208
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: riscv-randconfig-r012-20210430 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 8f5a2a5836cc8e4c1def2bdeb022e7b496623439)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install riscv cross compiling tool for clang build
        # apt-get install binutils-riscv64-linux-gnu
        # https://github.com/0day-ci/linux/commit/9a5b8d668b957989ae026f9f91da5ed59d831ef5
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Simon-Ser/drm-log-errors-in-drm_gem_fb_init_with_funcs/20210430-224208
        git checkout 9a5b8d668b957989ae026f9f91da5ed59d831ef5
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=riscv 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/drm_gem_framebuffer_helper.c:176:9: warning: format specifies type 'unsigned int' but the argument has type 'size_t' (aka 'unsigned long') [-Wformat]
                                       objs[i]->size, min_size, i);
                                       ^~~~~~~~~~~~~
   include/drm/drm_print.h:450:45: note: expanded from macro 'drm_dbg_kms'
           drm_dev_dbg((drm)->dev, DRM_UT_KMS, fmt, ##__VA_ARGS__)
                                               ~~~    ^~~~~~~~~~~
   1 warning generated.


vim +176 drivers/gpu/drm/drm_gem_framebuffer_helper.c

   118	
   119	/**
   120	 * drm_gem_fb_init_with_funcs() - Helper function for implementing
   121	 *				  &drm_mode_config_funcs.fb_create
   122	 *				  callback in cases when the driver
   123	 *				  allocates a subclass of
   124	 *				  struct drm_framebuffer
   125	 * @dev: DRM device
   126	 * @fb: framebuffer object
   127	 * @file: DRM file that holds the GEM handle(s) backing the framebuffer
   128	 * @mode_cmd: Metadata from the userspace framebuffer creation request
   129	 * @funcs: vtable to be used for the new framebuffer object
   130	 *
   131	 * This function can be used to set &drm_framebuffer_funcs for drivers that need
   132	 * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
   133	 * change &drm_framebuffer_funcs. The function does buffer size validation.
   134	 * The buffer size validation is for a general case, though, so users should
   135	 * pay attention to the checks being appropriate for them or, at least,
   136	 * non-conflicting.
   137	 *
   138	 * Returns:
   139	 * Zero or a negative error code.
   140	 */
   141	int drm_gem_fb_init_with_funcs(struct drm_device *dev,
   142				       struct drm_framebuffer *fb,
   143				       struct drm_file *file,
   144				       const struct drm_mode_fb_cmd2 *mode_cmd,
   145				       const struct drm_framebuffer_funcs *funcs)
   146	{
   147		const struct drm_format_info *info;
   148		struct drm_gem_object *objs[4];
   149		int ret, i;
   150	
   151		info = drm_get_format_info(dev, mode_cmd);
   152		if (!info) {
   153			drm_dbg_kms(dev, "Failed to get FB format info\n");
   154			return -EINVAL;
   155		}
   156	
   157		for (i = 0; i < info->num_planes; i++) {
   158			unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
   159			unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
   160			unsigned int min_size;
   161	
   162			objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
   163			if (!objs[i]) {
   164				drm_dbg_kms(dev, "Failed to lookup GEM object\n");
   165				ret = -ENOENT;
   166				goto err_gem_object_put;
   167			}
   168	
   169			min_size = (height - 1) * mode_cmd->pitches[i]
   170				 + drm_format_info_min_pitch(info, i, width)
   171				 + mode_cmd->offsets[i];
   172	
   173			if (objs[i]->size < min_size) {
   174				drm_dbg_kms(dev,
   175					    "GEM object size (%u) smaller than minimum size (%u) for plane %d\n",
 > 176					    objs[i]->size, min_size, i);
   177				drm_gem_object_put(objs[i]);
   178				ret = -EINVAL;
   179				goto err_gem_object_put;
   180			}
   181		}
   182	
   183		ret = drm_gem_fb_init(dev, fb, mode_cmd, objs, i, funcs);
   184		if (ret)
   185			goto err_gem_object_put;
   186	
   187		return 0;
   188	
   189	err_gem_object_put:
   190		for (i--; i >= 0; i--)
   191			drm_gem_object_put(objs[i]);
   192	
   193		return ret;
   194	}
   195	EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);
   196	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index 109d11fb4cd4..e4a3c7eb43b2 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -155,8 +155,10 @@  int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 	int ret, i;
 
 	info = drm_get_format_info(dev, mode_cmd);
-	if (!info)
+	if (!info) {
+		drm_dbg_kms(dev, "Failed to get FB format info\n");
 		return -EINVAL;
+	}
 
 	for (i = 0; i < info->num_planes; i++) {
 		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
@@ -175,6 +177,9 @@  int drm_gem_fb_init_with_funcs(struct drm_device *dev,
 			 + mode_cmd->offsets[i];
 
 		if (objs[i]->size < min_size) {
+			drm_dbg_kms(dev,
+				    "GEM object size (%u) smaller than minimum size (%u) for plane %d\n",
+				    objs[i]->size, min_size, i);
 			drm_gem_object_put(objs[i]);
 			ret = -EINVAL;
 			goto err_gem_object_put;