Skip to content

Commit

Permalink
qapi: Use returned bool to check for failure (again)
Browse files Browse the repository at this point in the history
Commit 012d4c9 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 012d4c9 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 <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
  • Loading branch information
Markus Armbruster committed Dec 14, 2022
1 parent f560eb1 commit d1c81c3
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 52 deletions.
5 changes: 1 addition & 4 deletions accel/kvm/kvm-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -3586,17 +3586,14 @@ static void kvm_set_dirty_ring_size(Object *obj, Visitor *v,
Error **errp)
{
KVMState *s = KVM_STATE(obj);
Error *error = NULL;
uint32_t value;

if (s->fd != -1) {
error_setg(errp, "Cannot set properties after the accelerator has been initialized");
return;
}

visit_type_uint32(v, name, &value, &error);
if (error) {
error_propagate(errp, error);
if (!visit_type_uint32(v, name, &value, errp)) {
return;
}
if (value & (value - 1)) {
Expand Down
5 changes: 1 addition & 4 deletions hw/core/qdev-properties-system.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,11 @@ static void set_reserved_region(Object *obj, Visitor *v, const char *name,
{
Property *prop = opaque;
ReservedRegion *rr = object_field_prop_ptr(obj, prop);
Error *local_err = NULL;
const char *endptr;
char *str;
int ret;

visit_type_str(v, name, &str, &local_err);
if (local_err) {
error_propagate(errp, local_err);
if (!visit_type_str(v, name, &str, errp)) {
return;
}

Expand Down
5 changes: 1 addition & 4 deletions hw/i386/pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1782,12 +1782,9 @@ static void pc_machine_set_max_fw_size(Object *obj, Visitor *v,
Error **errp)
{
PCMachineState *pcms = PC_MACHINE(obj);
Error *error = NULL;
uint64_t value;

visit_type_size(v, name, &value, &error);
if (error) {
error_propagate(errp, error);
if (!visit_type_size(v, name, &value, errp)) {
return;
}

Expand Down
20 changes: 9 additions & 11 deletions hw/virtio/virtio-balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
void *opaque, Error **errp)
{
Error *err = NULL;
VirtIOBalloon *s = VIRTIO_BALLOON(obj);
bool ok = false;
int i;

if (!visit_start_struct(v, name, NULL, 0, &err)) {
goto out;
if (!visit_start_struct(v, name, NULL, 0, errp)) {
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;
}

if (!visit_start_struct(v, "stats", NULL, 0, &err)) {
if (!visit_start_struct(v, "stats", NULL, 0, errp)) {
goto out_end;
}
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;
}
}
visit_check_struct(v, &err);
ok = visit_check_struct(v, errp);
out_nested:
visit_end_struct(v, NULL);

if (!err) {
visit_check_struct(v, &err);
if (ok) {
visit_check_struct(v, errp);
}
out_end:
visit_end_struct(v, NULL);
out:
error_propagate(errp, err);
}

static void balloon_stats_get_poll_interval(Object *obj, Visitor *v,
Expand Down
10 changes: 2 additions & 8 deletions hw/virtio/virtio-mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,12 +1094,9 @@ static void virtio_mem_set_requested_size(Object *obj, Visitor *v,
Error **errp)
{
VirtIOMEM *vmem = VIRTIO_MEM(obj);
Error *err = NULL;
uint64_t value;

visit_type_size(v, name, &value, &err);
if (err) {
error_propagate(errp, err);
if (!visit_type_size(v, name, &value, errp)) {
return;
}

Expand Down Expand Up @@ -1159,17 +1156,14 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
VirtIOMEM *vmem = VIRTIO_MEM(obj);
Error *err = NULL;
uint64_t value;

if (DEVICE(obj)->realized) {
error_setg(errp, "'%s' cannot be changed", name);
return;
}

visit_type_size(v, name, &value, &err);
if (err) {
error_propagate(errp, err);
if (!visit_type_size(v, name, &value, errp)) {
return;
}

Expand Down
13 changes: 4 additions & 9 deletions net/colo-compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -1135,22 +1135,17 @@ static void set_max_queue_size(Object *obj, Visitor *v,
const char *name, void *opaque,
Error **errp)
{
Error *local_err = NULL;
uint64_t value;

visit_type_uint64(v, name, &value, &local_err);
if (local_err) {
goto out;
if (!visit_type_uint64(v, name, &value, errp)) {
return;
}
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);
goto out;
return;
}
max_queue_size = value;

out:
error_propagate(errp, local_err);
}

static void compare_pri_rs_finalize(SocketReadState *pri_rs)
Expand Down
5 changes: 1 addition & 4 deletions target/i386/kvm/kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5689,17 +5689,14 @@ static void kvm_arch_set_notify_window(Object *obj, Visitor *v,
Error **errp)
{
KVMState *s = KVM_STATE(obj);
Error *error = NULL;
uint32_t value;

if (s->fd != -1) {
error_setg(errp, "Cannot set properties after the accelerator has been initialized");
return;
}

visit_type_uint32(v, name, &value, &error);
if (error) {
error_propagate(errp, error);
if (!visit_type_uint32(v, name, &value, errp)) {
return;
}

Expand Down
10 changes: 2 additions & 8 deletions util/thread-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,13 @@ static void thread_context_set_cpu_affinity(Object *obj, Visitor *v,
uint16List *l, *host_cpus = NULL;
unsigned long *bitmap = NULL;
int nbits = 0, ret;
Error *err = NULL;

if (tc->init_cpu_bitmap) {
error_setg(errp, "Mixing CPU and node affinity not supported");
return;
}

visit_type_uint16List(v, name, &host_cpus, &err);
if (err) {
error_propagate(errp, err);
if (!visit_type_uint16List(v, name, &host_cpus, errp)) {
return;
}

Expand Down Expand Up @@ -178,17 +175,14 @@ static void thread_context_set_node_affinity(Object *obj, Visitor *v,
uint16List *l, *host_nodes = NULL;
unsigned long *bitmap = NULL;
struct bitmask *tmp_cpus;
Error *err = NULL;
int ret, i;

if (tc->init_cpu_bitmap) {
error_setg(errp, "Mixing CPU and node affinity not supported");
return;
}

visit_type_uint16List(v, name, &host_nodes, &err);
if (err) {
error_propagate(errp, err);
if (!visit_type_uint16List(v, name, &host_nodes, errp)) {
return;
}

Expand Down

0 comments on commit d1c81c3

Please sign in to comment.