s390x/cpu_models: Misc cleanup on returned error code and local @err variables
cover s390x/cpu_models: Misc cleanup on returned error code and local @err variables
From: Zhao Liu <[email protected]>
Hi list,
This series is the followup of Thomas' suggestion in previous ERRP_GUARD() cleanup[1]. And based on Thomas' thoughts, I tried to clean up as many of the other related places (in s390x/cpu_models.c).
[1]: https://lore.kernel.org/qemu-devel/[email protected]/
Regards,
Zhao
---
Zhao Liu (6):
target/s390x/cpu_model: Make check_compatibility() return boolean target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model() target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return
boolean
target/s390x/cpu_models: Drop local @err in get_max_cpu_model() target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return
boolean
target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()
target/s390x/cpu_models.c | 25 ++++++++++--------------- target/s390x/cpu_models.h | 10 ++++++---- target/s390x/cpu_models_sysemu.c | 5 +---- target/s390x/kvm/kvm.c | 28 +++++++++++++++------------- 4 files changed, 32 insertions(+), 36 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/6 target/s390x/cpu_model: Make check_compatibility() return boolean
From: Zhao Liu <[email protected]>
As error.h suggested, the best practice for callee is to return something to indicate success / failure.
With returned boolean, there's no need to check @err.
--- target/s390x/cpu_models.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
target/s390x/cpu_models.c +7 -7
@@ -510,7 +510,7 @@ static void check_compat_model_failed(Error **errp,return ; } -static void check_compatibility (const S390CPUModel *max_model, +static bool check_compatibility (const S390CPUModel *max_model,const S390CPUModel *model,Error **errp) {ERRP_GUARD ();
@@ -518,11 +518,11 @@ static void check_compatibility(const S390CPUModel *max_model,if (model->def->gen > max_model->def->gen) {check_compat_model_failed (errp, max_model,"Selected CPU generation is too new" ); -return ; +return false; }else if (model->def->gen == max_model->def->gen && model->def->ec_ga > max_model->def->ec_ga) {check_compat_model_failed (errp, max_model,"Selected CPU GA level is too new" ); -return ; +return false; }#ifndef CONFIG_USER_ONLY
@@ -530,14 +530,14 @@ static void check_compatibility(const S390CPUModel *max_model,error_setg (errp,"The unpack facility is not compatible with " "the --only-migratable option. You must remove either " "the 'unpack' facility or the --only-migratable option" ); - return; + return false; }#endif /* detect the missing features to properly report them */ bitmap_andnot (missing, model->features, max_model->features,S390_FEAT_MAX );if (bitmap_empty (missing,S390_FEAT_MAX )) { -return ; +return true; }error_setg (errp," " );
@@ -546,6 +546,7 @@ static void check_compatibility(const S390CPUModel *max_model, "available in the current configuration: ");error_append_hint (errp,"Consider a different accelerator, QEMU, or kernel version\n" ); +return false; }S390CPUModel *get_max_cpu_model (Error **errp)
@@ -605,8 +606,7 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp) cpu->model->cpu_ver = max_model->cpu_ver;check_consistency (cpu->model); -check_compatibility (max_model, cpu->model, &err); -if (err) { +if (!check_compatibility (max_model, cpu->model, &err)) {error_propagate (errp, err);return ; }
Signature · 1 line
2.34.1
Re: [PATCH 1/6] target/s390x/cpu_model: Make check_compatibility() return boolean
Quoted 5 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As
error.hsuggested, the best practice for callee is to return something to indicate success / failure.
Quoted 7 lines
With returned boolean, there's no need to check @err.
Suggested-by Thomas Huth <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- target/s390x/cpu_models.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
PATCH 2/6 target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
Use @errp to fetech error information directly and drop the local virable @err.
--- target/s390x/cpu_models.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/cpu_models.c +1 -3
@@ -577,7 +577,6 @@ S390CPUModel *get_max_cpu_model(Error **errp)void s390_realize_cpu_model (CPUState *cs,Error **errp) {ERRP_GUARD (); -Error *err =NULL ;S390CPUClass *xcc =S390_CPU_GET_CLASS (cs);S390CPU *cpu =S390_CPU (cs);const S390CPUModel *max_model;
@@ -606,8 +605,7 @@ void s390_realize_cpu_model(CPUState *cs, Error **errp) cpu->model->cpu_ver = max_model->cpu_ver;check_consistency (cpu->model); -if (!check_compatibility (max_model, cpu->model, &err)) { -error_propagate (errp, err); +if (!check_compatibility (max_model, cpu->model, errp)) {return ; }
Signature · 1 line
2.34.1
Re: [PATCH 2/6] target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()
Quoted 3 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Use @errp to fetech error information directly and drop the local
s/fetech/fetch/
Quoted 1 line
virable @err.
s/virable/variable/
Quoted 5 lines
Suggested-by Thomas Huth <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- target/s390x/cpu_models.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
With the typos fixed:
Re: [PATCH 2/6] target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()
Quoted 16 lines · Thomas Huth
Date: Fri, 19 Apr 2024 09:39:53 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 2/6] target/s390x/cpu_model: Drop local @err in
s390_realize_cpu_model()Quoted 3 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Use @errp to fetech error information directly and drop the local
s/fetech/fetch/
Quoted 1 line
virable @err.
s/virable/variable/
Quoted 9 lines
Quoted 5 lines
Suggested-by Thomas Huth <[email protected]>Signed-off-by Zhao Liu <[email protected]>--- target/s390x/cpu_models.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)With the typos fixed:
Reviewed-by Thomas Huth <[email protected]>
Thanks! --codespell check also missed them. Will fix!
Regards,
Zhao
PATCH 3/6 target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As error.h suggested, the best practice for callee is to return something to indicate success / failure.
So make kvm_s390_get_host_cpu_model() return boolean and check the returned boolean in get_max_cpu_model() instead of accessing @err.
Additionally, since now get_max_cpu_model() returns directly if kvm_s390_get_host_cpu_model() fills @err, so make kvm_s390_get_host_cpu_model() return true by default for the non-KVM case in target/s390x/cpu_models.h.
--- target/s390x/cpu_models.c | 9 ++++----- target/s390x/cpu_models.h | 5 +++-- target/s390x/kvm/kvm.c | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-)
target/s390x/cpu_models.c +4 -5
@@ -560,16 +560,15 @@ S390CPUModel *get_max_cpu_model(Error **errp) }if (kvm_enabled ()) { -kvm_s390_get_host_cpu_model (&max_model, &err); +if (!kvm_s390_get_host_cpu_model (&max_model, &err)) { +error_propagate (errp, err); +return NULL ; + } }else { max_model.def =s390_find_cpu_def (QEMU_MAX_CPU_TYPE ,QEMU_MAX_CPU_GEN ,QEMU_MAX_CPU_EC_GA ,NULL );bitmap_copy (max_model.features, qemu_max_cpu_feat,S390_FEAT_MAX ); } -if (err) { -error_propagate (errp, err); -return NULL ; - } cached = true;return &max_model; }
target/s390x/cpu_models.h +3 -2
@@ -116,12 +116,13 @@ S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,#ifdef CONFIG_KVM bool kvm_s390_cpu_models_supported (void ); -void kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp); +bool kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp);void kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp);#else -static inline void kvm_s390_get_host_cpu_model (S390CPUModel *model, +static inline bool kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp) { +return true; }static inline void kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp)
target/s390x/kvm/kvm.c +7 -6
@@ -2375,7 +2375,7 @@ bool kvm_s390_cpu_models_supported(void) KVM_S390_VM_CPU_MACHINE_SUBFUNC); } -void kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp) +bool kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp) {struct kvm_s390_vm_cpu_machine prop = {};struct kvm_device_attr attr = {
@@ -2390,14 +2390,14 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)if (!kvm_s390_cpu_models_supported ()) {error_setg (errp,"KVM doesn't support CPU models" ); -return ; +return false; }/* query the basic cpu model properties */ rc =kvm_vm_ioctl (kvm_state,KVM_GET_DEVICE_ATTR , &attr);if (rc) {error_setg (errp,"KVM: Error querying host CPU model: %d" , rc); -return ; +return false; } cpu_type =cpuid_type (prop.cpuid);
@@ -2420,13 +2420,13 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp) rc =query_cpu_feat (model->features);if (rc) {error_setg (errp,"KVM: Error querying CPU features: %d" , rc); -return ; +return false; }/* get supported cpu subfunctions indicated via query / test bit */ rc =query_cpu_subfunc (model->features);if (rc) {error_setg (errp,"KVM: Error querying CPU subfunctions: %d" , rc); -return ; +return false; }/* PTFF subfunctions might be indicated although kernel support missing */
@@ -2482,7 +2482,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp) }if (!model->def) {error_setg (errp,"KVM: host CPU model could not be identified" ); -return ; +return false; }/* for now, we can only provide the AP feature with HW support */ if (ap_available ()) {
@@ -2506,6 +2506,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp)/* strip of features that are not part of the maximum model */ bitmap_and (model->features, model->features, model->def->full_feat,S390_FEAT_MAX ); +return true; }static int configure_uv_feat_guest (const S390FeatBitmap features)
Signature · 1 line
2.34.1
Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean
Quoted 25 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As
error.hsuggested, the best practice for callee is to return something to indicate success / failure.So make
kvm_s390_get_host_cpu_model()return boolean and check the returned boolean inget_max_cpu_model()instead of accessing @err.Additionally, since now
get_max_cpu_model()returns directly ifkvm_s390_get_host_cpu_model()fills @err, so makekvm_s390_get_host_cpu_model()return true by default for the non-KVM case intarget/s390x/cpu_models.h.Signed-off-by Zhao Liu <[email protected]>--- target/s390x/cpu_models.c | 9 ++++----- target/s390x/cpu_models.h | 5 +++-- target/s390x/kvm/kvm.c | 13 +++++++------ 3 files changed, 14 insertions(+), 13 deletions(-)target/s390x/cpu_models.c +0
-0
target/s390x/cpu_models.c S390CPUModel *get_max_cpu_model(Error **errp) · line 562
Quoted 3 lines
target/s390x/cpu_models.c +0
-0@@ -560,16 +560,15 @@ S390CPUModel *get_max_cpu_model(Error **errp) }if (kvm_enabled ()) {
Nitpicking, we could move @err declaration here:
Error *err = NULL;
Quoted 17 lines
target/s390x/cpu_models.c +4
-5-kvm_s390_get_host_cpu_model (&max_model, &err); +if (!kvm_s390_get_host_cpu_model (&max_model, &err)) { +error_propagate (errp, err); +return NULL ; + } }else { max_model.def =s390_find_cpu_def (QEMU_MAX_CPU_TYPE ,QEMU_MAX_CPU_GEN ,QEMU_MAX_CPU_EC_GA ,NULL );bitmap_copy (max_model.features, qemu_max_cpu_feat,S390_FEAT_MAX ); } -if (err) { -error_propagate (errp, err); -return NULL ; - } cached = true;return &max_model; }
Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean
Quoted 11 lines
target/s390x/cpu_models.c S390CPUModel *get_max_cpu_model(Error **errp) · line 561
Quoted 7 lines
target/s390x/cpu_models.c +0
-0@@ -560,16 +560,15 @@ S390CPUModel *get_max_cpu_model(Error **errp) }if (kvm_enabled ()) {Nitpicking, we could move @err declaration here:
Error *err = NULL;
Yeah! Next patch removes this variable completely, so I think it's OK not to move. ;-)
Thanks,
Zhao
Quoted 18 lines
Quoted 17 lines
target/s390x/cpu_models.c +4
-5-kvm_s390_get_host_cpu_model (&max_model, &err); +if (!kvm_s390_get_host_cpu_model (&max_model, &err)) { +error_propagate (errp, err); +return NULL ; + } }else { max_model.def =s390_find_cpu_def (QEMU_MAX_CPU_TYPE ,QEMU_MAX_CPU_GEN ,QEMU_MAX_CPU_EC_GA ,NULL );bitmap_copy (max_model.features, qemu_max_cpu_feat,S390_FEAT_MAX ); } -if (err) { -error_propagate (errp, err); -return NULL ; - } cached = true;return &max_model; }
Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean
In reply to Zhao LiuQuoted 5 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As
error.hsuggested, the best practice for callee is to return something to indicate success / failure.
Quoted 7 lines
So make
kvm_s390_get_host_cpu_model()return boolean and check the returned boolean inget_max_cpu_model()instead of accessing @err.Additionally, since now
get_max_cpu_model()returns directly ifkvm_s390_get_host_cpu_model()fills @err, so makekvm_s390_get_host_cpu_model()return true by default for the non-KVM case intarget/s390x/cpu_models.h.
You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.
Quoted 7 lines
index
d7b89129891a..5041c1e10fed100644target/s390x/cpu_models.h +0
-0@@ -116,12 +116,13 @@ S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,#ifdef CONFIG_KVM bool kvm_s390_cpu_models_supported (void );
target/s390x/cpu_models.h S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga, · line 126
Quoted 10 lines
target/s390x/cpu_models.h +3
-2-void kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp); +bool kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp);void kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp);#else -static inline void kvm_s390_get_host_cpu_model (S390CPUModel *model, +static inline bool kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp) { +return true; }
Thomas
Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean
Hi Thomas,
Quoted 19 lines · Thomas Huth
Date: Fri, 19 Apr 2024 09:50:46 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model()return booleanQuoted 5 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As
error.hsuggested, the best practice for callee is to return something to indicate success / failure.Quoted 7 lines
So make
kvm_s390_get_host_cpu_model()return boolean and check the returned boolean inget_max_cpu_model()instead of accessing @err.Additionally, since now
get_max_cpu_model()returns directly ifkvm_s390_get_host_cpu_model()fills @err, so makekvm_s390_get_host_cpu_model()return true by default for the non-KVM case intarget/s390x/cpu_models.h.
Quoted 4 lines
You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.
I see, since this interface in wrapped in kvm_enabled() condition, so the non-kvm sutb wouldn't be called.
Thanks! Will change to return false.
Regards,
Zhao
Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean
Quoted 27 lines · Zhao Liu
Hi Thomas,
Quoted 19 lines · Thomas Huth
Date: Fri, 19 Apr 2024 09:50:46 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model()return booleanQuoted 5 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As
error.hsuggested, the best practice for callee is to return something to indicate success / failure.Quoted 7 lines
So make
kvm_s390_get_host_cpu_model()return boolean and check the returned boolean inget_max_cpu_model()instead of accessing @err.Additionally, since now
get_max_cpu_model()returns directly ifkvm_s390_get_host_cpu_model()fills @err, so makekvm_s390_get_host_cpu_model()return true by default for the non-KVM case intarget/s390x/cpu_models.h.Quoted 4 lines
You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.
Quoted 4 lines
I see, since this interface in wrapped in
kvm_enabled()condition, so the non-kvm sutb wouldn't be called.Thanks! Will change to return false.
Or try to rebase your series on this untested patch:
https://lore.kernel.org/qemu-devel/[email protected]/
Re: [PATCH 3/6] target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return boolean
Quoted 33 lines · Philippe Mathieu-Daudé
Date: Fri, 19 Apr 2024 11:08:22 +0200
From: Philippe Mathieu-Daudé <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model()return booleanQuoted 27 lines · Zhao Liu
Hi Thomas,
Quoted 23 lines · Thomas Huth
Date: Fri, 19 Apr 2024 09:50:46 +0200
From: Thomas Huth <[email protected]>
Subject: Re: [PATCH 3/6] target/s390x/cpu_models: Make
kvm_s390_get_host_cpu_model()return booleanQuoted 5 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As
error.hsuggested, the best practice for callee is to return something to indicate success / failure.Quoted 7 lines
So make
kvm_s390_get_host_cpu_model()return boolean and check the returned boolean inget_max_cpu_model()instead of accessing @err.Additionally, since now
get_max_cpu_model()returns directly ifkvm_s390_get_host_cpu_model()fills @err, so makekvm_s390_get_host_cpu_model()return true by default for the non-KVM case intarget/s390x/cpu_models.h.You could also argue the other way round that there should be something in *model if it returns "true" ... anyway, the stub should never be executed, so it likely doesn't matter too much, but I'd still prefer if we'd rather return "false" in the non-KVM stub instead.
Quoted 8 lines
Quoted 4 lines
I see, since this interface in wrapped in
kvm_enabled()condition, so the non-kvm sutb wouldn't be called.Thanks! Will change to return false.
Or try to rebase your series on this untested patch:
https://lore.kernel.org/qemu-devel/[email protected]/
Good, pls let me pick this patch into my v2.
PATCH 4/6 target/s390x/cpu_models: Drop local @err in get_max_cpu_model()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
Use @errp to fetech error information directly and drop the local virable @err.
--- target/s390x/cpu_models.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/cpu_models.c +1 -3
@@ -551,7 +551,6 @@ static bool check_compatibility(const S390CPUModel *max_model,S390CPUModel *get_max_cpu_model (Error **errp) { -Error *err =NULL ;static S390CPUModel max_model;static bool cached;
@@ -560,8 +559,7 @@ S390CPUModel *get_max_cpu_model(Error **errp) }if (kvm_enabled ()) { -if (!kvm_s390_get_host_cpu_model (&max_model, &err)) { -error_propagate (errp, err); +if (!kvm_s390_get_host_cpu_model (&max_model, errp)) {return NULL ; } }else {
Signature · 1 line
2.34.1
Re: [PATCH 4/6] target/s390x/cpu_models: Drop local @err in get_max_cpu_model()
Quoted 4 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Use @errp to fetech error information directly and drop the local virable @err.
Copy-n-paste of the same typos as in patch 2 ;-)
Quoted 18 lines
Signed-off-by Zhao Liu <[email protected]>--- target/s390x/cpu_models.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)target/s390x/cpu_models.c +0
-1@@ -551,7 +551,6 @@ static bool check_compatibility(const S390CPUModel *max_model,S390CPUModel *get_max_cpu_model (Error **errp) { -Error *err =NULL ;static S390CPUModel max_model;static bool cached;
target/s390x/cpu_models.c S390CPUModel *get_max_cpu_model(Error **errp) · line 565
Quoted 9 lines
target/s390x/cpu_models.c +1
-2@@ -560,8 +559,7 @@ S390CPUModel *get_max_cpu_model(Error **errp) }if (kvm_enabled ()) { -if (!kvm_s390_get_host_cpu_model (&max_model, &err)) { -error_propagate (errp, err); +if (!kvm_s390_get_host_cpu_model (&max_model, errp)) {return NULL ; } }else {
With the typos fixed:
PATCH 5/6 target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return boolean
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
As error.h suggested, the best practice for callee is to return something to indicate success / failure.
So make kvm_s390_apply_cpu_model() return boolean and check the returned boolean in apply_cpu_model() instead of accessing @err.
--- target/s390x/cpu_models.h | 5 +++-- target/s390x/cpu_models_sysemu.c | 3 +-- target/s390x/kvm/kvm.c | 15 ++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-)
target/s390x/cpu_models.h +3 -2
@@ -117,16 +117,17 @@ S390CPUDef const *s390_find_cpu_def(uint16_t type, uint8_t gen, uint8_t ec_ga,#ifdef CONFIG_KVM bool kvm_s390_cpu_models_supported (void );bool kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp); -void kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp); +bool kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp);#else static inline bool kvm_s390_get_host_cpu_model (S390CPUModel *model,Error **errp) {return true; } -static inline void kvm_s390_apply_cpu_model (const S390CPUModel *model, +static inline bool kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp) { +return true; }static inline bool kvm_s390_cpu_models_supported (void ) {
target/s390x/cpu_models_sysemu.c +1 -2
@@ -405,8 +405,7 @@ void apply_cpu_model(const S390CPUModel *model, Error **errp) }if (kvm_enabled ()) { -kvm_s390_apply_cpu_model (model, &err); -if (err) { +if (!kvm_s390_apply_cpu_model (model, &err)) {error_propagate (errp, err);return ; }
target/s390x/kvm/kvm.c +8 -7
@@ -2543,7 +2543,7 @@ static void kvm_s390_configure_apie(bool interpret) } } -void kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp) +bool kvm_s390_apply_cpu_model (const S390CPUModel *model,Error **errp) {struct kvm_s390_vm_cpu_processor prop = { .fac_list = {0 },
@@ -2560,11 +2560,11 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp)if (kvm_s390_cmma_available ()) {kvm_s390_enable_cmma (); } -return ; +return true; }if (!kvm_s390_cpu_models_supported ()) {error_setg (errp,"KVM doesn't support CPU models" ); -return ; +return false; } prop.cpuid =s390_cpuid_from_cpu_model (model); prop.ibc =s390_ibc_from_cpu_model (model);
@@ -2574,19 +2574,19 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp) rc =kvm_vm_ioctl (kvm_state,KVM_SET_DEVICE_ATTR , &attr);if (rc) {error_setg (errp,"KVM: Error configuring the CPU model: %d" , rc); -return ; +return false; }/* configure cpu features indicated e.g. via SCLP */ rc =configure_cpu_feat (model->features);if (rc) {error_setg (errp,"KVM: Error configuring CPU features: %d" , rc); -return ; +return false; }/* configure cpu subfunctions indicated via query / test bit */ rc =configure_cpu_subfunc (model->features);if (rc) {error_setg (errp,"KVM: Error configuring CPU subfunctions: %d" , rc); -return ; +return false; }/* enable CMM via CMMA */ if (test_bit (S390_FEAT_CMM , model->features)) {
@@ -2601,8 +2601,9 @@ void kvm_s390_apply_cpu_model(const S390CPUModel *model, Error **errp) rc =configure_uv_feat_guest (model->features);if (rc) {error_setg (errp,"KVM: Error configuring CPU UV features %d" , rc); -return ; +return false; } +return true; }void kvm_s390_restart_interrupt (S390CPU *cpu)
Signature · 1 line
2.34.1
Re: [PATCH 5/6] target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return boolean
Quoted 8 lines · Zhao Liu
From: Zhao Liu <[email protected]>
As
error.hsuggested, the best practice for callee is to return something to indicate success / failure.So make
kvm_s390_apply_cpu_model()return boolean and check the returned boolean inapply_cpu_model()instead of accessing @err.
Quoted 6 lines
Signed-off-by Zhao Liu <[email protected]>--- target/s390x/cpu_models.h | 5 +++-- target/s390x/cpu_models_sysemu.c | 3 +-- target/s390x/kvm/kvm.c | 15 ++++++++------- 3 files changed, 12 insertions(+), 11 deletions(-)
PATCH 6/6 target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()
In reply to Zhao LiuFrom: Zhao Liu <[email protected]>
Use @errp to fetech error information directly and drop the local virable @err.
--- target/s390x/cpu_models_sysemu.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
target/s390x/cpu_models_sysemu.c +1 -3
@@ -389,7 +389,6 @@ CpuModelBaselineInfo *qmp_query_cpu_model_baseline(CpuModelInfo *infoa,void apply_cpu_model (const S390CPUModel *model,Error **errp) { -Error *err =NULL ;static S390CPUModel applied_model;static bool applied;
@@ -405,8 +404,7 @@ void apply_cpu_model(const S390CPUModel *model, Error **errp) }if (kvm_enabled ()) { -if (!kvm_s390_apply_cpu_model (model, &err)) { -error_propagate (errp, err); +if (!kvm_s390_apply_cpu_model (model, errp)) {return ; } }
Signature · 1 line
2.34.1
Re: [PATCH 6/6] target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()
Quoted 4 lines · Zhao Liu
From: Zhao Liu <[email protected]>
Use @errp to fetech error information directly and drop the local virable @err.
With the typos fixed:
Quoted 5 lines · Zhao Liu
From: Zhao Liu <[email protected]>
---
Zhao Liu (6):
Quoted 8 lines
target/s390x/cpu_model: Make check_compatibility() return boolean
target/s390x/cpu_model: Drop local @err in s390_realize_cpu_model()
target/s390x/cpu_models: Make kvm_s390_get_host_cpu_model() return
boolean
target/s390x/cpu_models: Drop local @err in get_max_cpu_model()
target/s390x/cpu_models: Make kvm_s390_apply_cpu_model() return
boolean
target/s390x/cpu_models_sysemu: Drop local @err in apply_cpu_model()Series: