Skip to contentSkip to conversation

fix ioctl return value

PATCH In review Glauber Costa 2 participants 4 messages Jul 21, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix ioctl return value

we expect a number less than 0, not exactly -1.
And furthermore, we return errno itself, so no need to use it.

This might break guests when this ioctl fails for some reason.

---
 kvm-all.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kvm-all.c +2 -3
index 8567ac9..9a79466 100644
@@ -319,9 +319,8 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
 
         d.slot = mem->slot;
 
-        if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) {
-            dprintf("ioctl failed %d\n", errno);
-            ret = -1;
+        if ((ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d)) < 0) {
+            dprintf("ioctl failed %d\n", ret);
             break;
         }
 
Signature · 1 line
1.6.2.2
#1 lore raw
Quoted 15 lines · Glauber Costa

we expect a number less than 0, not exactly -1.
And furthermore, we return errno itself, so no need to use it.

This might break guests when this ioctl fails for some reason.

---
 kvm-all.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kvm-all.c +0 -0
index 8567ac9..9a79466 100644

kvm-all.c int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, · line 324

Quoted 9 lines
kvm-all.c +2 -3
@@ -319,9 +319,8 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
 
         d.slot = mem->slot;
 
-        if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) {
-            dprintf("ioctl failed %d\n", errno);
-            ret = -1;
+        if ((ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d)) < 0) {
+            dprintf("ioctl failed %d\n", ret);
 

While this is fine, I usually prefer:

ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d);
if (ret < 0) {
dprintf(ioctl failed %d\n", ret);

Signature · 3 lines
Regards,

Anthony Liguori
#2 lore raw
Quoted 28 lines · Anthony Liguori
Quoted 15 lines · Glauber Costa

we expect a number less than 0, not exactly -1.
And furthermore, we return errno itself, so no need to use it.

This might break guests when this ioctl fails for some reason.

---
 kvm-all.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
kvm-all.c +0 -0
index 8567ac9..9a79466 100644

kvm-all.c int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, · line 324

Quoted 9 lines
kvm-all.c +2 -3
@@ -319,9 +319,8 @@ int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr,
 
         d.slot = mem->slot;
 
-        if (kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d) == -1) {
-            dprintf("ioctl failed %d\n", errno);
-            ret = -1;
+        if ((ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d)) < 0) {
+            dprintf("ioctl failed %d\n", ret);
 

While this is fine, I usually prefer:

Quoted 3 lines

ret = kvm_vm_ioctl(s, KVM_GET_DIRTY_LOG, &d);

if (ret < 0) {
   dprintf(ioctl failed %d\n", ret);

want me to shoot a new one?

#3 lore raw
Quoted 2 lines · Glauber Costa

want me to shoot a new one?

It's up to you.

Signature · 3 lines
Regards,

Anthony Liguori