Skip to contentSkip to conversation

More miscellaneous error handling fixes

PATCH Superseded Markus Armbruster 8 participants 31 messages Apr 24, 2020 – May 4, 2020

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover More miscellaneous error handling fixes

Markus Armbruster (11):
nvdimm: Plug memory leak in uuid property setter
xen: Fix and improve handling of device_add usb-host errors s390x/cpumodel: Fix harmless misuse of visit_check_struct() s390x/pci: Fix harmless mistake in zpci's property fid's setter tests/migration: Tighten error checking
error: Use error_reportf_err() where appropriate mips/malta: Fix create_cps() error handling mips/boston: Fix boston_mach_init() error handling mips/boston: Plug memory leak in boston_mach_init() arm/sabrelite: Consistently use &error_fatal in sabrelite_init()
i386: Fix x86_cpu_load_model() error API violation

 chardev/char-socket.c        |  5 +++--
 hw/arm/sabrelite.c           |  7 +------
 hw/mem/nvdimm.c              |  1 -
 hw/mips/boston.c             | 17 +++++++----------
 hw/mips/mips_malta.c         | 15 ++++++---------
 hw/s390x/s390-pci-bus.c      |  4 +++-
 hw/sd/pxa2xx_mmci.c          |  4 ++--
 hw/sd/sd.c                   |  4 ++--
 hw/usb/dev-mtp.c             |  9 +++++----
 hw/usb/xen-usb.c             | 18 ++++++++----------
 qemu-nbd.c                   |  7 +++----
 scsi/qemu-pr-helper.c        |  4 ++--
 target/i386/cpu.c            | 25 ++++++++++++++++---------
 target/s390x/cpu_models.c    |  2 +-
 tests/qtest/migration-test.c |  4 ++--
 15 files changed, 61 insertions(+), 65 deletions(-)
Signature · 1 line
2.21.1
#1 lore raw

PATCH 1/11 nvdimm: Plug memory leak in uuid property setter

nvdimm_set_uuid() leaks memory on qemu_uuid_parse() failure. Fix that.

Fixes 6c5627bb24dcd68c997857a8b671617333b1289f
Cc Xiao Guangrong <[email protected]>
Cc Shivaprasad G Bhat <[email protected]>
---
 hw/mem/nvdimm.c | 1 -
 1 file changed, 1 deletion(-)
hw/mem/nvdimm.c +0 -1
index 8e426d24bb..d5752f7bf6 100644
@@ -97,7 +97,6 @@ static void nvdimm_set_uuid(Object *obj, Visitor *v, const char *name,
     if (qemu_uuid_parse(value, &nvdimm->uuid) != 0) {
         error_setg(errp, "Property '%s.%s' has invalid value",
                    object_get_typename(obj), name);
-        goto out;
     }
     g_free(value);
 
Signature · 1 line
2.21.1
#2 lore raw

PATCH 2/11 xen: Fix and improve handling of device_add usb-host errors

In reply to Markus Armbruster

usbback_portid_add() leaks the error when qdev_device_add() fails. Fix that. While there, use the error to improve the error message.

The qemu_opts_from_qdict() similarly leaks on failure. But any failure there is a programming error. Pass &error_abort.

Fixes 816ac92ef769f9ffc534e49a1bb6177bddce7aa2
Cc Stefano Stabellini <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Paul Durrant <[email protected]>
Cc Gerd Hoffmann <[email protected]>
---
 hw/usb/xen-usb.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
hw/usb/xen-usb.c +8 -10
index 961190d0f7..42643c3390 100644
@@ -30,6 +30,7 @@
 #include "hw/usb.h"
 #include "hw/xen/xen-legacy-backend.h"
 #include "monitor/qdev.h"
+#include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
 
@@ -755,13 +756,15 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
     qdict_put_int(qdict, "port", port);
     qdict_put_int(qdict, "hostbus", atoi(busid));
     qdict_put_str(qdict, "hostport", portname);
-    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
-    if (local_err) {
-        goto err;
-    }
+    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict,
+                                &error_abort);
     usbif->ports[port - 1].dev = USB_DEVICE(qdev_device_add(opts, &local_err));
     if (!usbif->ports[port - 1].dev) {
-        goto err;
+        qobject_unref(qdict);
+        xen_pv_printf(&usbif->xendev, 0,
+                      "device %s could not be opened: %s\n",
+                      busid, error_get_pretty(local_err));
+        error_free(local_err);
     }
     qobject_unref(qdict);
     speed = usbif->ports[port - 1].dev->speed;
@@ -793,11 +796,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
     usbback_hotplug_enq(usbif, port);
 
     TR_BUS(&usbif->xendev, "port %d attached\n", port);
-    return;
-
-err:
-    qobject_unref(qdict);
-    xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid);
 }
 
 static void usbback_process_port(struct usbback_info *usbif, unsigned port)
Signature · 1 line
2.21.1
#3 lore raw

RE: [PATCH 02/11] xen: Fix and improve handling of device_add usb-host errors

Quoted 45 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: 24 April 2020 20:20
To: [email protected]
Cc: Stefano Stabellini <[email protected]>; Anthony Perard <[email protected]>; Paul Durrant <[email protected]>; Gerd Hoffmann <[email protected]>; [email protected]
Subject: [PATCH 02/11] xen: Fix and improve handling of device_add usb-host errors

usbback_portid_add() leaks the error when qdev_device_add() fails. Fix that. While there, use the error to improve the error message.

The qemu_opts_from_qdict() similarly leaks on failure. But any failure there is a programming error. Pass &error_abort.

Fixes 816ac92ef769f9ffc534e49a1bb6177bddce7aa2
Cc Stefano Stabellini <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Paul Durrant <[email protected]>
Cc Gerd Hoffmann <[email protected]>
---
 hw/usb/xen-usb.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
hw/usb/xen-usb.c +1 -4
index 961190d0f7..42643c3390 100644
@@ -30,6 +30,7 @@
 #include "hw/usb.h"
 #include "hw/xen/xen-legacy-backend.h"
 #include "monitor/qdev.h"
+#include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
 
@@ -755,13 +756,15 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
     qdict_put_int(qdict, "port", port);
     qdict_put_int(qdict, "hostbus", atoi(busid));
     qdict_put_str(qdict, "hostport", portname);
-    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
-    if (local_err) {
-        goto err;
-    }

hw/usb/xen-usb.c static void usbback_portid_add(struct usbback_info *usbif, unsigned port, · line 767

Quoted 10 lines
hw/usb/xen-usb.c +7 -1
+    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict,
+                                &error_abort);
     usbif->ports[port - 1].dev = USB_DEVICE(qdev_device_add(opts, &local_err));
     if (!usbif->ports[port - 1].dev) {
-        goto err;
+        qobject_unref(qdict);
+        xen_pv_printf(&usbif->xendev, 0,
+                      "device %s could not be opened: %s\n",
+                      busid, error_get_pretty(local_err));
+        error_free(local_err);

Previously the goto caused the function to bail out. Should there not be a 'return' here?

Quoted 17 lines
hw/usb/xen-usb.c +0 -6
     }
     qobject_unref(qdict);
     speed = usbif->ports[port - 1].dev->speed;
@@ -793,11 +796,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
     usbback_hotplug_enq(usbif, port);
 
     TR_BUS(&usbif->xendev, "port %d attached\n", port);
-    return;
-
-err:
-    qobject_unref(qdict);
-    xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid);
 }
 
 static void usbback_process_port(struct usbback_info *usbif, unsigned port)
--

2.21.1

#4 lore raw

Re: [PATCH 02/11] xen: Fix and improve handling of device_add usb-host errors

Quoted 49 lines · Paul Durrant
Quoted 49 lines

-----Original Message-----
From: Markus Armbruster <[email protected]>
Sent: 24 April 2020 20:20
To: [email protected]
Cc: Stefano Stabellini <[email protected]>; Anthony Perard <[email protected]>; Paul Durrant <[email protected]>; Gerd Hoffmann <[email protected]>; [email protected]
Subject: [PATCH 02/11] xen: Fix and improve handling of device_add usb-host errors

usbback_portid_add() leaks the error when qdev_device_add() fails. Fix that. While there, use the error to improve the error message.

The qemu_opts_from_qdict() similarly leaks on failure. But any failure there is a programming error. Pass &error_abort.

Fixes 816ac92ef769f9ffc534e49a1bb6177bddce7aa2
Cc Stefano Stabellini <[email protected]>
Cc Anthony Perard <[email protected]>
Cc Paul Durrant <[email protected]>
Cc Gerd Hoffmann <[email protected]>
---
 hw/usb/xen-usb.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
hw/usb/xen-usb.c +3 -4
index 961190d0f7..42643c3390 100644
@@ -30,6 +30,7 @@
 #include "hw/usb.h"
 #include "hw/xen/xen-legacy-backend.h"
 #include "monitor/qdev.h"
+#include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qapi/qmp/qstring.h"
 
@@ -755,13 +756,15 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
     qdict_put_int(qdict, "port", port);
     qdict_put_int(qdict, "hostbus", atoi(busid));
     qdict_put_str(qdict, "hostport", portname);
-    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
-    if (local_err) {
-        goto err;
-    }
+    opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict,
+                                &error_abort);
     usbif->ports[port - 1].dev = USB_DEVICE(qdev_device_add(opts, &local_err));
     if (!usbif->ports[port - 1].dev) {
Quoted 8 lines

hw/usb/xen-usb.c static void usbback_portid_add(struct usbback_info *usbif, unsigned port, · line 767

Quoted 6 lines
hw/usb/xen-usb.c +5 -1
-        goto err;
+        qobject_unref(qdict);
+        xen_pv_printf(&usbif->xendev, 0,
+                      "device %s could not be opened: %s\n",
+                      busid, error_get_pretty(local_err));
+        error_free(local_err);

Previously the goto caused the function to bail out. Should there not be a 'return' here?

Owww, of course. Thanks!

Quoted 18 lines
Quoted 18 lines
hw/usb/xen-usb.c +0 -6
     }
     qobject_unref(qdict);
     speed = usbif->ports[port - 1].dev->speed;
@@ -793,11 +796,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
     usbback_hotplug_enq(usbif, port);
 
     TR_BUS(&usbif->xendev, "port %d attached\n", port);
-    return;
-
-err:
-    qobject_unref(qdict);
-    xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid);
 }
 
 static void usbback_process_port(struct usbback_info *usbif, unsigned port)
--

2.21.1

#5 lore raw

PATCH 3/11 s390x/cpumodel: Fix harmless misuse of visit_check_struct()

In reply to Markus Armbruster

Commit e47970f51d "s390x/cpumodel: Fix query-cpu-model-FOO error API violations" neglected to change visit_end_struct()'s Error ** argument along with the others. If visit_end_struct() failed, we'd take the success path. Fortunately, it can't fail here:
qobject_input_check_struct() checks we consumed the whole dictionary, and to get here, we did. Fix it anyway.

Cc David Hildenbrand <[email protected]>
Cc Cornelia Huck <[email protected]>
---
 target/s390x/cpu_models.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/cpu_models.c +1 -1
index 7c32180269..87a8028ad3 100644
@@ -524,7 +524,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
             }
         }
         if (!err) {
-            visit_check_struct(visitor, errp);
+            visit_check_struct(visitor, &err);
         }
         visit_end_struct(visitor, NULL);
         visit_free(visitor);
Signature · 1 line
2.21.1
Reviewed-by on v1 3/11
#6 lore raw

Re: [PATCH 03/11] s390x/cpumodel: Fix harmless misuse of visit_check_struct()

Quoted 3 lines · Markus Armbruster

Commit e47970f51d "s390x/cpumodel: Fix query-cpu-model-FOO error API violations" neglected to change visit_end_struct()'s Error ** argument along with the others. If visit_end_struct() failed, we'd take the

s/visit_end_struct/visit_check_struct/ ?

Quoted 3 lines

success path. Fortunately, it can't fail here:
qobject_input_check_struct() checks we consumed the whole dictionary, and to get here, we did. Fix it anyway.

AFAIKs, if visit_check_struct() failed, we'd still do the memcopy, but also report the error. Not nice, not bad.

Quoted 22 lines
Cc David Hildenbrand <[email protected]>
Cc Cornelia Huck <[email protected]>
---
 target/s390x/cpu_models.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/cpu_models.c +1 -1
index 7c32180269..87a8028ad3 100644
@@ -524,7 +524,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,
             }
         }
         if (!err) {
-            visit_check_struct(visitor, errp);
+            visit_check_struct(visitor, &err);
         }
         visit_end_struct(visitor, NULL);
         visit_free(visitor);
Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH 03/11] s390x/cpumodel: Fix harmless misuse of visit_check_struct()

Quoted 6 lines · David Hildenbrand
Quoted 3 lines · Markus Armbruster

Commit e47970f51d "s390x/cpumodel: Fix query-cpu-model-FOO error API violations" neglected to change visit_end_struct()'s Error ** argument along with the others. If visit_end_struct() failed, we'd take the

s/visit_end_struct/visit_check_struct/ ?

Will fix.

Quoted 8 lines
Quoted 3 lines

success path. Fortunately, it can't fail here:
qobject_input_check_struct() checks we consumed the whole dictionary, and to get here, we did. Fix it anyway.

AFAIKs, if visit_check_struct() failed, we'd still do the memcopy, but also report the error. Not nice, not bad.

Thanks!

#8 lore raw

Re: [PATCH 03/11] s390x/cpumodel: Fix harmless misuse of visit_check_struct()

Quoted 15 lines · On Wed, 29 Apr 2020 07:51:04 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 6 lines · David Hildenbrand
Quoted 3 lines · Markus Armbruster

Commit e47970f51d "s390x/cpumodel: Fix query-cpu-model-FOO error API violations" neglected to change visit_end_struct()'s Error ** argument along with the others. If visit_end_struct() failed, we'd take the

s/visit_end_struct/visit_check_struct/ ?

Will fix.

Quoted 4 lines
Quoted 3 lines

success path. Fortunately, it can't fail here:
qobject_input_check_struct() checks we consumed the whole dictionary, and to get here, we did. Fix it anyway.

Quoted 6 lines
Quoted 4 lines

AFAIKs, if visit_check_struct() failed, we'd still do the memcopy, but also report the error. Not nice, not bad.

Thanks!

Will you queue this, or shall I queue it?

#9 lore raw

Re: [PATCH 03/11] s390x/cpumodel: Fix harmless misuse of visit_check_struct()

Quoted 18 lines · Cornelia Huck
Quoted 15 lines · On Wed, 29 Apr 2020 07:51:04 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 6 lines · David Hildenbrand
Quoted 3 lines · Markus Armbruster

Commit e47970f51d "s390x/cpumodel: Fix query-cpu-model-FOO error API violations" neglected to change visit_end_struct()'s Error ** argument along with the others. If visit_end_struct() failed, we'd take the

s/visit_end_struct/visit_check_struct/ ?

Will fix.

Quoted 4 lines
Quoted 3 lines

success path. Fortunately, it can't fail here:
qobject_input_check_struct() checks we consumed the whole dictionary, and to get here, we did. Fix it anyway.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

AFAIKs, if visit_check_struct() failed, we'd still do the memcopy, but also report the error. Not nice, not bad.

Thanks!

Will you queue this, or shall I queue it?

Me taking the complete series through my tree would be easiest for me. But I can cope with other maintainers picking up bits.

Reviewed-by
#10 lore raw

Re: [PATCH 03/11] s390x/cpumodel: Fix harmless misuse of visit_check_struct()

Quoted 23 lines · On Mon, 04 May 2020 17:24:59 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 21 lines · Cornelia Huck
Quoted 18 lines · On Wed, 29 Apr 2020 07:51:04 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 6 lines · David Hildenbrand
Quoted 3 lines · Markus Armbruster

Commit e47970f51d "s390x/cpumodel: Fix query-cpu-model-FOO error API violations" neglected to change visit_end_struct()'s Error ** argument along with the others. If visit_end_struct() failed, we'd take the

s/visit_end_struct/visit_check_struct/ ?

Will fix.

Quoted 7 lines
Quoted 3 lines

success path. Fortunately, it can't fail here:
qobject_input_check_struct() checks we consumed the whole dictionary, and to get here, we did. Fix it anyway.

AFAIKs, if visit_check_struct() failed, we'd still do the memcopy, but also report the error. Not nice, not bad.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Thanks!

Will you queue this, or shall I queue it?

Me taking the complete series through my tree would be easiest for me. But I can cope with other maintainers picking up bits.

In that case, have my

and feel free to pick up :)

#11 lore raw

PATCH 4/11 s390x/pci: Fix harmless mistake in zpci's property fid's setter

In reply to Markus Armbruster

s390_pci_set_fid() sets zpci->fid_defined to true even when visit_type_uint32() failed. Reproducer: "-device zpci,fid=junk". Harmless in practice, because qdev_device_add() then fails, throwing away @zpci. Fix it anyway.

Cc Matthew Rosato <[email protected]>
Cc Cornelia Huck <[email protected]>
---
 hw/s390x/s390-pci-bus.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-bus.c +3 -1
index ed8be124da..19ee1f02bb 100644
@@ -1276,7 +1276,9 @@ static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    visit_type_uint32(v, name, ptr, errp);
+    if (!visit_type_uint32(v, name, ptr, errp)) {
+        return;
+    }
     zpci->fid_defined = true;
 }
 
Signature · 1 line
2.21.1
#12 lore raw

Re: [PATCH 04/11] s390x/pci: Fix harmless mistake in zpci's property fid's setter

Quoted 17 lines · Markus Armbruster

s390_pci_set_fid() sets zpci->fid_defined to true even when visit_type_uint32() failed. Reproducer: "-device zpci,fid=junk". Harmless in practice, because qdev_device_add() then fails, throwing away @zpci. Fix it anyway.

Cc Matthew Rosato <[email protected]>
Cc Cornelia Huck <[email protected]>
---
  hw/s390x/s390-pci-bus.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-bus.c +0 -0
index ed8be124da..19ee1f02bb 100644

hw/s390x/s390-pci-bus.c static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name, · line 1281

Quoted 7 lines
hw/s390x/s390-pci-bus.c +3 -1
@@ -1276,7 +1276,9 @@ static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
          return;
      }
 
-    visit_type_uint32(v, name, ptr, errp);
+    if (!visit_type_uint32(v, name, ptr, errp)) {
+        return;
+    }

Hi Markus,

Am I missing something here (a preceding patch maybe?) -- visit_type_uint32 is a void function. A quick look, no other callers are checking it for a return value either...

The error value might get set in visit_type_uintN though. Taking a hint from other places that handle this sort of case (ex: cpu_max_set_sve_max_vq), maybe something like:

Error *err = NULL;
...
visit_type_uint32(v, name, ptr, &err);

if (err) {
	error_propogate(errp, err);
	return;
}

zpci->fid_defined = true;

Instead?

#13 lore raw

Re: [PATCH 04/11] s390x/pci: Fix harmless mistake in zpci's property fid's setter

Quoted 38 lines · Matthew Rosato
Quoted 17 lines · Markus Armbruster

s390_pci_set_fid() sets zpci->fid_defined to true even when visit_type_uint32() failed. Reproducer: "-device zpci,fid=junk". Harmless in practice, because qdev_device_add() then fails, throwing away @zpci. Fix it anyway.

Cc Matthew Rosato <[email protected]>
Cc Cornelia Huck <[email protected]>
---
  hw/s390x/s390-pci-bus.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
hw/s390x/s390-pci-bus.c +0 -0
index ed8be124da..19ee1f02bb 100644

hw/s390x/s390-pci-bus.c static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name, · line 1281

Quoted 6 lines
hw/s390x/s390-pci-bus.c +3 -0
@@ -1276,7 +1276,9 @@ static void s390_pci_set_fid(Object *obj, Visitor *v, const char *name,
          return;
      }
  -    visit_type_uint32(v, name, ptr, errp);
+    if (!visit_type_uint32(v, name, ptr, errp)) {
+        return;
+    }

Hi Markus,

Am I missing something here (a preceding patch maybe?) -- visit_type_uint32 is a void function. A quick look, no other callers are checking it for a return value either...

