diff mbox

vfio: fix config virtualization, esp command byte

Message ID 1289933847.3069.8.camel@x201 (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Alex Williamson Nov. 16, 2010, 6:57 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/vfio/vfio_pci_config.c b/drivers/vfio/vfio_pci_config.c
index 7132ac4..422d7b1 100644
--- a/drivers/vfio/vfio_pci_config.c
+++ b/drivers/vfio/vfio_pci_config.c
@@ -964,11 +964,6 @@  static int vfio_config_rwbyte(int write,
 		return 0;
 	}
 
-	if (write) {
-		if (copy_from_user(&newval, buf, 1))
-			return -EFAULT;
-	}
-
 	if (~virt) {	/* mix of real and virt bits */
 		/* update vconfig with latest hw bits */
 		ret = vfio_read_config_byte(vdev, pos, &realbits);
@@ -978,9 +973,14 @@  static int vfio_config_rwbyte(int write,
 			(vdev->vconfig[pos] & virt) | (realbits & ~virt);
 	}
 
-	/* update vconfig with writeable bits */
-	vdev->vconfig[pos] =
-		(vdev->vconfig[pos] & ~wr) | (newval & wr);
+	if (write) {
+		if (copy_from_user(&newval, buf, 1))
+			return -EFAULT;
+
+		/* update vconfig with writeable bits */
+		vdev->vconfig[pos] =
+			(vdev->vconfig[pos] & ~wr) | (newval & wr);
+        }
 
 	/*
 	 * Now massage virtual fields