Skip to contentSkip to conversation

xen/gntdev: add ioctl for grant copy

DISCUSSION Dan Carpenter 2 participants 2 messages Jan 13, 2016 – Jan 14, 2016

lore
Share & tools
lore
#0 lore raw

Hello David Vrabel,

The patch a4cdb556cae0: "xen/gntdev: add ioctl for grant copy" from Dec 2, 2014, leads to the following static checker warning:

	drivers/xen/gntdev.c:775 gntdev_get_page()
	warn: mask and shift to zero

drivers/xen/gntdev.c
761 static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt,
762 bool writeable, unsigned long *gfn)
763 {

   764          unsigned long addr = (unsigned long)virt;
   765          struct page *page;
   766          unsigned long xen_pfn;
   767          int ret;
   768  
   769          ret = get_user_pages_fast(addr, 1, writeable, &page);
   770          if (ret < 0)
   771                  return ret;
   772  
   773          batch->pages[batch->nr_pages++] = page;
   774  
   775          xen_pfn = page_to_xen_pfn(page) + XEN_PFN_DOWN(addr & ~PAGE_MASK);
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is zero most of the time. Did you intend the bitwise negate?

   776          *gfn = pfn_to_gfn(xen_pfn);
   777  
   778          return 0;
   779  }

regards,
dan carpenter

#1 lore raw
Quoted 25 lines · Dan Carpenter

Hello David Vrabel,

The patch a4cdb556cae0: "xen/gntdev: add ioctl for grant copy" from Dec 2, 2014, leads to the following static checker warning:

	drivers/xen/gntdev.c:775 gntdev_get_page()
	warn: mask and shift to zero

drivers/xen/gntdev.c
761 static int gntdev_get_page(struct gntdev_copy_batch *batch, void __user *virt,
762 bool writeable, unsigned long *gfn)

   763  {
   764          unsigned long addr = (unsigned long)virt;
   765          struct page *page;
   766          unsigned long xen_pfn;
   767          int ret;
   768  
   769          ret = get_user_pages_fast(addr, 1, writeable, &page);
   770          if (ret < 0)
   771                  return ret;
   772  
   773          batch->pages[batch->nr_pages++] = page;
   774  
   775          xen_pfn = page_to_xen_pfn(page) + XEN_PFN_DOWN(addr & ~PAGE_MASK);
                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 1 line

This is zero most of the time. Did you intend the bitwise negate?

This is non-zero if XEN_PAGE_SIZE < PAGE_SIZE and is needed for this case.

David