diff mbox series

drm/i915: Check input parameter for NULL

Message ID 1645455221-38580-1-git-send-email-lyz_cs@pku.edu.cn (mailing list archive)
State New, archived
Headers show
Series drm/i915: Check input parameter for NULL | expand

Commit Message

刘永志 Feb. 21, 2022, 2:53 p.m. UTC
[why]
i915_gem_object_put_pages_phys() frees pages and standard
pattern is to allow caller to not care if it's
NULL or not. This will reduce burden on
the callers to perform this check.

[how]
Fix it by adding Null check.

Signed-off-by: Yongzhi Liu <lyz_cs@pku.edu.cn>
---
 drivers/gpu/drm/i915/gem/i915_gem_phys.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

kernel test robot Feb. 21, 2022, 11:41 p.m. UTC | #1
Hi Yongzhi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on v5.17-rc5 next-20220217]
[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/Yongzhi-Liu/drm-i915-Check-input-parameter-for-NULL/20220221-225508
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-randconfig-a014-20220221 (https://download.01.org/0day-ci/archive/20220222/202202220722.25BhJJ6r-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)
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/0day-ci/linux/commit/c54be425a38b3f4cb82c5badecf6b343f9e24a90
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yongzhi-Liu/drm-i915-Check-input-parameter-for-NULL/20220221-225508
        git checkout c54be425a38b3f4cb82c5badecf6b343f9e24a90
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/gpu/drm/i915/

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/i915/gem/i915_gem_phys.c:100:13: warning: mixing declarations and code is a C99 extension [-Wdeclaration-after-statement]
           dma_addr_t dma = sg_dma_address(pages->sgl);
                      ^
   1 warning generated.


vim +100 drivers/gpu/drm/i915/gem/i915_gem_phys.c

f033428db28bdf Chris Wilson      2019-05-28   93  
a61170975718d5 Maarten Lankhorst 2021-03-23   94  void
f033428db28bdf Chris Wilson      2019-05-28   95  i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,
f033428db28bdf Chris Wilson      2019-05-28   96  			       struct sg_table *pages)
f033428db28bdf Chris Wilson      2019-05-28   97  {
c54be425a38b3f Yongzhi Liu       2022-02-21   98  	if (!pages)
c54be425a38b3f Yongzhi Liu       2022-02-21   99  		return;
c6790dc22312f5 Chris Wilson      2020-02-02 @100  	dma_addr_t dma = sg_dma_address(pages->sgl);
c6790dc22312f5 Chris Wilson      2020-02-02  101  	void *vaddr = sg_page(pages->sgl);
c6790dc22312f5 Chris Wilson      2020-02-02  102  
f033428db28bdf Chris Wilson      2019-05-28  103  	__i915_gem_object_release_shmem(obj, pages, false);
f033428db28bdf Chris Wilson      2019-05-28  104  
f033428db28bdf Chris Wilson      2019-05-28  105  	if (obj->mm.dirty) {
f033428db28bdf Chris Wilson      2019-05-28  106  		struct address_space *mapping = obj->base.filp->f_mapping;
c6790dc22312f5 Chris Wilson      2020-02-02  107  		void *src = vaddr;
f033428db28bdf Chris Wilson      2019-05-28  108  		int i;
f033428db28bdf Chris Wilson      2019-05-28  109  
f033428db28bdf Chris Wilson      2019-05-28  110  		for (i = 0; i < obj->base.size / PAGE_SIZE; i++) {
f033428db28bdf Chris Wilson      2019-05-28  111  			struct page *page;
f033428db28bdf Chris Wilson      2019-05-28  112  			char *dst;
f033428db28bdf Chris Wilson      2019-05-28  113  
f033428db28bdf Chris Wilson      2019-05-28  114  			page = shmem_read_mapping_page(mapping, i);
f033428db28bdf Chris Wilson      2019-05-28  115  			if (IS_ERR(page))
f033428db28bdf Chris Wilson      2019-05-28  116  				continue;
f033428db28bdf Chris Wilson      2019-05-28  117  
f033428db28bdf Chris Wilson      2019-05-28  118  			dst = kmap_atomic(page);
c6790dc22312f5 Chris Wilson      2020-02-02  119  			drm_clflush_virt_range(src, PAGE_SIZE);
c6790dc22312f5 Chris Wilson      2020-02-02  120  			memcpy(dst, src, PAGE_SIZE);
f033428db28bdf Chris Wilson      2019-05-28  121  			kunmap_atomic(dst);
f033428db28bdf Chris Wilson      2019-05-28  122  
f033428db28bdf Chris Wilson      2019-05-28  123  			set_page_dirty(page);
f033428db28bdf Chris Wilson      2019-05-28  124  			if (obj->mm.madv == I915_MADV_WILLNEED)
f033428db28bdf Chris Wilson      2019-05-28  125  				mark_page_accessed(page);
f033428db28bdf Chris Wilson      2019-05-28  126  			put_page(page);
c6790dc22312f5 Chris Wilson      2020-02-02  127  
c6790dc22312f5 Chris Wilson      2020-02-02  128  			src += PAGE_SIZE;
f033428db28bdf Chris Wilson      2019-05-28  129  		}
f033428db28bdf Chris Wilson      2019-05-28  130  		obj->mm.dirty = false;
f033428db28bdf Chris Wilson      2019-05-28  131  	}
f033428db28bdf Chris Wilson      2019-05-28  132  
f033428db28bdf Chris Wilson      2019-05-28  133  	sg_free_table(pages);
f033428db28bdf Chris Wilson      2019-05-28  134  	kfree(pages);
f033428db28bdf Chris Wilson      2019-05-28  135  
8ff5446a7ca47c Thomas Zimmermann 2021-01-28  136  	dma_free_coherent(obj->base.dev->dev,
c6790dc22312f5 Chris Wilson      2020-02-02  137  			  roundup_pow_of_two(obj->base.size),
c6790dc22312f5 Chris Wilson      2020-02-02  138  			  vaddr, dma);
f033428db28bdf Chris Wilson      2019-05-28  139  }
f033428db28bdf Chris Wilson      2019-05-28  140  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Feb. 22, 2022, 12:12 a.m. UTC | #2
Hi Yongzhi,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on v5.17-rc5 next-20220217]
[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/Yongzhi-Liu/drm-i915-Check-input-parameter-for-NULL/20220221-225508
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: x86_64-randconfig-a001-20220221 (https://download.01.org/0day-ci/archive/20220222/202202220847.76w2eWNU-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/c54be425a38b3f4cb82c5badecf6b343f9e24a90
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yongzhi-Liu/drm-i915-Check-input-parameter-for-NULL/20220221-225508
        git checkout c54be425a38b3f4cb82c5badecf6b343f9e24a90
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/gpu/drm/i915/

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/i915/gem/i915_gem_phys.c: In function 'i915_gem_object_put_pages_phys':
>> drivers/gpu/drm/i915/gem/i915_gem_phys.c:100:2: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
     100 |  dma_addr_t dma = sg_dma_address(pages->sgl);
         |  ^~~~~~~~~~


vim +100 drivers/gpu/drm/i915/gem/i915_gem_phys.c

f033428db28bdf Chris Wilson      2019-05-28   93  
a61170975718d5 Maarten Lankhorst 2021-03-23   94  void
f033428db28bdf Chris Wilson      2019-05-28   95  i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,
f033428db28bdf Chris Wilson      2019-05-28   96  			       struct sg_table *pages)
f033428db28bdf Chris Wilson      2019-05-28   97  {
c54be425a38b3f Yongzhi Liu       2022-02-21   98  	if (!pages)
c54be425a38b3f Yongzhi Liu       2022-02-21   99  		return;
c6790dc22312f5 Chris Wilson      2020-02-02 @100  	dma_addr_t dma = sg_dma_address(pages->sgl);
c6790dc22312f5 Chris Wilson      2020-02-02  101  	void *vaddr = sg_page(pages->sgl);
c6790dc22312f5 Chris Wilson      2020-02-02  102  
f033428db28bdf Chris Wilson      2019-05-28  103  	__i915_gem_object_release_shmem(obj, pages, false);
f033428db28bdf Chris Wilson      2019-05-28  104  
f033428db28bdf Chris Wilson      2019-05-28  105  	if (obj->mm.dirty) {
f033428db28bdf Chris Wilson      2019-05-28  106  		struct address_space *mapping = obj->base.filp->f_mapping;
c6790dc22312f5 Chris Wilson      2020-02-02  107  		void *src = vaddr;
f033428db28bdf Chris Wilson      2019-05-28  108  		int i;
f033428db28bdf Chris Wilson      2019-05-28  109  
f033428db28bdf Chris Wilson      2019-05-28  110  		for (i = 0; i < obj->base.size / PAGE_SIZE; i++) {
f033428db28bdf Chris Wilson      2019-05-28  111  			struct page *page;
f033428db28bdf Chris Wilson      2019-05-28  112  			char *dst;
f033428db28bdf Chris Wilson      2019-05-28  113  
f033428db28bdf Chris Wilson      2019-05-28  114  			page = shmem_read_mapping_page(mapping, i);
f033428db28bdf Chris Wilson      2019-05-28  115  			if (IS_ERR(page))
f033428db28bdf Chris Wilson      2019-05-28  116  				continue;
f033428db28bdf Chris Wilson      2019-05-28  117  
f033428db28bdf Chris Wilson      2019-05-28  118  			dst = kmap_atomic(page);
c6790dc22312f5 Chris Wilson      2020-02-02  119  			drm_clflush_virt_range(src, PAGE_SIZE);
c6790dc22312f5 Chris Wilson      2020-02-02  120  			memcpy(dst, src, PAGE_SIZE);
f033428db28bdf Chris Wilson      2019-05-28  121  			kunmap_atomic(dst);
f033428db28bdf Chris Wilson      2019-05-28  122  
f033428db28bdf Chris Wilson      2019-05-28  123  			set_page_dirty(page);
f033428db28bdf Chris Wilson      2019-05-28  124  			if (obj->mm.madv == I915_MADV_WILLNEED)
f033428db28bdf Chris Wilson      2019-05-28  125  				mark_page_accessed(page);
f033428db28bdf Chris Wilson      2019-05-28  126  			put_page(page);
c6790dc22312f5 Chris Wilson      2020-02-02  127  
c6790dc22312f5 Chris Wilson      2020-02-02  128  			src += PAGE_SIZE;
f033428db28bdf Chris Wilson      2019-05-28  129  		}
f033428db28bdf Chris Wilson      2019-05-28  130  		obj->mm.dirty = false;
f033428db28bdf Chris Wilson      2019-05-28  131  	}
f033428db28bdf Chris Wilson      2019-05-28  132  
f033428db28bdf Chris Wilson      2019-05-28  133  	sg_free_table(pages);
f033428db28bdf Chris Wilson      2019-05-28  134  	kfree(pages);
f033428db28bdf Chris Wilson      2019-05-28  135  
8ff5446a7ca47c Thomas Zimmermann 2021-01-28  136  	dma_free_coherent(obj->base.dev->dev,
c6790dc22312f5 Chris Wilson      2020-02-02  137  			  roundup_pow_of_two(obj->base.size),
c6790dc22312f5 Chris Wilson      2020-02-02  138  			  vaddr, dma);
f033428db28bdf Chris Wilson      2019-05-28  139  }
f033428db28bdf Chris Wilson      2019-05-28  140  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Feb. 22, 2022, 1:23 a.m. UTC | #3
Hi Yongzhi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on v5.17-rc5 next-20220217]
[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/Yongzhi-Liu/drm-i915-Check-input-parameter-for-NULL/20220221-225508
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-randconfig-a004-20220221 (https://download.01.org/0day-ci/archive/20220222/202202220935.3r4emO4y-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/c54be425a38b3f4cb82c5badecf6b343f9e24a90
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Yongzhi-Liu/drm-i915-Check-input-parameter-for-NULL/20220221-225508
        git checkout c54be425a38b3f4cb82c5badecf6b343f9e24a90
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

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

All errors (new ones prefixed by >>):

   drivers/gpu/drm/i915/gem/i915_gem_phys.c: In function 'i915_gem_object_put_pages_phys':
>> drivers/gpu/drm/i915/gem/i915_gem_phys.c:100:2: error: ISO C90 forbids mixed declarations and code [-Werror=declaration-after-statement]
     100 |  dma_addr_t dma = sg_dma_address(pages->sgl);
         |  ^~~~~~~~~~
   cc1: all warnings being treated as errors


vim +100 drivers/gpu/drm/i915/gem/i915_gem_phys.c

f033428db28bdf Chris Wilson      2019-05-28   93  
a61170975718d5 Maarten Lankhorst 2021-03-23   94  void
f033428db28bdf Chris Wilson      2019-05-28   95  i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,
f033428db28bdf Chris Wilson      2019-05-28   96  			       struct sg_table *pages)
f033428db28bdf Chris Wilson      2019-05-28   97  {
c54be425a38b3f Yongzhi Liu       2022-02-21   98  	if (!pages)
c54be425a38b3f Yongzhi Liu       2022-02-21   99  		return;
c6790dc22312f5 Chris Wilson      2020-02-02 @100  	dma_addr_t dma = sg_dma_address(pages->sgl);
c6790dc22312f5 Chris Wilson      2020-02-02  101  	void *vaddr = sg_page(pages->sgl);
c6790dc22312f5 Chris Wilson      2020-02-02  102  
f033428db28bdf Chris Wilson      2019-05-28  103  	__i915_gem_object_release_shmem(obj, pages, false);
f033428db28bdf Chris Wilson      2019-05-28  104  
f033428db28bdf Chris Wilson      2019-05-28  105  	if (obj->mm.dirty) {
f033428db28bdf Chris Wilson      2019-05-28  106  		struct address_space *mapping = obj->base.filp->f_mapping;
c6790dc22312f5 Chris Wilson      2020-02-02  107  		void *src = vaddr;
f033428db28bdf Chris Wilson      2019-05-28  108  		int i;
f033428db28bdf Chris Wilson      2019-05-28  109  
f033428db28bdf Chris Wilson      2019-05-28  110  		for (i = 0; i < obj->base.size / PAGE_SIZE; i++) {
f033428db28bdf Chris Wilson      2019-05-28  111  			struct page *page;
f033428db28bdf Chris Wilson      2019-05-28  112  			char *dst;
f033428db28bdf Chris Wilson      2019-05-28  113  
f033428db28bdf Chris Wilson      2019-05-28  114  			page = shmem_read_mapping_page(mapping, i);
f033428db28bdf Chris Wilson      2019-05-28  115  			if (IS_ERR(page))
f033428db28bdf Chris Wilson      2019-05-28  116  				continue;
f033428db28bdf Chris Wilson      2019-05-28  117  
f033428db28bdf Chris Wilson      2019-05-28  118  			dst = kmap_atomic(page);
c6790dc22312f5 Chris Wilson      2020-02-02  119  			drm_clflush_virt_range(src, PAGE_SIZE);
c6790dc22312f5 Chris Wilson      2020-02-02  120  			memcpy(dst, src, PAGE_SIZE);
f033428db28bdf Chris Wilson      2019-05-28  121  			kunmap_atomic(dst);
f033428db28bdf Chris Wilson      2019-05-28  122  
f033428db28bdf Chris Wilson      2019-05-28  123  			set_page_dirty(page);
f033428db28bdf Chris Wilson      2019-05-28  124  			if (obj->mm.madv == I915_MADV_WILLNEED)
f033428db28bdf Chris Wilson      2019-05-28  125  				mark_page_accessed(page);
f033428db28bdf Chris Wilson      2019-05-28  126  			put_page(page);
c6790dc22312f5 Chris Wilson      2020-02-02  127  
c6790dc22312f5 Chris Wilson      2020-02-02  128  			src += PAGE_SIZE;
f033428db28bdf Chris Wilson      2019-05-28  129  		}
f033428db28bdf Chris Wilson      2019-05-28  130  		obj->mm.dirty = false;
f033428db28bdf Chris Wilson      2019-05-28  131  	}
f033428db28bdf Chris Wilson      2019-05-28  132  
f033428db28bdf Chris Wilson      2019-05-28  133  	sg_free_table(pages);
f033428db28bdf Chris Wilson      2019-05-28  134  	kfree(pages);
f033428db28bdf Chris Wilson      2019-05-28  135  
8ff5446a7ca47c Thomas Zimmermann 2021-01-28  136  	dma_free_coherent(obj->base.dev->dev,
c6790dc22312f5 Chris Wilson      2020-02-02  137  			  roundup_pow_of_two(obj->base.size),
c6790dc22312f5 Chris Wilson      2020-02-02  138  			  vaddr, dma);
f033428db28bdf Chris Wilson      2019-05-28  139  }
f033428db28bdf Chris Wilson      2019-05-28  140  

---
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/i915/gem/i915_gem_phys.c b/drivers/gpu/drm/i915/gem/i915_gem_phys.c
index ca6faff..5445f41 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_phys.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_phys.c
@@ -95,6 +95,8 @@  void
 i915_gem_object_put_pages_phys(struct drm_i915_gem_object *obj,
 			       struct sg_table *pages)
 {
+	if (!pages)
+		return;
 	dma_addr_t dma = sg_dma_address(pages->sgl);
 	void *vaddr = sg_page(pages->sgl);