The error value might get set in visit_type_uintN though. Taking a hint from other places that handle this sort of case (ex:
cpu_max_set_sve_max_vq), maybe something like:

Error *err = NULL;
...
visit_type_uint32(v, name, ptr, &err);

Quoted 7 lines
if (err) {
	error_propogate(errp, err);
	return;
}

zpci->fid_defined = true;

Instead?

This patch crept into this series by mistake. It indeed depends on other work I haven't published, yet. Thanks, and sorry for wasting your time!

#14 lore raw

PATCH 5/11 tests/migration: Tighten error checking

In reply to Markus Armbruster

migrate_get_socket_address() neglects to check visit_type_SocketAddressList() failure. This smells like a leak, but it actually will crash dereferencing @addrs. Pass &error_abort to remove the code smell.

---
 tests/qtest/migration-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/qtest/migration-test.c +2 -2
index 2568c9529c..dc3490c9fa 100644
@@ -13,6 +13,7 @@
 #include "qemu/osdep.h"
 
 #include "libqtest.h"
+#include "qapi/error.h"
 #include "qapi/qmp/qdict.h"
 #include "qemu/module.h"
 #include "qemu/option.h"
@@ -301,7 +302,6 @@ static char *migrate_get_socket_address(QTestState *who, const char *parameter)
 {
     QDict *rsp;
     char *result;
-    Error *local_err = NULL;
     SocketAddressList *addrs;
     Visitor *iv = NULL;
     QObject *object;
@@ -310,7 +310,7 @@ static char *migrate_get_socket_address(QTestState *who, const char *parameter)
     object = qdict_get(rsp, parameter);
 
     iv = qobject_input_visitor_new(object);
-    visit_type_SocketAddressList(iv, NULL, &addrs, &local_err);
+    visit_type_SocketAddressList(iv, NULL, &addrs, &error_abort);
     visit_free(iv);
 
     /* we are only using a single address */
Signature · 1 line
2.21.1
#15 lore raw

PATCH 6/11 error: Use error_reportf_err() where appropriate

In reply to Markus Armbruster

Replace

    error_report("...: %s", ..., error_get_pretty(err));

by

    error_reportf_err(err, "...: ", ...);
---
 chardev/char-socket.c | 5 +++--
 hw/sd/pxa2xx_mmci.c   | 4 ++--
 hw/sd/sd.c            | 4 ++--
 hw/usb/dev-mtp.c      | 9 +++++----
 qemu-nbd.c            | 7 +++----
 scsi/qemu-pr-helper.c | 4 ++--
 6 files changed, 17 insertions(+), 16 deletions(-)
chardev/char-socket.c +3 -2
index 185fe38dda..e5ee685f8c 100644
@@ -138,8 +138,9 @@ static void check_report_connect_error(Chardev *chr,
     SocketChardev *s = SOCKET_CHARDEV(chr);
 
     if (!s->connect_err_reported) {
-        error_report("Unable to connect character device %s: %s",
-                     chr->label, error_get_pretty(err));
+        error_reportf_err(err,
+                          "Unable to connect character device %s: ",
+                          chr->label);
         s->connect_err_reported = true;
     }
     qemu_chr_socket_restart_timer(chr);
hw/sd/pxa2xx_mmci.c +2 -2
index 8f9ab0ec16..f9c50ddda5 100644
@@ -497,12 +497,12 @@ PXA2xxMMCIState *pxa2xx_mmci_init(MemoryRegion *sysmem,
     carddev = qdev_create(qdev_get_child_bus(dev, "sd-bus"), TYPE_SD_CARD);
     qdev_prop_set_drive(carddev, "drive", blk, &err);
     if (err) {
-        error_report("failed to init SD card: %s", error_get_pretty(err));
+        error_reportf_err(err, "failed to init SD card: ");
         return NULL;
     }
     object_property_set_bool(OBJECT(carddev), true, "realized", &err);
     if (err) {
-        error_report("failed to init SD card: %s", error_get_pretty(err));
+        error_reportf_err(err, "failed to init SD card: ");
         return NULL;
     }
 
hw/sd/sd.c +2 -2
index 71a9af09ab..3c06a0ac6d 100644
@@ -703,13 +703,13 @@ SDState *sd_init(BlockBackend *blk, bool is_spi)
     dev = DEVICE(obj);
     qdev_prop_set_drive(dev, "drive", blk, &err);
     if (err) {
-        error_report("sd_init failed: %s", error_get_pretty(err));
+        error_reportf_err(err, "sd_init failed: ");
         return NULL;
     }
     qdev_prop_set_bit(dev, "spi", is_spi);
     object_property_set_bool(obj, true, "realized", &err);
     if (err) {
-        error_report("sd_init failed: %s", error_get_pretty(err));
+        error_reportf_err(err, "sd_init failed: ");
         return NULL;
     }
 
hw/usb/dev-mtp.c +5 -4
index 20717f026b..168428156b 100644
@@ -631,8 +631,9 @@ static void usb_mtp_object_readdir(MTPState *s, MTPObject *o)
         int64_t id = qemu_file_monitor_add_watch(s->file_monitor, o->path, NULL,
                                                  file_monitor_event, s, &err);
         if (id == -1) {
-            error_report("usb-mtp: failed to add watch for %s: %s", o->path,
-                         error_get_pretty(err));
+            error_reportf_err(err,
+                              "usb-mtp: failed to add watch for %s: ",
+                              o->path);
             error_free(err);
         } else {
             trace_usb_mtp_file_monitor_event(s->dev.addr, o->path,
@@ -1276,8 +1277,8 @@ static void usb_mtp_command(MTPState *s, MTPControl *c)
 
         s->file_monitor = qemu_file_monitor_new(&err);
         if (err) {
-            error_report("usb-mtp: file monitoring init failed: %s",
-                         error_get_pretty(err));
+            error_reportf_err(err,
+                              "usb-mtp: file monitoring init failed: ");
             error_free(err);
         } else {
             QTAILQ_INIT(&s->events);
qemu-nbd.c +3 -4
index 4aa005004e..30deb5d9e6 100644
@@ -856,8 +856,7 @@ int main(int argc, char **argv)
         }
         tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
         if (local_err) {
-            error_report("Failed to get TLS creds %s",
-                         error_get_pretty(local_err));
+            error_reportf_err(local_err, "Failed to get TLS creds ");
             exit(EXIT_FAILURE);
         }
     } else {
@@ -979,8 +978,8 @@ int main(int argc, char **argv)
                                              &local_err);
             if (sioc == NULL) {
                 object_unref(OBJECT(server));
-                error_report("Failed to use socket activation: %s",
-                             error_get_pretty(local_err));
+                error_reportf_err(local_err,
+                                  "Failed to use socket activation: ");
                 exit(EXIT_FAILURE);
             }
             qio_net_listener_add(server, sioc);
scsi/qemu-pr-helper.c +2 -2
index 181ed4a186..57ad830d54 100644
@@ -1030,8 +1030,8 @@ int main(int argc, char **argv)
         server_ioc = qio_channel_socket_new_fd(FIRST_SOCKET_ACTIVATION_FD,
                                                &local_err);
         if (server_ioc == NULL) {
-            error_report("Failed to use socket activation: %s",
-                         error_get_pretty(local_err));
+            error_reportf_err(local_err,
+                              "Failed to use socket activation: ");
             exit(EXIT_FAILURE);
         }
     }
Signature · 1 line
2.21.1
Reviewed-by on v1 6/11
#16 lore raw

Re: [PATCH 06/11] error: Use error_reportf_err() where appropriate

Quoted 7 lines · Markus Armbruster

Replace

     error_report("...: %s", ..., error_get_pretty(err));

by

     error_reportf_err(err, "...: ", ...);
Quoted 10 lines
---
  chardev/char-socket.c | 5 +++--
  hw/sd/pxa2xx_mmci.c   | 4 ++--
  hw/sd/sd.c            | 4 ++--
  hw/usb/dev-mtp.c      | 9 +++++----
  qemu-nbd.c            | 7 +++----
  scsi/qemu-pr-helper.c | 4 ++--
  6 files changed, 17 insertions(+), 16 deletions(-)

Although it touches NBD, I'm happy for this to go through your tree with the larger series.

qemu-nbd.c int main(int argc, char **argv) · line 859

Quoted 8 lines

+++ b/qemu-nbd.c

qemu-nbd.c +1 -2
@@ -856,8 +856,7 @@ int main(int argc, char **argv)
          }
          tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
          if (local_err) {
-            error_report("Failed to get TLS creds %s",
-                         error_get_pretty(local_err));
+            error_reportf_err(local_err, "Failed to get TLS creds ");

Odd one out for not using ':' in the message, but that's independent of this patch.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#17 lore raw

Re: [PATCH 06/11] error: Use error_reportf_err() where appropriate

Quoted 25 lines · Eric Blake
Quoted 7 lines · Markus Armbruster

Replace

     error_report("...: %s", ..., error_get_pretty(err));

by

     error_reportf_err(err, "...: ", ...);
Quoted 10 lines
---
  chardev/char-socket.c | 5 +++--
  hw/sd/pxa2xx_mmci.c   | 4 ++--
  hw/sd/sd.c            | 4 ++--
  hw/usb/dev-mtp.c      | 9 +++++----
  qemu-nbd.c            | 7 +++----
  scsi/qemu-pr-helper.c | 4 ++--
  6 files changed, 17 insertions(+), 16 deletions(-)

Although it touches NBD, I'm happy for this to go through your tree with the larger series.

Quoted 11 lines

qemu-nbd.c int main(int argc, char **argv) · line 859

Quoted 8 lines

+++ b/qemu-nbd.c

qemu-nbd.c +1 -2
@@ -856,8 +856,7 @@ int main(int argc, char **argv)
          }
          tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
          if (local_err) {
-            error_report("Failed to get TLS creds %s",
-                         error_get_pretty(local_err));
+            error_reportf_err(local_err, "Failed to get TLS creds ");

Odd one out for not using ':' in the message, but that's independent of this patch.

The patch is short enough to deviate from "purely mechanical" and stick in ':' here. Your choice.

Thanks!

#18 lore raw

Re: [PATCH 06/11] error: Use error_reportf_err() where appropriate

Quoted 39 lines · Markus Armbruster
Quoted 25 lines · Eric Blake
Quoted 7 lines · Markus Armbruster

Replace

      error_report("...: %s", ..., error_get_pretty(err));

by

      error_reportf_err(err, "...: ", ...);
Quoted 10 lines
---
   chardev/char-socket.c | 5 +++--
   hw/sd/pxa2xx_mmci.c   | 4 ++--
   hw/sd/sd.c            | 4 ++--
   hw/usb/dev-mtp.c      | 9 +++++----
   qemu-nbd.c            | 7 +++----
   scsi/qemu-pr-helper.c | 4 ++--
   6 files changed, 17 insertions(+), 16 deletions(-)

Although it touches NBD, I'm happy for this to go through your tree with the larger series.

Quoted 11 lines

qemu-nbd.c int main(int argc, char **argv) · line 859

Quoted 8 lines

+++ b/qemu-nbd.c

qemu-nbd.c +1 -2
@@ -856,8 +856,7 @@ int main(int argc, char **argv)
           }
           tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
           if (local_err) {
-            error_report("Failed to get TLS creds %s",
-                         error_get_pretty(local_err));
+            error_reportf_err(local_err, "Failed to get TLS creds ");

Odd one out for not using ':' in the message, but that's independent of this patch.

Quoted 2 lines

The patch is short enough to deviate from "purely mechanical" and stick in ':' here. Your choice.

Let's deviate, else we might forget about it.

#19 lore raw

Re: [PATCH 06/11] error: Use error_reportf_err() where appropriate

In reply to Markus Armbruster
Quoted 18 lines · Markus Armbruster
Quoted 14 lines · Eric Blake

Although it touches NBD, I'm happy for this to go through your tree with the larger series.

qemu-nbd.c int main(int argc, char **argv) · line 859

Quoted 8 lines

+++ b/qemu-nbd.c

qemu-nbd.c +1 -2
@@ -856,8 +856,7 @@ int main(int argc, char **argv)
           }
           tlscreds = nbd_get_tls_creds(tlscredsid, list, &local_err);
           if (local_err) {
-            error_report("Failed to get TLS creds %s",
-                         error_get_pretty(local_err));
+            error_reportf_err(local_err, "Failed to get TLS creds ");

Odd one out for not using ':' in the message, but that's independent of this patch.

Quoted 2 lines

The patch is short enough to deviate from "purely mechanical" and stick in ':' here. Your choice.

Adding it in now is fine by me.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#20 lore raw

PATCH 7/11 mips/malta: Fix create_cps() error handling

In reply to Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second

create_cps() is wrong that way. The last calls treats an error as fatal. Do that for the prior ones, too.

Fixes bff384a4fbd5d0e86939092e74e766ef0f5f592c
Cc Aleksandar Markovic <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>
Cc Aurelien Jarno <[email protected]>
---
 hw/mips/mips_malta.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
hw/mips/mips_malta.c +6 -9
index e4c4de1b4e..17bf41616b 100644
@@ -1185,17 +1185,14 @@ static void create_cpu_without_cps(MachineState *ms,
 static void create_cps(MachineState *ms, MaltaState *s,
                        qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
-    Error *err = NULL;
-
     sysbus_init_child_obj(OBJECT(s), "cps", OBJECT(&s->cps), sizeof(s->cps),
                           TYPE_MIPS_CPS);
-    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type", &err);
-    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp", &err);
-    object_property_set_bool(OBJECT(&s->cps), true, "realized", &err);
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));
-        exit(1);
-    }
+    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type",
+                            &error_fatal);
+    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp",
+                            &error_fatal);
+    object_property_set_bool(OBJECT(&s->cps), true, "realized",
+                             &error_fatal);
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
Signature · 1 line
2.21.1
#21 lore raw

Re: [PATCH 07/11] mips/malta: Fix create_cps() error handling

Quoted 24 lines · Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second

create_cps() is wrong that way. The last calls treats an error as fatal. Do that for the prior ones, too.

Fixes bff384a4fbd5d0e86939092e74e766ef0f5f592c
Cc Aleksandar Markovic <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>
Cc Aurelien Jarno <[email protected]>
---
 hw/mips/mips_malta.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
hw/mips/mips_malta.c +0 -0
index e4c4de1b4e..17bf41616b 100644
@@ -1185,17 +1185,14 @@ static void create_cpu_without_cps(MachineState *ms,
 static void create_cps(MachineState *ms, MaltaState *s,
                        qemu_irq *cbus_irq, qemu_irq *i8259_irq)

hw/mips/mips_malta.c static void create_cpu_without_cps(MachineState *ms, · line 1196

Quoted 10 lines
hw/mips/mips_malta.c +0 -7
 {
-    Error *err = NULL;
-
     sysbus_init_child_obj(OBJECT(s), "cps", OBJECT(&s->cps), sizeof(s->cps),
                           TYPE_MIPS_CPS);
-    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type", &err);
-    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp", &err);
-    object_property_set_bool(OBJECT(&s->cps), true, "realized", &err);
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));

In https://www.mail-archive.com/[email protected]/msg695645.html I also remove "qemu/error-report.h" which is not needed once you remove this call.

Quoted 12 lines
hw/mips/mips_malta.c +6 -2
-        exit(1);
-    }
+    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type",
+                            &error_fatal);
+    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp",
+                            &error_fatal);
+    object_property_set_bool(OBJECT(&s->cps), true, "realized",
+                             &error_fatal);
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
#22 lore raw

Re: [PATCH 07/11] mips/malta: Fix create_cps() error handling

Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second

create_cps() is wrong that way. The last calls treats an error as fatal. Do that for the prior ones, too.

Fixes bff384a4fbd5d0e86939092e74e766ef0f5f592c
Cc Aleksandar Markovic <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>
Cc Aurelien Jarno <[email protected]>
---
 hw/mips/mips_malta.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
hw/mips/mips_malta.c +0 -3
index e4c4de1b4e..17bf41616b 100644
@@ -1185,17 +1185,14 @@ static void create_cpu_without_cps(MachineState *ms,
 static void create_cps(MachineState *ms, MaltaState *s,
                        qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
-    Error *err = NULL;
-
     sysbus_init_child_obj(OBJECT(s), "cps", OBJECT(&s->cps), sizeof(s->cps),
                           TYPE_MIPS_CPS);
-    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type", &err);
Quoted 8 lines

hw/mips/mips_malta.c static void create_cpu_without_cps(MachineState *ms, · line 1196

Quoted 4 lines
hw/mips/mips_malta.c +0 -4
-    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp", &err);
-    object_property_set_bool(OBJECT(&s->cps), true, "realized", &err);
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));

In https://www.mail-archive.com/[email protected]/msg695645.html I also remove "qemu/error-report.h" which is not needed once you remove this call.

Missed it, sorry. I only reviewed the Coccinelle scripts [PATCH 1+3/7].

I'd replace my patch by yours to give you proper credit, but your commit message mentions "the coccinelle script", presumably the one from PATCH 1/7, and that patch isn't quite ready in my opinion.

Quoted 12 lines
Quoted 12 lines
hw/mips/mips_malta.c +6 -2
-        exit(1);
-    }
+    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type",
+                            &error_fatal);
+    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp",
+                            &error_fatal);
+    object_property_set_bool(OBJECT(&s->cps), true, "realized",
+                             &error_fatal);
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
Reviewed-by Tested-by
#23 lore raw

Re: [PATCH 07/11] mips/malta: Fix create_cps() error handling

+Peter for crediting his advice.

Quoted 42 lines · Markus Armbruster
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second

create_cps() is wrong that way. The last calls treats an error as fatal. Do that for the prior ones, too.

Fixes bff384a4fbd5d0e86939092e74e766ef0f5f592c
Cc Aleksandar Markovic <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>
Cc Aurelien Jarno <[email protected]>
---
  hw/mips/mips_malta.c | 15 ++++++---------
  1 file changed, 6 insertions(+), 9 deletions(-)
hw/mips/mips_malta.c +0 -3
index e4c4de1b4e..17bf41616b 100644
@@ -1185,17 +1185,14 @@ static void create_cpu_without_cps(MachineState *ms,
  static void create_cps(MachineState *ms, MaltaState *s,
                         qemu_irq *cbus_irq, qemu_irq *i8259_irq)
  {
-    Error *err = NULL;
-
      sysbus_init_child_obj(OBJECT(s), "cps", OBJECT(&s->cps), sizeof(s->cps),
                            TYPE_MIPS_CPS);
-    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type", &err);
Quoted 8 lines

hw/mips/mips_malta.c static void create_cpu_without_cps(MachineState *ms, · line 1196

Quoted 4 lines
hw/mips/mips_malta.c +0 -4
-    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp", &err);
-    object_property_set_bool(OBJECT(&s->cps), true, "realized", &err);
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));

In https://www.mail-archive.com/[email protected]/msg695645.html I also remove "qemu/error-report.h" which is not needed once you remove this call.

Quoted 1 line

Missed it, sorry. I only reviewed the Coccinelle scripts [PATCH 1+3/7].

My bad for not Cc'ing you on the whole series, which is Error related, and use the default get_maintainer.pl selection.

Quoted 3 lines

I'd replace my patch by yours to give you proper credit, but your commit message mentions "the coccinelle script", presumably the one from PATCH 1/7, and that patch isn't quite ready in my opinion.

I'm not worried about credit, but duplicating effort or wasting time.

Peter once warned the problem with Coccinelle scripts is finding the correct balance between time spent to improve QEMU codebase, and time spent learning Coccinelle and improving a script that is often used only once in a lifetime.
If the script is not provided, we ask for the script. If the script is embedded in various patch descriptions, we ask to add it independently for reuse or as example. Then the script must be almost perfect. Meanwhile all the following patches referencing it, while reviewed, are stuck.

Anyway back to your patch:

Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
hw/mips/mips_malta.c +6 -2
-        exit(1);
-    }
+    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type",
+                            &error_fatal);
+    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp",
+                            &error_fatal);
+    object_property_set_bool(OBJECT(&s->cps), true, "realized",
+                             &error_fatal);
 
      sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
#24 lore raw

Re: [PATCH 07/11] mips/malta: Fix create_cps() error handling

Quoted 56 lines · Philippe Mathieu-Daudé

+Peter for crediting his advice.

Quoted 42 lines · Markus Armbruster
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 30 lines · Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second

create_cps() is wrong that way. The last calls treats an error as fatal. Do that for the prior ones, too.

Fixes bff384a4fbd5d0e86939092e74e766ef0f5f592c
Cc Aleksandar Markovic <[email protected]>
Cc "Philippe Mathieu-Daudé" <[email protected]>
Cc Aurelien Jarno <[email protected]>
---
  hw/mips/mips_malta.c | 15 ++++++---------
  1 file changed, 6 insertions(+), 9 deletions(-)
hw/mips/mips_malta.c +0 -3
index e4c4de1b4e..17bf41616b 100644
@@ -1185,17 +1185,14 @@ static void create_cpu_without_cps(MachineState *ms,
  static void create_cps(MachineState *ms, MaltaState *s,
                         qemu_irq *cbus_irq, qemu_irq *i8259_irq)
  {
-    Error *err = NULL;
-
      sysbus_init_child_obj(OBJECT(s), "cps", OBJECT(&s->cps), sizeof(s->cps),
                            TYPE_MIPS_CPS);
-    object_property_set_str(OBJECT(&s->cps), ms->cpu_type, "cpu-type", &err);
Quoted 8 lines

hw/mips/mips_malta.c static void create_cpu_without_cps(MachineState *ms, · line 1196

Quoted 4 lines
hw/mips/mips_malta.c +0 -4
-    object_property_set_int(OBJECT(&s->cps), ms->smp.cpus, "num-vp", &err);
-    object_property_set_bool(OBJECT(&s->cps), true, "realized", &err);
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));

In https://www.mail-archive.com/[email protected]/msg695645.html I also remove "qemu/error-report.h" which is not needed once you remove this call.

Quoted 1 line

Missed it, sorry. I only reviewed the Coccinelle scripts [PATCH 1+3/7].

My bad for not Cc'ing you on the whole series, which is Error related, and use the default get_maintainer.pl selection.

Quoted 3 lines

I'd replace my patch by yours to give you proper credit, but your commit message mentions "the coccinelle script", presumably the one from PATCH 1/7, and that patch isn't quite ready in my opinion.

I'm not worried about credit, but duplicating effort or wasting time.

Quoted 9 lines

Peter once warned the problem with Coccinelle scripts is finding the correct balance between time spent to improve QEMU codebase, and time spent learning Coccinelle and improving a script that is often used only once in a lifetime.
If the script is not provided, we ask for the script. If the script is embedded in various patch descriptions, we ask to add it independently for reuse or as example. Then the script must be almost perfect. Meanwhile all the following patches referencing it, while reviewed, are stuck.

True. I try not to ask for undue perfection, but perfection eludes me in that, too :)

For PATCH 1/7, I only asked you to explain the script's limitations in the script and the commit message. Her's a bit of inspiration from the kernel's scripts/coccinelle/misc/doubleinit.cocci (picked almost at random):

    /// Find duplicate field initializations.  This has a high rate of false
    /// positives due to #ifdefs, which Coccinelle is not aware of in a structure
    /// initialization.
    ///
    // Confidence: Low

I like the Confidence: tag. It should come with an explanation, as it does here.

For PATCH 3/7, I had a question.

Quoted 3 lines

Anyway back to your patch:

Thanks!

#25 lore raw

PATCH 8/11 mips/boston: Fix boston_mach_init() error handling

In reply to Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second

boston_mach_init() is wrong that way. The last calls treats an error as fatal. Do that for the prior ones, too.

Fixes df1d8a1f29f567567b9d20be685a4241282e7005
Cc Paul Burton <[email protected]>
Cc Aleksandar Rikalo <[email protected]>
---
 hw/mips/boston.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
hw/mips/boston.c +5 -8
index 98ecd25e8e..2832dfa6ae 100644
@@ -458,14 +458,11 @@ static void boston_mach_init(MachineState *machine)
     sysbus_init_child_obj(OBJECT(machine), "cps", OBJECT(&s->cps),
                           sizeof(s->cps), TYPE_MIPS_CPS);
     object_property_set_str(OBJECT(&s->cps), machine->cpu_type, "cpu-type",
-                            &err);
-    object_property_set_int(OBJECT(&s->cps), machine->smp.cpus, "num-vp", &err);
-    object_property_set_bool(OBJECT(&s->cps), true, "realized", &err);
-
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));
-        exit(1);
-    }
+                            &error_fatal);
+    object_property_set_int(OBJECT(&s->cps), machine->smp.cpus, "num-vp",
+                            &error_fatal);
+    object_property_set_bool(OBJECT(&s->cps), true, "realized",
+                             &error_fatal);
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
Signature · 1 line
2.21.1
#26 lore raw

Re: [PATCH 08/11] mips/boston: Fix boston_mach_init() error handling

Quoted 4 lines · Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second

call.

Whoops!

Quoted 35 lines

boston_mach_init() is wrong that way. The last calls treats an error as fatal. Do that for the prior ones, too.

Fixes df1d8a1f29f567567b9d20be685a4241282e7005
Cc Paul Burton <[email protected]>
Cc Aleksandar Rikalo <[email protected]>
---
 hw/mips/boston.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
hw/mips/boston.c +5 -8
index 98ecd25e8e..2832dfa6ae 100644
@@ -458,14 +458,11 @@ static void boston_mach_init(MachineState *machine)
     sysbus_init_child_obj(OBJECT(machine), "cps", OBJECT(&s->cps),
                           sizeof(s->cps), TYPE_MIPS_CPS);
     object_property_set_str(OBJECT(&s->cps), machine->cpu_type, "cpu-type",
-                            &err);
-    object_property_set_int(OBJECT(&s->cps), machine->smp.cpus, "num-vp", &err);
-    object_property_set_bool(OBJECT(&s->cps), true, "realized", &err);
-
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));
-        exit(1);
-    }
+                            &error_fatal);
+    object_property_set_int(OBJECT(&s->cps), machine->smp.cpus, "num-vp",
+                            &error_fatal);
+    object_property_set_bool(OBJECT(&s->cps), true, "realized",
+                             &error_fatal);
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
#27 lore raw

PATCH 9/11 mips/boston: Plug memory leak in boston_mach_init()

In reply to Markus Armbruster
Fixes df1d8a1f29f567567b9d20be685a4241282e7005
Cc Paul Burton <[email protected]>
Cc Aleksandar Rikalo <[email protected]>
---
 hw/mips/boston.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/mips/boston.c +2 -2
