[vfio:vfio-vga 4/5] drivers/vfio/pci/vfio_pci_rdwr.c:191 vfio_pci_legacy_mem_rw() warn: consider using resource_size() here

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

 



Hi Alex,

FYI, there are new smatch warnings show up in

tree:   git://github.com/awilliam/linux-vfio.git vfio-vga
head:   2c2e21fa66c40ed7b8e434c86a9f2ab0c879f21d
commit: c5b7a5a85fa477e70497c513f2acda50eea73bf7 [4/5] vfio-pci: Add support for legacy MMIO & I/O port towards VGA support

New smatch warnings:
drivers/vfio/pci/vfio_pci_rdwr.c:191 vfio_pci_legacy_mem_rw() warn: consider using resource_size() here
drivers/vfio/pci/vfio_pci_rdwr.c:206 vfio_pci_legacy_mem_rw() warn: always true condition '(done >= 0) => (0-u32max >= 0)'
drivers/vfio/pci/vfio_pci_rdwr.c:254 vfio_pci_legacy_io_rw() warn: always true condition '(done >= 0) => (0-u32max >= 0)'

Old smatch warnings:
drivers/vfio/pci/vfio_pci_rdwr.c:170 vfio_pci_bar_rw() warn: always true condition '(done >= 0) => (0-u32max >= 0)'

git remote add vfio git://github.com/awilliam/linux-vfio.git
git remote update vfio
git checkout c5b7a5a85fa477e70497c513f2acda50eea73bf7
vim +191 drivers/vfio/pci/vfio_pci_rdwr.c

c5b7a5a8 Alex Williamson 2013-01-16  185  	if (vdev->has_vga && pos >= 0xa0000 && pos < 0xc0000) {
c5b7a5a8 Alex Williamson 2013-01-16  186  		void __iomem *mem;
c5b7a5a8 Alex Williamson 2013-01-16  187  		size_t done;
c5b7a5a8 Alex Williamson 2013-01-16  188  
c5b7a5a8 Alex Williamson 2013-01-16  189  		count = min(count, (size_t)(0xc0000 - pos));
c5b7a5a8 Alex Williamson 2013-01-16  190  
c5b7a5a8 Alex Williamson 2013-01-16 @191  		mem = ioremap_nocache(0xa0000, 0xc0000 - 0xa0000);
c5b7a5a8 Alex Williamson 2013-01-16  192  		if (!mem)
c5b7a5a8 Alex Williamson 2013-01-16  193  			return -ENOMEM;
c5b7a5a8 Alex Williamson 2013-01-16  194  
c5b7a5a8 Alex Williamson 2013-01-16  195  		ret = vga_get_interruptible(vdev->pdev, VGA_RSRC_LEGACY_MEM);
c5b7a5a8 Alex Williamson 2013-01-16  196  		if (ret) {
c5b7a5a8 Alex Williamson 2013-01-16  197  			iounmap(mem);
c5b7a5a8 Alex Williamson 2013-01-16  198  			return ret;
c5b7a5a8 Alex Williamson 2013-01-16  199  		}
c5b7a5a8 Alex Williamson 2013-01-16  200  
c5b7a5a8 Alex Williamson 2013-01-16  201  		done = do_io_rw(mem, buf, pos - 0xa0000, count, 0, 0, iswrite);
c5b7a5a8 Alex Williamson 2013-01-16  202  
c5b7a5a8 Alex Williamson 2013-01-16  203  		vga_put(vdev->pdev, VGA_RSRC_LEGACY_MEM);
c5b7a5a8 Alex Williamson 2013-01-16  204  		iounmap(mem);
c5b7a5a8 Alex Williamson 2013-01-16  205  
c5b7a5a8 Alex Williamson 2013-01-16 @206  		if (done >= 0)
c5b7a5a8 Alex Williamson 2013-01-16  207  			*ppos += done;
c5b7a5a8 Alex Williamson 2013-01-16  208  
c5b7a5a8 Alex Williamson 2013-01-16  209  		return done;
c5b7a5a8 Alex Williamson 2013-01-16  210  	}
c5b7a5a8 Alex Williamson 2013-01-16  211  
c5b7a5a8 Alex Williamson 2013-01-16  212  	return -EINVAL;
c5b7a5a8 Alex Williamson 2013-01-16  213  }
c5b7a5a8 Alex Williamson 2013-01-16  214  
c5b7a5a8 Alex Williamson 2013-01-16  215  ssize_t vfio_pci_legacy_io_rw(struct vfio_pci_device *vdev, char __user *buf,
c5b7a5a8 Alex Williamson 2013-01-16  216  			      size_t count, loff_t *ppos, bool iswrite)
c5b7a5a8 Alex Williamson 2013-01-16  217  {
c5b7a5a8 Alex Williamson 2013-01-16  218  	int ret;
c5b7a5a8 Alex Williamson 2013-01-16  219  	loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
c5b7a5a8 Alex Williamson 2013-01-16  220  
c5b7a5a8 Alex Williamson 2013-01-16  221  	if (vdev->has_vga &&
c5b7a5a8 Alex Williamson 2013-01-16  222  	    ((pos >= 0x3b0 && pos < 0x3bc) || (pos >= 0x3c0 && pos < 0x3e0))) {
c5b7a5a8 Alex Williamson 2013-01-16  223  		void __iomem *io = NULL;
c5b7a5a8 Alex Williamson 2013-01-16  224  		loff_t off;
c5b7a5a8 Alex Williamson 2013-01-16  225  		size_t done;
c5b7a5a8 Alex Williamson 2013-01-16  226  
c5b7a5a8 Alex Williamson 2013-01-16  227  		switch (pos) {
c5b7a5a8 Alex Williamson 2013-01-16  228  		case 0x3b0 ... 0x3bb:
c5b7a5a8 Alex Williamson 2013-01-16  229  			count = min(count, (size_t)(0x3bc - pos));
c5b7a5a8 Alex Williamson 2013-01-16  230  			io = ioport_map(0x3b0, 0x3bc - 0x3b0);
c5b7a5a8 Alex Williamson 2013-01-16  231  			off = pos - 0x3b0;
c5b7a5a8 Alex Williamson 2013-01-16  232  			break;
c5b7a5a8 Alex Williamson 2013-01-16  233  		case 0x3c0 ... 0x3df:
c5b7a5a8 Alex Williamson 2013-01-16  234  			count = min(count, (size_t)(0x3e0 - pos));
c5b7a5a8 Alex Williamson 2013-01-16  235  			io = ioport_map(0x3c0, 0x3e0 - 0x3c0);
c5b7a5a8 Alex Williamson 2013-01-16  236  			off = pos - 0x3c0;
c5b7a5a8 Alex Williamson 2013-01-16  237  			break;
c5b7a5a8 Alex Williamson 2013-01-16  238  		}
c5b7a5a8 Alex Williamson 2013-01-16  239  
c5b7a5a8 Alex Williamson 2013-01-16  240  		if (!io)
c5b7a5a8 Alex Williamson 2013-01-16  241  			return -ENOMEM;
c5b7a5a8 Alex Williamson 2013-01-16  242  
c5b7a5a8 Alex Williamson 2013-01-16  243  		ret = vga_get_interruptible(vdev->pdev, VGA_RSRC_LEGACY_IO);
c5b7a5a8 Alex Williamson 2013-01-16  244  		if (ret) {
c5b7a5a8 Alex Williamson 2013-01-16  245  			ioport_unmap(io);
c5b7a5a8 Alex Williamson 2013-01-16  246  			return ret;
c5b7a5a8 Alex Williamson 2013-01-16  247  		}
c5b7a5a8 Alex Williamson 2013-01-16  248  
c5b7a5a8 Alex Williamson 2013-01-16  249  		done = do_io_rw(io, buf, off, count, 0, 0, iswrite);
c5b7a5a8 Alex Williamson 2013-01-16  250  
c5b7a5a8 Alex Williamson 2013-01-16  251  		vga_put(vdev->pdev, VGA_RSRC_LEGACY_IO);
c5b7a5a8 Alex Williamson 2013-01-16  252  		ioport_unmap(io);
c5b7a5a8 Alex Williamson 2013-01-16  253  
c5b7a5a8 Alex Williamson 2013-01-16 @254  		if (done >= 0)
c5b7a5a8 Alex Williamson 2013-01-16  255  			*ppos += done;
c5b7a5a8 Alex Williamson 2013-01-16  256  
c5b7a5a8 Alex Williamson 2013-01-16  257  		return done;

---
0-DAY kernel build testing backend              Open Source Technology Center
http://lists.01.org/mailman/listinfo/kbuild                 Intel Corporation
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux