kvmppc_vcore_create() can fail and return NULL, this patch fixes the
error handling when this happens.

vcore and online_vcores count should only be updated when vcore was
actually created, otherwise it's state gets messed up for the VM run.

Signed-off-by: Ritesh Harjani (IBM) <[email protected]>
---
 arch/powerpc/kvm/book3s_hv.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 22283d46e8fe..e39491dfb975 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -3090,10 +3090,12 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu 
*vcpu)
                        err = -ENOMEM;
                        vcore = kvmppc_vcore_create(kvm,
                                        id & ~(kvm->arch.smt_mode - 1));
-                       mutex_lock(&kvm->arch.mmu_setup_lock);
-                       kvm->arch.vcores[core] = vcore;
-                       kvm->arch.online_vcores++;
-                       mutex_unlock(&kvm->arch.mmu_setup_lock);
+                       if (vcore) {
+                               mutex_lock(&kvm->arch.mmu_setup_lock);
+                               kvm->arch.vcores[core] = vcore;
+                               kvm->arch.online_vcores++;
+                               mutex_unlock(&kvm->arch.mmu_setup_lock);
+                       }
                }
        }
 
-- 
2.39.5


Reply via email to