[bug report] [media] vmalloc_sg: make sure all pages in vmalloc area are really DMA-ready

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi linux-media devs, this is similar to one of HCH's patches that
hasn't been applied yet.

The patch 7b4eeed174b7: "[media] vmalloc_sg: make sure all pages in
vmalloc area are really DMA-ready" from Jun 12, 2014, leads to the
following static checker warning:

	drivers/media/v4l2-core/videobuf-dma-sg.c:236 videobuf_dma_init_kernel()
	error: 'addr' came from dma_alloc_coherent() so we can't do virt_to_phys()

drivers/media/v4l2-core/videobuf-dma-sg.c
   210  static int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
   211                               int nr_pages)
   212  {
   213          int i;
   214  
   215          dprintk(1, "init kernel [%d pages]\n", nr_pages);
   216  
   217          dma->direction = direction;
   218          dma->vaddr_pages = kcalloc(nr_pages, sizeof(*dma->vaddr_pages),
   219                                     GFP_KERNEL);
   220          if (!dma->vaddr_pages)
   221                  return -ENOMEM;
   222  
   223          dma->dma_addr = kcalloc(nr_pages, sizeof(*dma->dma_addr), GFP_KERNEL);
   224          if (!dma->dma_addr) {
   225                  kfree(dma->vaddr_pages);
   226                  return -ENOMEM;
   227          }
   228          for (i = 0; i < nr_pages; i++) {
   229                  void *addr;
   230  
   231                  addr = dma_alloc_coherent(dma->dev, PAGE_SIZE,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^

   232                                            &(dma->dma_addr[i]), GFP_KERNEL);
   233                  if (addr == NULL)
   234                          goto out_free_pages;
   235  
   236                  dma->vaddr_pages[i] = virt_to_page(addr);
                                              ^^^^^^^^^^^^^^^^^^
Apparently this isn't allowed.

   237          }
   238          dma->vaddr = vmap(dma->vaddr_pages, nr_pages, VM_MAP | VM_IOREMAP,
   239                            PAGE_KERNEL);
   240          if (NULL == dma->vaddr) {
   241                  dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
   242                  goto out_free_pages;
   243          }
   244  
   245          dprintk(1, "vmalloc is at addr %p, size=%d\n",
   246                  dma->vaddr, nr_pages << PAGE_SHIFT);
   247  
   248          memset(dma->vaddr, 0, nr_pages << PAGE_SHIFT);
   249          dma->nr_pages = nr_pages;
   250  
   251          return 0;
   252  out_free_pages:
   253          while (i > 0) {
   254                  void *addr;

regards,
dan carpenter



[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux