qapi: Use returned bool to check for failure (again)
Commit012d4c96e2
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 commit012d4c96e2
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:
parent
f560eb1f0a
commit
d1c81c3496
@ -3586,7 +3586,6 @@ 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) {
|
||||
@ -3594,9 +3593,7 @@ static void kvm_set_dirty_ring_size(Object *obj, Visitor *v,
|
||||
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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -1159,7 +1156,6 @@ 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) {
|
||||
@ -1167,9 +1163,7 @@ static void virtio_mem_set_block_size(Object *obj, Visitor *v, const char *name,
|
||||
return;
|
||||
}
|
||||
|
||||
visit_type_size(v, name, &value, &err);
|
||||
if (err) {
|
||||
error_propagate(errp, err);
|
||||
if (!visit_type_size(v, name, &value, errp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -5689,7 +5689,6 @@ 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) {
|
||||
@ -5697,9 +5696,7 @@ static void kvm_arch_set_notify_window(Object *obj, Visitor *v,
|
||||
return;
|
||||
}
|
||||
|
||||
visit_type_uint32(v, name, &value, &error);
|
||||
if (error) {
|
||||
error_propagate(errp, error);
|
||||
if (!visit_type_uint32(v, name, &value, errp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
@ -178,7 +175,6 @@ 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) {
|
||||
@ -186,9 +182,7 @@ static void thread_context_set_node_affinity(Object *obj, Visitor *v,
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user