drivers/gpu/drm/drm_gem_shmem_helper.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
From: Rob Clark <robdclark@chromium.org>
Once we create the handle, the handle owns the reference. Currently
nothing was doing anything with the shmem ptr after the handle was
created, but let's change drm_gem_shmem_create_with_handle() to not
return the pointer, so-as to not encourage problematic use of this
function in the future. As a bonus, it makes the code a bit cleaner.
Signed-off-by: Rob Clark <robdclark@chromium.org>
---
drivers/gpu/drm/drm_gem_shmem_helper.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c
index f21f47737817..19406f4907df 100644
--- a/drivers/gpu/drm/drm_gem_shmem_helper.c
+++ b/drivers/gpu/drm/drm_gem_shmem_helper.c
@@ -415,7 +415,7 @@ void drm_gem_shmem_vunmap(struct drm_gem_shmem_object *shmem,
}
EXPORT_SYMBOL(drm_gem_shmem_vunmap);
-static struct drm_gem_shmem_object *
+static int
drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
struct drm_device *dev, size_t size,
uint32_t *handle)
@@ -434,10 +434,8 @@ drm_gem_shmem_create_with_handle(struct drm_file *file_priv,
ret = drm_gem_handle_create(file_priv, &shmem->base, handle);
/* drop reference from allocate - handle holds it now. */
drm_gem_object_put(&shmem->base);
- if (ret)
- return ERR_PTR(ret);
- return shmem;
+ return ret;
}
/* Update madvise status, returns true if not purged, else
@@ -533,9 +531,7 @@ int drm_gem_shmem_dumb_create(struct drm_file *file, struct drm_device *dev,
args->size = PAGE_ALIGN(args->pitch * args->height);
}
- shmem = drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
-
- return PTR_ERR_OR_ZERO(shmem);
+ return drm_gem_shmem_create_with_handle(file, dev, args->size, &args->handle);
}
EXPORT_SYMBOL_GPL(drm_gem_shmem_dumb_create);
--
2.38.1
Hi Rob, I love your patch! Perhaps something to improve: [auto build test WARNING on drm-misc/drm-misc-next] [also build test WARNING on drm/drm-next drm-exynos/exynos-drm-next drm-intel/for-linux-next drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.2-rc4 next-20230119] [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#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Rob-Clark/drm-shmem-Cleanup-drm_gem_shmem_create_with_handle/20230120-021440 base: git://anongit.freedesktop.org/drm/drm-misc drm-misc-next patch link: https://lore.kernel.org/r/20230119181325.2834875-1-robdclark%40gmail.com patch subject: [PATCH] drm/shmem: Cleanup drm_gem_shmem_create_with_handle() config: ia64-allyesconfig (https://download.01.org/0day-ci/archive/20230120/202301200511.h6Af907u-lkp@intel.com/config) compiler: ia64-linux-gcc (GCC) 12.1.0 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 # https://github.com/intel-lab-lkp/linux/commit/0de4f64a7edc0dcbf8ac711d79e203698fcd95a7 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Rob-Clark/drm-shmem-Cleanup-drm_gem_shmem_create_with_handle/20230120-021440 git checkout 0de4f64a7edc0dcbf8ac711d79e203698fcd95a7 # save the config file mkdir build_dir && cp config build_dir/.config COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=ia64 SHELL=/bin/bash drivers/gpu/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): drivers/gpu/drm/drm_gem_shmem_helper.c: In function 'drm_gem_shmem_create_with_handle': >> drivers/gpu/drm/drm_gem_shmem_helper.c:428:24: warning: returning 'struct drm_gem_shmem_object *' from a function with return type 'int' makes integer from pointer without a cast [-Wint-conversion] 428 | return shmem; | ^~~~~ drivers/gpu/drm/drm_gem_shmem_helper.c: In function 'drm_gem_shmem_dumb_create': drivers/gpu/drm/drm_gem_shmem_helper.c:521:38: warning: unused variable 'shmem' [-Wunused-variable] 521 | struct drm_gem_shmem_object *shmem; | ^~~~~ vim +428 drivers/gpu/drm/drm_gem_shmem_helper.c 2194a63a818db7 Noralf Trønnes 2019-03-12 417 0de4f64a7edc0d Rob Clark 2023-01-19 418 static int 2194a63a818db7 Noralf Trønnes 2019-03-12 419 drm_gem_shmem_create_with_handle(struct drm_file *file_priv, 2194a63a818db7 Noralf Trønnes 2019-03-12 420 struct drm_device *dev, size_t size, 2194a63a818db7 Noralf Trønnes 2019-03-12 421 uint32_t *handle) 2194a63a818db7 Noralf Trønnes 2019-03-12 422 { 2194a63a818db7 Noralf Trønnes 2019-03-12 423 struct drm_gem_shmem_object *shmem; 2194a63a818db7 Noralf Trønnes 2019-03-12 424 int ret; 2194a63a818db7 Noralf Trønnes 2019-03-12 425 cfe28f909ddd6c Daniel Vetter 2020-06-16 426 shmem = drm_gem_shmem_create(dev, size); 2194a63a818db7 Noralf Trønnes 2019-03-12 427 if (IS_ERR(shmem)) 2194a63a818db7 Noralf Trønnes 2019-03-12 @428 return shmem; 2194a63a818db7 Noralf Trønnes 2019-03-12 429 2194a63a818db7 Noralf Trønnes 2019-03-12 430 /* 2194a63a818db7 Noralf Trønnes 2019-03-12 431 * Allocate an id of idr table where the obj is registered 2194a63a818db7 Noralf Trønnes 2019-03-12 432 * and handle has the id what user can see. 2194a63a818db7 Noralf Trønnes 2019-03-12 433 */ 2194a63a818db7 Noralf Trønnes 2019-03-12 434 ret = drm_gem_handle_create(file_priv, &shmem->base, handle); 2194a63a818db7 Noralf Trønnes 2019-03-12 435 /* drop reference from allocate - handle holds it now. */ be6ee102341bc4 Emil Velikov 2020-05-15 436 drm_gem_object_put(&shmem->base); 2194a63a818db7 Noralf Trønnes 2019-03-12 437 0de4f64a7edc0d Rob Clark 2023-01-19 438 return ret; 2194a63a818db7 Noralf Trønnes 2019-03-12 439 } 2194a63a818db7 Noralf Trønnes 2019-03-12 440 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
© 2016 - 2025 Red Hat, Inc.