Skip to contentSkip to conversation

virtio-serial: Simplify virtio_serial_load()

PATCH Applied Markus Armbruster 4 participants 5 messages May 31, 2010 – Jun 30, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-serial: Simplify virtio_serial_load()

For all i, ports_map[i] is used in and only in the i-th iteration. Replace the dynamic array by a scalar variable.

---
 hw/virtio-serial-bus.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
hw/virtio-serial-bus.c +3 -9
index 3ce95e8..bcc6d5d 100644
@@ -492,8 +492,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
 {
     VirtIOSerial *s = opaque;
     VirtIOSerialPort *port;
-    size_t ports_map_size;
-    uint32_t max_nr_ports, nr_active_ports, *ports_map;
+    uint32_t max_nr_ports, nr_active_ports, ports_map;
     unsigned int i;
 
     if (version_id > 2) {
@@ -517,22 +516,17 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
         return -EINVAL;
     }
 
-    ports_map_size = sizeof(uint32_t) * (max_nr_ports + 31) / 32;
-    ports_map = qemu_malloc(ports_map_size);
-
     for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
-        qemu_get_be32s(f, &ports_map[i]);
+        qemu_get_be32s(f, &ports_map);
 
-        if (ports_map[i] != s->ports_map[i]) {
+        if (ports_map != s->ports_map[i]) {
             /*
              * Ports active on source and destination don't
              * match. Fail migration.
              */
-            qemu_free(ports_map);
             return -EINVAL;
         }
     }
-    qemu_free(ports_map);
 
     qemu_get_be32s(f, &nr_active_ports);
 
Signature · 1 line
1.6.6.1
#2 lore raw
In reply to Markus Armbruster
Quoted 51 lines · ----- "Markus Armbruster

For all i, ports_map[i] is used in and only in the i-th iteration. Replace the dynamic array by a scalar variable.

---
 hw/virtio-serial-bus.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
hw/virtio-serial-bus.c +1 -2
index 3ce95e8..bcc6d5d 100644
@@ -492,8 +492,7 @@ static int virtio_serial_load(QEMUFile *f, void
 *opaque, int version_id)
 {
     VirtIOSerial *s = opaque;
     VirtIOSerialPort *port;
-    size_t ports_map_size;
-    uint32_t max_nr_ports, nr_active_ports, *ports_map;
+    uint32_t max_nr_ports, nr_active_ports, ports_map;
     unsigned int i;
 
     if (version_id > 2) {
hw/virtio-serial-bus.c +2 -7
@@ -517,22 +516,17 @@ static int virtio_serial_load(QEMUFile *f, void
 *opaque, int version_id)
         return -EINVAL;
     }
 
-    ports_map_size = sizeof(uint32_t) * (max_nr_ports + 31) / 32;
-    ports_map = qemu_malloc(ports_map_size);
-
     for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
-        qemu_get_be32s(f, &ports_map[i]);
+        qemu_get_be32s(f, &ports_map);
 
-        if (ports_map[i] != s->ports_map[i]) {
+        if (ports_map != s->ports_map[i]) {
             /*
              * Ports active on source and destination don't
              * match. Fail migration.
              */
-            qemu_free(ports_map);
             return -EINVAL;
         }
     }
-    qemu_free(ports_map);
 
     qemu_get_be32s(f, &nr_active_ports);
Signature · 2 lines
-- 
1.6.6.1

ACK

#3 lore raw
In reply to Markus Armbruster

Did this fall through the cracks?

Quoted 46 lines · Markus Armbruster

For all i, ports_map[i] is used in and only in the i-th iteration. Replace the dynamic array by a scalar variable.

---
 hw/virtio-serial-bus.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)
hw/virtio-serial-bus.c +3 -9
index 3ce95e8..bcc6d5d 100644
@@ -492,8 +492,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
 {
     VirtIOSerial *s = opaque;
     VirtIOSerialPort *port;
-    size_t ports_map_size;
-    uint32_t max_nr_ports, nr_active_ports, *ports_map;
+    uint32_t max_nr_ports, nr_active_ports, ports_map;
     unsigned int i;
 
     if (version_id > 2) {
@@ -517,22 +516,17 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
         return -EINVAL;
     }
 
-    ports_map_size = sizeof(uint32_t) * (max_nr_ports + 31) / 32;
-    ports_map = qemu_malloc(ports_map_size);
-
     for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
-        qemu_get_be32s(f, &ports_map[i]);
+        qemu_get_be32s(f, &ports_map);
 
-        if (ports_map[i] != s->ports_map[i]) {
+        if (ports_map != s->ports_map[i]) {
             /*
              * Ports active on source and destination don't
              * match. Fail migration.
              */
-            qemu_free(ports_map);
             return -EINVAL;
         }
     }
-    qemu_free(ports_map);
 
     qemu_get_be32s(f, &nr_active_ports);
#4 lore raw
In reply to Markus Armbruster
Quoted 7 lines · Markus Armbruster

For all i, ports_map[i] is used in and only in the i-th iteration. Replace the dynamic array by a scalar variable.

---
 hw/virtio-serial-bus.c |   12 +++---------
 1 files changed, 3 insertions(+), 9 deletions(-)

Thanks, applied.

Quoted 44 lines
hw/virtio-serial-bus.c +3 -9
index 3ce95e8..bcc6d5d 100644
@@ -492,8 +492,7 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
 {
     VirtIOSerial *s = opaque;
     VirtIOSerialPort *port;
-    size_t ports_map_size;
-    uint32_t max_nr_ports, nr_active_ports, *ports_map;
+    uint32_t max_nr_ports, nr_active_ports, ports_map;
     unsigned int i;
 
     if (version_id > 2) {
@@ -517,22 +516,17 @@ static int virtio_serial_load(QEMUFile *f, void *opaque, int version_id)
         return -EINVAL;
     }
 
-    ports_map_size = sizeof(uint32_t) * (max_nr_ports + 31) / 32;
-    ports_map = qemu_malloc(ports_map_size);
-
     for (i = 0; i < (max_nr_ports + 31) / 32; i++) {
-        qemu_get_be32s(f, &ports_map[i]);
+        qemu_get_be32s(f, &ports_map);
 
-        if (ports_map[i] != s->ports_map[i]) {
+        if (ports_map != s->ports_map[i]) {
             /*
              * Ports active on source and destination don't
              * match. Fail migration.
              */
-            qemu_free(ports_map);
             return -EINVAL;
         }
     }
-    qemu_free(ports_map);
 
     qemu_get_be32s(f, &nr_active_ports);
 
Signature · 1 line
1.6.6.1
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net