qdev: Make error_set_from_qdev_prop_error() get Object* argument

Make the code more generic and not specific to TYPE_DEVICE.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com> #s390 parts
Message-Id: <20201211220529.2290218-13-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
Eduardo Habkost 2020-12-11 17:05:09 -05:00
parent 381481597c
commit c7525b183c
4 changed files with 12 additions and 12 deletions

View File

@ -352,7 +352,7 @@ static void set_mac(Object *obj, Visitor *v, const char *name, void *opaque,
return; return;
inval: inval:
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
g_free(str); g_free(str);
} }
@ -440,7 +440,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
peers_ptr->queues = queues; peers_ptr->queues = queues;
out: out:
error_set_from_qdev_prop_error(errp, err, dev, prop, str); error_set_from_qdev_prop_error(errp, err, obj, prop, str);
g_free(str); g_free(str);
} }
@ -492,7 +492,7 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
card->state = state; card->state = state;
out: out:
error_set_from_qdev_prop_error(errp, err, dev, prop, str); error_set_from_qdev_prop_error(errp, err, obj, prop, str);
g_free(str); g_free(str);
} }
@ -790,7 +790,7 @@ static void set_pci_devfn(Object *obj, Visitor *v, const char *name,
return; return;
invalid: invalid:
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
g_free(str); g_free(str);
} }
@ -914,7 +914,7 @@ static void set_pci_host_devaddr(Object *obj, Visitor *v, const char *name,
return; return;
inval: inval:
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
g_free(str); g_free(str);
} }

View File

@ -581,7 +581,7 @@ static void set_uuid(Object *obj, Visitor *v, const char *name, void *opaque,
if (!strcmp(str, UUID_VALUE_AUTO)) { if (!strcmp(str, UUID_VALUE_AUTO)) {
qemu_uuid_generate(uuid); qemu_uuid_generate(uuid);
} else if (qemu_uuid_parse(str, uuid) < 0) { } else if (qemu_uuid_parse(str, uuid) < 0) {
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
} }
g_free(str); g_free(str);
} }
@ -735,22 +735,22 @@ static Property *qdev_prop_find(DeviceState *dev, const char *name)
return NULL; return NULL;
} }
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
Property *prop, const char *value) Property *prop, const char *value)
{ {
switch (ret) { switch (ret) {
case -EEXIST: case -EEXIST:
error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use", error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use",
object_get_typename(OBJECT(dev)), prop->name, value); object_get_typename(obj), prop->name, value);
break; break;
default: default:
case -EINVAL: case -EINVAL:
error_setg(errp, QERR_PROPERTY_VALUE_BAD, error_setg(errp, QERR_PROPERTY_VALUE_BAD,
object_get_typename(OBJECT(dev)), prop->name, value); object_get_typename(obj), prop->name, value);
break; break;
case -ENOENT: case -ENOENT:
error_setg(errp, "Property '%s.%s' can't find value '%s'", error_setg(errp, "Property '%s.%s' can't find value '%s'",
object_get_typename(OBJECT(dev)), prop->name, value); object_get_typename(obj), prop->name, value);
break; break;
case 0: case 0:
break; break;

View File

@ -2390,7 +2390,7 @@ static void set_css_devid(Object *obj, Visitor *v, const char *name,
num = sscanf(str, "%2x.%1x%n.%4x%n", &cssid, &ssid, &n1, &devid, &n2); num = sscanf(str, "%2x.%1x%n.%4x%n", &cssid, &ssid, &n1, &devid, &n2);
if (num != 3 || (n2 - n1) != 5 || strlen(str) != n2) { if (num != 3 || (n2 - n1) != 5 || strlen(str) != n2) {
error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); error_set_from_qdev_prop_error(errp, EINVAL, obj, prop, str);
goto out; goto out;
} }
if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) { if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) {

View File

@ -309,7 +309,7 @@ const GlobalProperty *qdev_find_global_prop(Object *obj,
const char *name); const char *name);
int qdev_prop_check_globals(void); int qdev_prop_check_globals(void);
void qdev_prop_set_globals(DeviceState *dev); void qdev_prop_set_globals(DeviceState *dev);
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
Property *prop, const char *value); Property *prop, const char *value);
/** /**