Skip to contentSkip to conversation

KVM: PPC: Fix error return code in kvm_vm_ioctl_create_spapr_tce()

PATCH Superseded Wei Yongjun 2 participants 3 messages Feb 7, 2017 – Feb 8, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: PPC: Fix error return code in kvm_vm_ioctl_create_spapr_tce()

From: Wei Yongjun <[email protected]>

Fix to return error code -ENOMEM from the memory alloc error handling case instead of 0, as done elsewhere in this function.

---
 arch/powerpc/kvm/book3s_64_vio.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_64_vio.c +6 -2
index d71f872..8a4a3f0 100644
@@ -173,8 +173,10 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
 
 	stt = kzalloc(sizeof(*stt) + npages * sizeof(struct page *),
 		      GFP_KERNEL);
-	if (!stt)
+	if (!stt) {
+		ret = -ENOMEM;
 		goto fail;
+	}
 
 	stt->liobn = args->liobn;
 	stt->page_shift = args->page_shift;
@@ -184,8 +186,10 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
 
 	for (i = 0; i < npages; i++) {
 		stt->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO);
-		if (!stt->pages[i])
+		if (!stt->pages[i]) {
+			ret = -ENOMEM;
 			goto fail;
+		}
 	}
 
 	kvm_get_kvm(kvm);
#1 lore raw
Quoted 15 lines · Wei Yongjun

From: Wei Yongjun <[email protected]>

Fix to return error code -ENOMEM from the memory alloc error handling case instead of 0, as done elsewhere in this function.

---
 arch/powerpc/kvm/book3s_64_vio.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/powerpc/kvm/book3s_64_vio.c +0 -0
index d71f872..8a4a3f0 100644

arch/powerpc/kvm/book3s_64_vio.c long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, · line 178

Quoted 7 lines
arch/powerpc/kvm/book3s_64_vio.c +2 -1
@@ -173,8 +173,10 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
 
 	stt = kzalloc(sizeof(*stt) + npages * sizeof(struct page *),
 		      GFP_KERNEL);
-	if (!stt)
+	if (!stt) {
+		ret = -ENOMEM;
 		goto fail;

I think it would be better to set ret unconditionally to -ENOMEM before the if; that would save you one line here and make the second hunk unnecessary.

Quoted 6 lines
arch/powerpc/kvm/book3s_64_vio.c +1 -0
+	}
 
 	stt->liobn = args->liobn;
 	stt->page_shift = args->page_shift;
@@ -184,8 +186,10 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
 

arch/powerpc/kvm/book3s_64_vio.c long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm, · line 195

Quoted 10 lines
arch/powerpc/kvm/book3s_64_vio.c +3 -1
 	for (i = 0; i < npages; i++) {
 		stt->pages[i] = alloc_page(GFP_KERNEL | __GFP_ZERO);
-		if (!stt->pages[i])
+		if (!stt->pages[i]) {
+			ret = -ENOMEM;
 			goto fail;
+		}
 	}
 
 	kvm_get_kvm(kvm);

Paul.

#2 lore raw

PATCH v2 1/1 KVM: PPC: fix error return code in kvm_vm_ioctl_create_spapr_tce()

In reply to Wei Yongjun

From: Wei Yongjun <[email protected]>

Fix to return error code -ENOMEM from the memory alloc error handling case instead of 0, as done elsewhere in this function.

---
 arch/powerpc/kvm/book3s_64_vio.c | 1 +
 1 file changed, 1 insertion(+)
arch/powerpc/kvm/book3s_64_vio.c +1 -0
index d71f872..ab9d14c 100644
@@ -171,6 +171,7 @@ long kvm_vm_ioctl_create_spapr_tce(struct kvm *kvm,
 		goto fail;
 	}
 
+	ret = -ENOMEM;
 	stt = kzalloc(sizeof(*stt) + npages * sizeof(struct page *),
 		      GFP_KERNEL);
 	if (!stt)