index 2832dfa6ae..a896056be1 100644
@@ -426,7 +426,6 @@ static void boston_mach_init(MachineState *machine)
 {
     DeviceState *dev;
     BostonState *s;
-    Error *err = NULL;
     MemoryRegion *flash, *ddr_low_alias, *lcd, *platreg;
     MemoryRegion *sys_mem = get_system_memory();
     XilinxPCIEHost *pcie2;
@@ -467,7 +466,8 @@ static void boston_mach_init(MachineState *machine)
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->cps), 0, 0, 1);
 
     flash =  g_new(MemoryRegion, 1);
-    memory_region_init_rom(flash, NULL, "boston.flash", 128 * MiB, &err);
+    memory_region_init_rom(flash, NULL, "boston.flash", 128 * MiB,
+                           &error_fatal);
     memory_region_add_subregion_overlap(sys_mem, 0x18000000, flash, 0);
 
     memory_region_add_subregion_overlap(sys_mem, 0x80000000, machine->ram, 0);
Signature · 1 line
2.21.1
#28 lore raw

PATCH 10/11 arm/sabrelite: Consistently use &error_fatal in sabrelite_init()

In reply to Markus Armbruster
Cc Peter Maydell <[email protected]>
Cc Jean-Christophe Dubois <[email protected]>
---
 hw/arm/sabrelite.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
hw/arm/sabrelite.c +1 -6
index e31694bb92..04f4b96591 100644
@@ -41,7 +41,6 @@ static void sabrelite_reset_secondary(ARMCPU *cpu,
 static void sabrelite_init(MachineState *machine)
 {
     FslIMX6State *s;
-    Error *err = NULL;
 
     /* Check the amount of memory is compatible with the SOC */
     if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
@@ -52,11 +51,7 @@ static void sabrelite_init(MachineState *machine)
 
     s = FSL_IMX6(object_new(TYPE_FSL_IMX6));
     object_property_add_child(OBJECT(machine), "soc", OBJECT(s), &error_fatal);
-    object_property_set_bool(OBJECT(s), true, "realized", &err);
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));
-        exit(1);
-    }
+    object_property_set_bool(OBJECT(s), true, "realized", &error_fatal);
 
     memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
                                 machine->ram);
Signature · 1 line
2.21.1
Reviewed-by on v1 10/11
#29 lore raw

Re: [PATCH 10/11] arm/sabrelite: Consistently use &error_fatal in sabrelite_init()

Quoted 23 lines · Markus Armbruster
Cc Peter Maydell <[email protected]>
Cc Jean-Christophe Dubois <[email protected]>
---
 hw/arm/sabrelite.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)
hw/arm/sabrelite.c +0 -1
index e31694bb92..04f4b96591 100644
@@ -41,7 +41,6 @@ static void sabrelite_reset_secondary(ARMCPU *cpu,
 static void sabrelite_init(MachineState *machine)
 {
     FslIMX6State *s;
-    Error *err = NULL;
 
     /* Check the amount of memory is compatible with the SOC */
     if (machine->ram_size > FSL_IMX6_MMDC_SIZE) {
@@ -52,11 +51,7 @@ static void sabrelite_init(MachineState *machine)
 
     s = FSL_IMX6(object_new(TYPE_FSL_IMX6));

hw/arm/sabrelite.c static void sabrelite_init(MachineState *machine) · line 57

Quoted 10 lines
hw/arm/sabrelite.c +1 -5
     object_property_add_child(OBJECT(machine), "soc", OBJECT(s), &error_fatal);
-    object_property_set_bool(OBJECT(s), true, "realized", &err);
-    if (err != NULL) {
-        error_report("%s", error_get_pretty(err));
-        exit(1);
-    }
+    object_property_set_bool(OBJECT(s), true, "realized", &error_fatal);
 
     memory_region_add_subregion(get_system_memory(), FSL_IMX6_MMDC_ADDR,
                                 machine->ram);
#30 lore raw

PATCH 11/11 i386: Fix x86_cpu_load_model() error API violation

In reply to Markus Armbruster

The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second call.

x86_cpu_load_model() is wrong that way. Harmless, because its @errp is always &error_abort. To fix, cut out the @errp middleman.

Cc Paolo Bonzini <[email protected]>
Cc Richard Henderson <[email protected]>
Cc Eduardo Habkost <[email protected]>
---
 target/i386/cpu.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
target/i386/cpu.c +16 -9
index 90ffc5f3b1..3f09fd2321 100644
@@ -5078,7 +5078,7 @@ static void x86_cpu_apply_version_props(X86CPU *cpu, X86CPUModel *model)
 
 /* Load data from X86CPUDefinition into a X86CPU object
  */
-static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model, Error **errp)
+static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model)
 {
     X86CPUDefinition *def = model->cpudef;
     CPUX86State *env = &cpu->env;
@@ -5092,13 +5092,19 @@ static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model, Error **errp)
      */
 
     /* CPU models only set _minimum_ values for level/xlevel: */
-    object_property_set_uint(OBJECT(cpu), def->level, "min-level", errp);
-    object_property_set_uint(OBJECT(cpu), def->xlevel, "min-xlevel", errp);
+    object_property_set_uint(OBJECT(cpu), def->level, "min-level",
+                             &error_abort);
+    object_property_set_uint(OBJECT(cpu), def->xlevel, "min-xlevel",
+                             &error_abort);
 
-    object_property_set_int(OBJECT(cpu), def->family, "family", errp);
-    object_property_set_int(OBJECT(cpu), def->model, "model", errp);
-    object_property_set_int(OBJECT(cpu), def->stepping, "stepping", errp);
-    object_property_set_str(OBJECT(cpu), def->model_id, "model-id", errp);
+    object_property_set_int(OBJECT(cpu), def->family, "family",
+                            &error_abort);
+    object_property_set_int(OBJECT(cpu), def->model, "model",
+                            &error_abort);
+    object_property_set_int(OBJECT(cpu), def->stepping, "stepping",
+                            &error_abort);
+    object_property_set_str(OBJECT(cpu), def->model_id, "model-id",
+                            &error_abort);
     for (w = 0; w < FEATURE_WORDS; w++) {
         env->features[w] = def->features[w];
     }
@@ -5135,7 +5141,8 @@ static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model, Error **errp)
         vendor = host_vendor;
     }
 
-    object_property_set_str(OBJECT(cpu), vendor, "vendor", errp);
+    object_property_set_str(OBJECT(cpu), vendor, "vendor",
+                            &error_abort);
 
     x86_cpu_apply_version_props(cpu, model);
 }
@@ -6981,7 +6988,7 @@ static void x86_cpu_initfn(Object *obj)
     object_property_add_alias(obj, "sse4_2", obj, "sse4.2", &error_abort);
 
     if (xcc->model) {
-        x86_cpu_load_model(cpu, xcc->model, &error_abort);
+        x86_cpu_load_model(cpu, xcc->model);
     }
 }
 
Signature · 1 line
2.21.1