drivers/media/common/videobuf2/videobuf2-dma-contig.c:188 vb2_dc_mmap() warn: variable dereferenced before check 'buf' (see line 185)
PATCH 3/10 drivers/media/common/videobuf2/videobuf2-dma-contig.c:188 vb2_dc_mmap() warn: variable dereferenced before check 'buf' (see line 185)
tree: git://git.infradead.org/users/hch/misc.git dma_alloc_noncontiguous head: ecc175d8a7100071b073720d6729bb3f40dae639 commit: 6673227deba5cfc9c90084f49988e044a2ca2933 [3/10] WIP videobuf2: rework vb2_mem_ops API config: x86_64-randconfig-m001-20210126 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
smatch warnings:drivers/media/common/videobuf2/videobuf2-dma-contig.c:188 vb2_dc_mmap() warn: variable dereferenced before check 'buf' (see line 185)
vim +/buf +188 drivers/media/common/videobuf2/videobuf2-dma-contig.c
f7f129ce2e33f9 drivers/media/v4l2-core/videobuf2-dma-contig.c Laurent Pinchart 2012-06-14 182 static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma)
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 183 {
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 184 struct vb2_dc_buf *buf = buf_priv;
6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 @185 struct vb2_queue *q = buf->vb->vb2_queue;
^^^^^Dereference
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 186 int ret;
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 187
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 @188 if (!buf) {
^^^^NULL check is too late.
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 189 printk(KERN_ERR "No buffer to map\n");
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 190 return -EINVAL;
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 191 }
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 192
6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 193 ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, buf->dma_addr,
6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 194 buf->size, q->dma_attrs);
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 195 if (ret) {
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 196 pr_err("Remapping memory failed, error: %d\n", ret);---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 28 lines · Dan Carpenter
tree: git://git.infradead.org/users/hch/misc.git dma_alloc_noncontiguous head: ecc175d8a7100071b073720d6729bb3f40dae639 commit: 6673227deba5cfc9c90084f49988e044a2ca2933 [3/10] WIP videobuf2: rework vb2_mem_ops API config: x86_64-randconfig-m001-20210126 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>smatch warnings:
drivers/media/common/videobuf2/videobuf2-dma-contig.c:188vb2_dc_mmap()warn: variable dereferenced before check 'buf' (see line 185)vim +/buf +188
drivers/media/common/videobuf2/videobuf2-dma-contig.cf7f129ce2e33f9 drivers/media/v4l2-core/videobuf2-dma-contig.c Laurent Pinchart 2012-06-14 182 static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 183 { 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 184 struct vb2_dc_buf *buf = buf_priv; 6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 @185 struct vb2_queue *q = buf->vb->vb2_queue; ^^^^^Dereference
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 186 int ret; 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 187 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 @188 if (!buf) { ^^^^NULL check is too late.
Quoted 8 lines
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 189 printk(KERN_ERR "No buffer to map\n");
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 190 return -EINVAL;
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 191 }
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 192
6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 193 ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, buf->dma_addr,
6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 194 buf->size, q->dma_attrs);
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 195 if (ret) {
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 196 pr_err("Remapping memory failed, error: %d\n", ret);Oh, yeah...
I'll take a look. My WIP branch is not really ready for the show yet.
-ss
Quoted 38 lines · Sergey Senozhatsky
Quoted 28 lines · Dan Carpenter
tree: git://git.infradead.org/users/hch/misc.git dma_alloc_noncontiguous head: ecc175d8a7100071b073720d6729bb3f40dae639 commit: 6673227deba5cfc9c90084f49988e044a2ca2933 [3/10] WIP videobuf2: rework vb2_mem_ops API config: x86_64-randconfig-m001-20210126 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>smatch warnings:
drivers/media/common/videobuf2/videobuf2-dma-contig.c:188vb2_dc_mmap()warn: variable dereferenced before check 'buf' (see line 185)vim +/buf +188
drivers/media/common/videobuf2/videobuf2-dma-contig.cf7f129ce2e33f9 drivers/media/v4l2-core/videobuf2-dma-contig.c Laurent Pinchart 2012-06-14 182 static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 183 { 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 184 struct vb2_dc_buf *buf = buf_priv; 6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 @185 struct vb2_queue *q = buf->vb->vb2_queue; ^^^^^Dereference
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 186 int ret; 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 187 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 @188 if (!buf) { ^^^^NULL check is too late.
Quoted 8 lines
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 189 printk(KERN_ERR "No buffer to map\n"); 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 190 return -EINVAL; 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 191 } 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 192 6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 193 ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, buf->dma_addr, 6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 194 buf->size, q->dma_attrs); c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 195 if (ret) { c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 196 pr_err("Remapping memory failed, error: %d\n", ret);
Quoted 3 lines
Oh, yeah...
I'll take a look. My WIP branch is not really ready for the show yet.
Could also be that I messed it up when porting to the new API..
Quoted 27 lines · Christoph Hellwig
Quoted 27 lines
Quoted 26 lines
smatch warnings:
drivers/media/common/videobuf2/videobuf2-dma-contig.c:188vb2_dc_mmap()warn: variable dereferenced before check 'buf' (see line 185)vim +/buf +188
drivers/media/common/videobuf2/videobuf2-dma-contig.cf7f129ce2e33f9 drivers/media/v4l2-core/videobuf2-dma-contig.c Laurent Pinchart 2012-06-14 182 static int vb2_dc_mmap(void *buf_priv, struct vm_area_struct *vma) 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 183 { 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 184 struct vb2_dc_buf *buf = buf_priv; 6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 @185 struct vb2_queue *q = buf->vb->vb2_queue; ^^^^^Dereference
c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 186 int ret; 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 187 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 @188 if (!buf) { ^^^^NULL check is too late.
1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 189 printk(KERN_ERR "No buffer to map\n"); 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 190 return -EINVAL; 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 191 } 1a758d4e847f77 drivers/media/video/videobuf2-dma-contig.c Pawel Osciak 2010-10-11 192 6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 193 ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, buf->dma_addr, 6673227deba5cf drivers/media/common/videobuf2/videobuf2-dma-contig.c Sergey Senozhatsky 2020-11-27 194 buf->size, q->dma_attrs); c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 195 if (ret) { c60520fa50cd86 drivers/media/v4l2-core/videobuf2-dma-contig.c Marek Szyprowski 2012-06-14 196 pr_err("Remapping memory failed, error: %d\n", ret);
Quoted 5 lines
Quoted 3 lines
Oh, yeah...
I'll take a look. My WIP branch is not really ready for the show yet.
Could also be that I messed it up when porting to the new API..
Rather unlikely ;)
I'm reworking some of the patches in my WIP branch. For instance, I don't think that reading queue->flags is ->preare and ->finish is
correct: the queue can be reconfigured while the buffers are still on the fly, so we'll read stale data. So vb2_queue->non_consistent_mem should be store in buffers, during allocation.
Need some more time.
-ss