diff mbox series

[02/20] qdev: Stop using error_set_from_qdev_prop_error() for netdev property

Message ID 20201030202131.796967-3-ehabkost@redhat.com
State New
Headers show
Series qdev/qom: Remove explicit type names from error_setg() calls | expand

Commit Message

Eduardo Habkost Oct. 30, 2020, 8:21 p.m. UTC
Just setting a reasonable error string using error_setg() is
simpler and makes error messages clearer.

Before:

  $ qemu-system-x86_64 -device e1000,netdev=n0
  qemu-system-x86_64: -device e1000,netdev=n0: Property 'e1000.netdev' can't find value 'n0'
  $ qemu-system-x86_64 -netdev id=n0,type=user -device e1000,netdev=n0 -device e1000,netdev=n0
  qemu-system-x86_64: -device e1000,netdev=n0: Property 'e1000.netdev' can't take value 'n0', it's in use

After:

  $ ./qemu-system-x86_64 -device e1000,netdev=n0
  qemu-system-x86_64: -device e1000,netdev=n0: Property 'e1000.netdev' can't take value 'n0': netdev not found
  $ ./qemu-system-x86_64 -netdev id=n0,type=user -device e1000,netdev=n0 -device e1000,netdev=n0
  qemu-system-x86_64: -device e1000,netdev=n0: Property 'e1000.netdev' can't take value 'n0': netdev is in use

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 hw/core/qdev-properties-system.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 232ff955fa..60be09efba 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -376,7 +376,7 @@  static void set_netdev(Object *obj, Visitor *v, const char *name,
     NICPeers *peers_ptr = object_static_prop_ptr(obj, prop);
     NetClientState **ncs = peers_ptr->ncs;
     NetClientState *peers[MAX_QUEUE_NUM];
-    int queues, err = 0, i = 0;
+    int queues, i = 0;
     char *str;
 
     if (!visit_type_str(v, name, &str, errp)) {
@@ -387,7 +387,7 @@  static void set_netdev(Object *obj, Visitor *v, const char *name,
                                           NET_CLIENT_DRIVER_NIC,
                                           MAX_QUEUE_NUM);
     if (queues == 0) {
-        err = -ENOENT;
+        error_setg(errp, "netdev not found");
         goto out;
     }
 
@@ -399,7 +399,7 @@  static void set_netdev(Object *obj, Visitor *v, const char *name,
 
     for (i = 0; i < queues; i++) {
         if (peers[i]->peer) {
-            err = -EEXIST;
+            error_setg(errp, "netdev is in use");
             goto out;
         }
 
@@ -418,7 +418,6 @@  static void set_netdev(Object *obj, Visitor *v, const char *name,
     peers_ptr->queues = queues;
 
 out:
-    error_set_from_qdev_prop_error(errp, err, obj, prop, str);
     g_free(str);
 }