qapi: Use returned bool to check for failure (again)

Commit 012d4c96e2 changed the visitor functions taking Error ** to
return bool instead of void, and the commits following it used the new
return value to simplify error checking.  Since then a few more uses
in need of the same treatment crept in.  Do that.  All pretty
mechanical except for

* balloon_stats_get_all()

  This is basically the same transformation commit 012d4c96e2 applied
  to the virtual walk example in include/qapi/visitor.h.

* set_max_queue_size()

  Additionally replace "goto end of function" by return.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20221121085054.683122-10-armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
Markus Armbruster 2022-11-21 09:50:53 +01:00
parent f560eb1f0a
commit d1c81c3496
8 changed files with 21 additions and 52 deletions

View File

@ -3586,7 +3586,6 @@ static void kvm_set_dirty_ring_size(Object *obj, Visitor *v,
Error **errp) Error **errp)
{ {
KVMState *s = KVM_STATE(obj); KVMState *s = KVM_STATE(obj);
Error *error = NULL;
uint32_t value; uint32_t value;
if (s->fd != -1) { if (s->fd != -1) {
@ -3594,9 +3593,7 @@ static void kvm_set_dirty_ring_size(Object *obj, Visitor *v,
return; return;
} }
visit_type_uint32(v, name, &value, &error); if (!visit_type_uint32(v, name, &value, errp)) {
if (error) {
error_propagate(errp, error);
return; return;
} }
if (value & (value - 1)) { if (value & (value - 1)) {

View File

@ -679,14 +679,11 @@ static void set_reserved_region(Object *obj, Visitor *v, const char *name,
{ {
Property *prop = opaque; Property *prop = opaque;
ReservedRegion *rr = object_field_prop_ptr(obj, prop); ReservedRegion *rr = object_field_prop_ptr(obj, prop);
Error *local_err = NULL;
const char *endptr; const char *endptr;
char *str; char *str;
int ret; int ret;
visit_type_str(v, name, &str, &local_err); if (!visit_type_str(v, name, &str, errp)) {
if (local_err) {
error_propagate(errp, local_err);
return; return;
} }

View File

@ -1782,12 +1782,9 @@ static void pc_machine_set_max_fw_size(Object *obj, Visitor *v,
Error **errp) Error **errp)
{ {
PCMachineState *pcms = PC_MACHINE(obj); PCMachineState *pcms = PC_MACHINE(obj);
Error *error = NULL;
uint64_t value; uint64_t value;
visit_type_size(v, name, &value, &error); if (!visit_type_size(v, name, &value, errp)) {
if (error) {
error_propagate(errp, error);
return; return;
} }

View File

@ -241,36 +241,34 @@ static void balloon_stats_poll_cb(void *opaque)
static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name, static void balloon_stats_get_all(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp) void *opaque, Error **errp)
{ {
Error *err = NULL;
VirtIOBalloon *s = VIRTIO_BALLOON(obj); VirtIOBalloon *s = VIRTIO_BALLOON(obj);
bool ok = false;
int i; int i;
if (!visit_start_struct(v, name, NULL, 0, &err)) { if (!visit_start_struct(v, name, NULL, 0, errp)) {
goto out; return;
} }
if (!visit_type_int(v, "last-update", &s->stats_last_update, &err)) { if (!visit_type_int(v, "last-update", &s->stats_last_update, errp)) {
goto out_end; goto out_end;
} }
if (!visit_start_struct(v, "stats", NULL, 0, &err)) { if (!visit_start_struct(v, "stats", NULL, 0, errp)) {
goto out_end; goto out_end;
} }
for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) { for (i = 0; i < VIRTIO_BALLOON_S_NR; i++) {
if (!visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], &err)) { if (!visit_type_uint64(v, balloon_stat_names[i], &s->stats[i], errp)) {
goto out_nested; goto out_nested;
} }
} }
visit_check_struct(v, &err); ok = visit_check_struct(v, errp);
out_nested: out_nested:
visit_end_struct(v, NULL); visit_end_struct(v, NULL);
if (!err) { if (ok) {
visit_check_struct(v, &err); visit_check_struct(v, errp);
} }
out_end: out_end:
visit_end_struct(v, NULL); visit_end_struct(v, NULL);
out:
error_propagate(errp, err);
} }
static void balloon_stats_get_poll_interval(Object *obj, Visitor *v, static void balloon_stats_get_poll_interval(Object *obj, Visitor *v,

View File

@ -1094,12 +1094,9 @@ static void virtio_mem_set_requested_size(Object *obj, Visitor *v,
Error **errp) Error **errp)
{ {
VirtIOMEM *vmem = VIRTIO_MEM(obj); VirtIOMEM *vmem = VIRTIO_MEM(obj);
Error *err = NULL;
uint64_t value; uint64_t value;
visit_type_size(v, name, &value, &err); if (!visit_type_size(v, name, &value, errp)) {
if (err) {
error_propagate(errp, err);
return; return;
} }
@ -1159,7 +1156,6 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp) void *opaque, Error **errp)
{ {
VirtIOMEM *vmem = VIRTIO_MEM(obj); VirtIOMEM *vmem = VIRTIO_MEM(obj);
Error *err = NULL;
uint64_t value; uint64_t value;
if (DEVICE(obj)->realized) { if (DEVICE(obj)->realized) {
@ -1167,9 +1163,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
return; return;
} }
visit_type_size(v, name, &value, &err); if (!visit_type_size(v, name, &value, errp)) {
if (err) {
error_propagate(errp, err);
return; return;
} }

View File

@ -1135,22 +1135,17 @@ static void set_max_queue_size(Object *obj, Visitor *v,
const char *name, void *opaque, const char *name, void *opaque,
Error **errp) Error **errp)
{ {
Error *local_err = NULL;
uint64_t value; uint64_t value;
visit_type_uint64(v, name, &value, &local_err); if (!visit_type_uint64(v, name, &value, errp)) {
if (local_err) { return;
goto out;
} }
if (!value) { if (!value) {
error_setg(&local_err, "Property '%s.%s' requires a positive value", error_setg(errp, "Property '%s.%s' requires a positive value",
object_get_typename(obj), name); object_get_typename(obj), name);
goto out; return;
} }
max_queue_size = value; max_queue_size = value;
out:
error_propagate(errp, local_err);
} }
static void compare_pri_rs_finalize(SocketReadState *pri_rs) static void compare_pri_rs_finalize(SocketReadState *pri_rs)

View File

@ -5689,7 +5689,6 @@ static void kvm_arch_set_notify_window(Object *obj, Visitor *v,
Error **errp) Error **errp)
{ {
KVMState *s = KVM_STATE(obj); KVMState *s = KVM_STATE(obj);
Error *error = NULL;
uint32_t value; uint32_t value;
if (s->fd != -1) { if (s->fd != -1) {
@ -5697,9 +5696,7 @@ static void kvm_arch_set_notify_window(Object *obj, Visitor *v,
return; return;
} }
visit_type_uint32(v, name, &value, &error); if (!visit_type_uint32(v, name, &value, errp)) {
if (error) {
error_propagate(errp, error);
return; return;
} }

View File

@ -90,16 +90,13 @@ static void thread_context_set_cpu_affinity(Object *obj, Visitor *v,
uint16List *l, *host_cpus = NULL; uint16List *l, *host_cpus = NULL;
unsigned long *bitmap = NULL; unsigned long *bitmap = NULL;
int nbits = 0, ret; int nbits = 0, ret;
Error *err = NULL;
if (tc->init_cpu_bitmap) { if (tc->init_cpu_bitmap) {
error_setg(errp, "Mixing CPU and node affinity not supported"); error_setg(errp, "Mixing CPU and node affinity not supported");
return; return;
} }
visit_type_uint16List(v, name, &host_cpus, &err); if (!visit_type_uint16List(v, name, &host_cpus, errp)) {
if (err) {
error_propagate(errp, err);
return; return;
} }
@ -178,7 +175,6 @@ static void thread_context_set_node_affinity(Object *obj, Visitor *v,
uint16List *l, *host_nodes = NULL; uint16List *l, *host_nodes = NULL;
unsigned long *bitmap = NULL; unsigned long *bitmap = NULL;
struct bitmask *tmp_cpus; struct bitmask *tmp_cpus;
Error *err = NULL;
int ret, i; int ret, i;
if (tc->init_cpu_bitmap) { if (tc->init_cpu_bitmap) {
@ -186,9 +182,7 @@ static void thread_context_set_node_affinity(Object *obj, Visitor *v,
return; return;
} }
visit_type_uint16List(v, name, &host_nodes, &err); if (!visit_type_uint16List(v, name, &host_nodes, errp)) {
if (err) {
error_propagate(errp, err);
return; return;
} }