Skip to contentSkip to conversation

KVM: PPC: Book3S HV: check for kmalloc errors in ioctl

PATCH In review Dan Carpenter 2 participants 2 messages Mar 17, 2017 – Mar 20, 2017

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

PATCH 1/1 KVM: PPC: Book3S HV: check for kmalloc errors in ioctl

kzalloc() won't actually fail because sizeof(*resize) is small, but static checkers complain.

arch/powerpc/kvm/book3s_64_mmu_hv.c +4 -0
index 8c68145ba1bd..710e491206ed 100644
@@ -1487,6 +1487,10 @@ long kvm_vm_ioctl_resize_hpt_prepare(struct kvm *kvm,
 	/* start new resize */
 
 	resize = kzalloc(sizeof(*resize), GFP_KERNEL);
+	if (!resize) {
+		ret = -ENOMEM;
+		goto out;
+	}
 	resize->order = shift;
 	resize->kvm = kvm;
 	INIT_WORK(&resize->work, resize_hpt_prepare_work);
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dan Carpenter

kzalloc() won't actually fail because sizeof(*resize) is small, but static checkers complain.

Oops, that's an embarrassing mistake.

Quoted 17 lines
arch/powerpc/kvm/book3s_64_mmu_hv.c +4 -0
index 8c68145ba1bd..710e491206ed 100644
@@ -1487,6 +1487,10 @@ long kvm_vm_ioctl_resize_hpt_prepare(struct kvm *kvm,
 	/* start new resize */
 
 	resize = kzalloc(sizeof(*resize), GFP_KERNEL);
+	if (!resize) {
+		ret = -ENOMEM;
+		goto out;
+	}
 	resize->order = shift;
 	resize->kvm = kvm;
 	INIT_WORK(&resize->work, resize_hpt_prepare_work);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson