From d2623129a7dec1d3041ad1221dda1ca49c667532 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 5 May 2020 17:29:22 +0200 Subject: qom: Drop parameter @errp of object_property_add() & friends The only way object_property_add() can fail is when a property with the same name already exists. Since our property names are all hardcoded, failure is a programming error, and the appropriate way to handle it is passing &error_abort. Same for its variants, except for object_property_add_child(), which additionally fails when the child already has a parent. Parentage is also under program control, so this is a programming error, too. We have a bit over 500 callers. Almost half of them pass &error_abort, slightly fewer ignore errors, one test case handles errors, and the remaining few callers pass them to their own callers. The previous few commits demonstrated once again that ignoring programming errors is a bad idea. Of the few ones that pass on errors, several violate the Error API. The Error ** argument must be NULL, &error_abort, &error_fatal, or a pointer to a variable containing NULL. Passing an argument of the latter kind twice without clearing it in between is wrong: if the first call sets an error, it no longer points to NULL for the second call. ich9_pm_add_properties(), sparc32_ledma_realize(), sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize() are wrong that way. When the one appropriate choice of argument is &error_abort, letting users pick the argument is a bad idea. Drop parameter @errp and assert the preconditions instead. There's one exception to "duplicate property name is a programming error": the way object_property_add() implements the magic (and undocumented) "automatic arrayification". Don't drop @errp there. Instead, rename object_property_add() to object_property_try_add(), and add the obvious wrapper object_property_add(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Reviewed-by: Paolo Bonzini Message-Id: <20200505152926.18877-15-armbru@redhat.com> [Two semantic rebase conflicts resolved] --- target/arm/cpu.c | 11 +++--- target/arm/cpu64.c | 8 ++--- target/arm/kvm.c | 2 +- target/i386/cpu.c | 85 +++++++++++++++++++++++------------------------ target/i386/sev.c | 17 ++++------ target/ppc/compat.c | 9 +---- target/s390x/cpu.c | 2 +- target/s390x/cpu_models.c | 11 +++--- 8 files changed, 65 insertions(+), 80 deletions(-) (limited to 'target') diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 3794f0dbc4..32bec156f2 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1179,8 +1179,7 @@ void arm_cpu_post_init(Object *obj) TYPE_MEMORY_REGION, (Object **)&cpu->secure_memory, qdev_prop_allow_set_link_before_realize, - OBJ_PROP_LINK_STRONG, - &error_abort); + OBJ_PROP_LINK_STRONG); } if (arm_feature(&cpu->env, ARM_FEATURE_EL2)) { @@ -1190,8 +1189,7 @@ void arm_cpu_post_init(Object *obj) if (arm_feature(&cpu->env, ARM_FEATURE_PMU)) { cpu->has_pmu = true; - object_property_add_bool(obj, "pmu", arm_get_pmu, arm_set_pmu, - &error_abort); + object_property_add_bool(obj, "pmu", arm_get_pmu, arm_set_pmu); } /* @@ -1231,8 +1229,7 @@ void arm_cpu_post_init(Object *obj) if (arm_feature(&cpu->env, ARM_FEATURE_M_SECURITY)) { object_property_add_link(obj, "idau", TYPE_IDAU_INTERFACE, &cpu->idau, qdev_prop_allow_set_link_before_realize, - OBJ_PROP_LINK_STRONG, - &error_abort); + OBJ_PROP_LINK_STRONG); /* * M profile: initial value of the Secure VTOR. We can't just use * a simple DEFINE_PROP_UINT32 for this because we want to permit @@ -1240,7 +1237,7 @@ void arm_cpu_post_init(Object *obj) */ object_property_add_uint32_ptr(obj, "init-svtor", &cpu->init_svtor, - OBJ_PROP_FLAG_READWRITE, &error_abort); + OBJ_PROP_FLAG_READWRITE); } qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property); diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 18a0af88e2..cbc5c3868f 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -571,13 +571,13 @@ void aarch64_add_sve_properties(Object *obj) uint32_t vq; object_property_add(obj, "sve", "bool", cpu_arm_get_sve, - cpu_arm_set_sve, NULL, NULL, &error_fatal); + cpu_arm_set_sve, NULL, NULL); for (vq = 1; vq <= ARM_MAX_VQ; ++vq) { char name[8]; sprintf(name, "sve%d", vq * 128); object_property_add(obj, name, "bool", cpu_arm_get_sve_vq, - cpu_arm_set_sve_vq, NULL, NULL, &error_fatal); + cpu_arm_set_sve_vq, NULL, NULL); } } @@ -726,7 +726,7 @@ static void aarch64_max_initfn(Object *obj) aarch64_add_sve_properties(obj); object_property_add(obj, "sve-max-vq", "uint32", cpu_max_get_sve_max_vq, - cpu_max_set_sve_max_vq, NULL, NULL, &error_fatal); + cpu_max_set_sve_max_vq, NULL, NULL); } static const ARMCPUInfo aarch64_cpus[] = { @@ -767,7 +767,7 @@ static void aarch64_cpu_set_aarch64(Object *obj, bool value, Error **errp) static void aarch64_cpu_initfn(Object *obj) { object_property_add_bool(obj, "aarch64", aarch64_cpu_get_aarch64, - aarch64_cpu_set_aarch64, NULL); + aarch64_cpu_set_aarch64); object_property_set_description(obj, "aarch64", "Set on/off to enable/disable aarch64 " "execution state "); diff --git a/target/arm/kvm.c b/target/arm/kvm.c index 1ea2d047e3..4bdbe6dcac 100644 --- a/target/arm/kvm.c +++ b/target/arm/kvm.c @@ -200,7 +200,7 @@ void kvm_arm_add_vcpu_properties(Object *obj) ARM_CPU(obj)->kvm_adjvtime = true; object_property_add_bool(obj, "kvm-no-adjvtime", kvm_no_adjvtime_get, - kvm_no_adjvtime_set, &error_abort); + kvm_no_adjvtime_set); object_property_set_description(obj, "kvm-no-adjvtime", "Set on to disable the adjustment of " "the virtual counter. VM stopped time " diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9c256ab159..6a64d2a5cd 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6110,7 +6110,7 @@ static void x86_cpu_apic_create(X86CPU *cpu, Error **errp) cpu->apic_state = DEVICE(object_new_with_class(apic_class)); object_property_add_child(OBJECT(cpu), "lapic", - OBJECT(cpu->apic_state), &error_abort); + OBJECT(cpu->apic_state)); object_unref(OBJECT(cpu->apic_state)); qdev_prop_set_uint32(cpu->apic_state, "id", cpu->apic_id); @@ -6822,7 +6822,7 @@ static void x86_cpu_register_bit_prop(X86CPU *cpu, object_property_add(OBJECT(cpu), prop_name, "bool", x86_cpu_get_bit_prop, x86_cpu_set_bit_prop, - x86_cpu_release_bit_prop, fp, &error_abort); + x86_cpu_release_bit_prop, fp); } } @@ -6905,28 +6905,28 @@ static void x86_cpu_initfn(Object *obj) object_property_add(obj, "family", "int", x86_cpuid_version_get_family, - x86_cpuid_version_set_family, NULL, NULL, NULL); + x86_cpuid_version_set_family, NULL, NULL); object_property_add(obj, "model", "int", x86_cpuid_version_get_model, - x86_cpuid_version_set_model, NULL, NULL, NULL); + x86_cpuid_version_set_model, NULL, NULL); object_property_add(obj, "stepping", "int", x86_cpuid_version_get_stepping, - x86_cpuid_version_set_stepping, NULL, NULL, NULL); + x86_cpuid_version_set_stepping, NULL, NULL); object_property_add_str(obj, "vendor", x86_cpuid_get_vendor, - x86_cpuid_set_vendor, NULL); + x86_cpuid_set_vendor); object_property_add_str(obj, "model-id", x86_cpuid_get_model_id, - x86_cpuid_set_model_id, NULL); + x86_cpuid_set_model_id); object_property_add(obj, "tsc-frequency", "int", x86_cpuid_get_tsc_freq, - x86_cpuid_set_tsc_freq, NULL, NULL, NULL); + x86_cpuid_set_tsc_freq, NULL, NULL); object_property_add(obj, "feature-words", "X86CPUFeatureWordInfo", x86_cpu_get_feature_words, - NULL, NULL, (void *)env->features, NULL); + NULL, NULL, (void *)env->features); object_property_add(obj, "filtered-features", "X86CPUFeatureWordInfo", x86_cpu_get_feature_words, - NULL, NULL, (void *)cpu->filtered_features, NULL); + NULL, NULL, (void *)cpu->filtered_features); /* * The "unavailable-features" property has the same semantics as * CpuDefinitionInfo.unavailable-features on the "query-cpu-definitions" @@ -6935,10 +6935,10 @@ static void x86_cpu_initfn(Object *obj) */ object_property_add(obj, "unavailable-features", "strList", x86_cpu_get_unavailable_features, - NULL, NULL, NULL, &error_abort); + NULL, NULL, NULL); object_property_add(obj, "crash-information", "GuestPanicInformation", - x86_cpu_get_crash_info_qom, NULL, NULL, NULL, NULL); + x86_cpu_get_crash_info_qom, NULL, NULL, NULL); for (w = 0; w < FEATURE_WORDS; w++) { int bitnr; @@ -6948,37 +6948,36 @@ static void x86_cpu_initfn(Object *obj) } } - object_property_add_alias(obj, "sse3", obj, "pni", &error_abort); - object_property_add_alias(obj, "pclmuldq", obj, "pclmulqdq", &error_abort); - object_property_add_alias(obj, "sse4-1", obj, "sse4.1", &error_abort); - object_property_add_alias(obj, "sse4-2", obj, "sse4.2", &error_abort); - object_property_add_alias(obj, "xd", obj, "nx", &error_abort); - object_property_add_alias(obj, "ffxsr", obj, "fxsr-opt", &error_abort); - object_property_add_alias(obj, "i64", obj, "lm", &error_abort); - - object_property_add_alias(obj, "ds_cpl", obj, "ds-cpl", &error_abort); - object_property_add_alias(obj, "tsc_adjust", obj, "tsc-adjust", &error_abort); - object_property_add_alias(obj, "fxsr_opt", obj, "fxsr-opt", &error_abort); - object_property_add_alias(obj, "lahf_lm", obj, "lahf-lm", &error_abort); - object_property_add_alias(obj, "cmp_legacy", obj, "cmp-legacy", &error_abort); - object_property_add_alias(obj, "nodeid_msr", obj, "nodeid-msr", &error_abort); - object_property_add_alias(obj, "perfctr_core", obj, "perfctr-core", &error_abort); - object_property_add_alias(obj, "perfctr_nb", obj, "perfctr-nb", &error_abort); - object_property_add_alias(obj, "kvm_nopiodelay", obj, "kvm-nopiodelay", &error_abort); - object_property_add_alias(obj, "kvm_mmu", obj, "kvm-mmu", &error_abort); - object_property_add_alias(obj, "kvm_asyncpf", obj, "kvm-asyncpf", &error_abort); - object_property_add_alias(obj, "kvm_steal_time", obj, "kvm-steal-time", &error_abort); - object_property_add_alias(obj, "kvm_pv_eoi", obj, "kvm-pv-eoi", &error_abort); - object_property_add_alias(obj, "kvm_pv_unhalt", obj, "kvm-pv-unhalt", &error_abort); - object_property_add_alias(obj, "kvm_poll_control", obj, "kvm-poll-control", - &error_abort); - object_property_add_alias(obj, "svm_lock", obj, "svm-lock", &error_abort); - object_property_add_alias(obj, "nrip_save", obj, "nrip-save", &error_abort); - object_property_add_alias(obj, "tsc_scale", obj, "tsc-scale", &error_abort); - object_property_add_alias(obj, "vmcb_clean", obj, "vmcb-clean", &error_abort); - object_property_add_alias(obj, "pause_filter", obj, "pause-filter", &error_abort); - object_property_add_alias(obj, "sse4_1", obj, "sse4.1", &error_abort); - object_property_add_alias(obj, "sse4_2", obj, "sse4.2", &error_abort); + object_property_add_alias(obj, "sse3", obj, "pni"); + object_property_add_alias(obj, "pclmuldq", obj, "pclmulqdq"); + object_property_add_alias(obj, "sse4-1", obj, "sse4.1"); + object_property_add_alias(obj, "sse4-2", obj, "sse4.2"); + object_property_add_alias(obj, "xd", obj, "nx"); + object_property_add_alias(obj, "ffxsr", obj, "fxsr-opt"); + object_property_add_alias(obj, "i64", obj, "lm"); + + object_property_add_alias(obj, "ds_cpl", obj, "ds-cpl"); + object_property_add_alias(obj, "tsc_adjust", obj, "tsc-adjust"); + object_property_add_alias(obj, "fxsr_opt", obj, "fxsr-opt"); + object_property_add_alias(obj, "lahf_lm", obj, "lahf-lm"); + object_property_add_alias(obj, "cmp_legacy", obj, "cmp-legacy"); + object_property_add_alias(obj, "nodeid_msr", obj, "nodeid-msr"); + object_property_add_alias(obj, "perfctr_core", obj, "perfctr-core"); + object_property_add_alias(obj, "perfctr_nb", obj, "perfctr-nb"); + object_property_add_alias(obj, "kvm_nopiodelay", obj, "kvm-nopiodelay"); + object_property_add_alias(obj, "kvm_mmu", obj, "kvm-mmu"); + object_property_add_alias(obj, "kvm_asyncpf", obj, "kvm-asyncpf"); + object_property_add_alias(obj, "kvm_steal_time", obj, "kvm-steal-time"); + object_property_add_alias(obj, "kvm_pv_eoi", obj, "kvm-pv-eoi"); + object_property_add_alias(obj, "kvm_pv_unhalt", obj, "kvm-pv-unhalt"); + object_property_add_alias(obj, "kvm_poll_control", obj, "kvm-poll-control"); + object_property_add_alias(obj, "svm_lock", obj, "svm-lock"); + object_property_add_alias(obj, "nrip_save", obj, "nrip-save"); + object_property_add_alias(obj, "tsc_scale", obj, "tsc-scale"); + object_property_add_alias(obj, "vmcb_clean", obj, "vmcb-clean"); + object_property_add_alias(obj, "pause_filter", obj, "pause-filter"); + object_property_add_alias(obj, "sse4_1", obj, "sse4.1"); + object_property_add_alias(obj, "sse4_2", obj, "sse4.2"); if (xcc->model) { x86_cpu_load_model(cpu, xcc->model, &error_abort); diff --git a/target/i386/sev.c b/target/i386/sev.c index 6842cfc26d..51cdbe5496 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -248,20 +248,17 @@ qsev_guest_class_init(ObjectClass *oc, void *data) { object_class_property_add_str(oc, "sev-device", qsev_guest_get_sev_device, - qsev_guest_set_sev_device, - NULL); + qsev_guest_set_sev_device); object_class_property_set_description(oc, "sev-device", "SEV device to use"); object_class_property_add_str(oc, "dh-cert-file", qsev_guest_get_dh_cert_file, - qsev_guest_set_dh_cert_file, - NULL); + qsev_guest_set_dh_cert_file); object_class_property_set_description(oc, "dh-cert-file", "guest owners DH certificate (encoded with base64)"); object_class_property_add_str(oc, "session-file", qsev_guest_get_session_file, - qsev_guest_set_session_file, - NULL); + qsev_guest_set_session_file); object_class_property_set_description(oc, "session-file", "guest owners session parameters (encoded with base64)"); } @@ -274,14 +271,14 @@ qsev_guest_init(Object *obj) sev->sev_device = g_strdup(DEFAULT_SEV_DEVICE); sev->policy = DEFAULT_GUEST_POLICY; object_property_add_uint32_ptr(obj, "policy", &sev->policy, - OBJ_PROP_FLAG_READWRITE, NULL); + OBJ_PROP_FLAG_READWRITE); object_property_add_uint32_ptr(obj, "handle", &sev->handle, - OBJ_PROP_FLAG_READWRITE, NULL); + OBJ_PROP_FLAG_READWRITE); object_property_add_uint32_ptr(obj, "cbitpos", &sev->cbitpos, - OBJ_PROP_FLAG_READWRITE, NULL); + OBJ_PROP_FLAG_READWRITE); object_property_add_uint32_ptr(obj, "reduced-phys-bits", &sev->reduced_phys_bits, - OBJ_PROP_FLAG_READWRITE, NULL); + OBJ_PROP_FLAG_READWRITE); } /* sev guest info */ diff --git a/target/ppc/compat.c b/target/ppc/compat.c index 46ffb6da6d..7f144392f8 100644 --- a/target/ppc/compat.c +++ b/target/ppc/compat.c @@ -301,17 +301,13 @@ void ppc_compat_add_property(Object *obj, const char *name, uint32_t *compat_pvr, const char *basedesc, Error **errp) { - Error *local_err = NULL; gchar *namesv[ARRAY_SIZE(compat_table) + 1]; gchar *names, *desc; int i; object_property_add(obj, name, "string", ppc_compat_prop_get, ppc_compat_prop_set, NULL, - compat_pvr, &local_err); - if (local_err) { - goto out; - } + compat_pvr); for (i = 0; i < ARRAY_SIZE(compat_table); i++) { /* @@ -328,7 +324,4 @@ void ppc_compat_add_property(Object *obj, const char *name, g_free(names); g_free(desc); - -out: - error_propagate(errp, local_err); } diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index f2ccf0a06a..ca50b70451 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -296,7 +296,7 @@ static void s390_cpu_initfn(Object *obj) cs->halted = 1; cs->exception_index = EXCP_HLT; object_property_add(obj, "crash-information", "GuestPanicInformation", - s390_cpu_get_crash_info_qom, NULL, NULL, NULL, NULL); + s390_cpu_get_crash_info_qom, NULL, NULL, NULL); s390_cpu_model_register_props(obj); #if !defined(CONFIG_USER_ONLY) cpu->env.tod_timer = diff --git a/target/s390x/cpu_models.c b/target/s390x/cpu_models.c index aa7fc713ca..8efe6ed514 100644 --- a/target/s390x/cpu_models.c +++ b/target/s390x/cpu_models.c @@ -1106,13 +1106,13 @@ void s390_cpu_model_register_props(Object *obj) for (feat = 0; feat < S390_FEAT_MAX; feat++) { const S390FeatDef *def = s390_feat_def(feat); object_property_add(obj, def->name, "bool", get_feature, - set_feature, NULL, (void *) feat, NULL); + set_feature, NULL, (void *) feat); object_property_set_description(obj, def->name, def->desc); } for (group = 0; group < S390_FEAT_GROUP_MAX; group++) { const S390FeatGroupDef *def = s390_feat_group_def(group); object_property_add(obj, def->name, "bool", get_feature_group, - set_feature_group, NULL, (void *) group, NULL); + set_feature_group, NULL, (void *) group); object_property_set_description(obj, def->name, def->desc); } } @@ -1225,11 +1225,10 @@ static char *get_description(Object *obj, Error **errp) void s390_cpu_model_class_register_props(ObjectClass *oc) { object_class_property_add_bool(oc, "migration-safe", get_is_migration_safe, - NULL, NULL); + NULL); object_class_property_add_bool(oc, "static", get_is_static, - NULL, NULL); - object_class_property_add_str(oc, "description", get_description, NULL, - NULL); + NULL); + object_class_property_add_str(oc, "description", get_description, NULL); } #ifdef CONFIG_KVM -- cgit v1.2.3