diff mbox

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

Message ID 20170317204113.GA16505@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter March 17, 2017, 8:41 p.m. UTC
kzalloc() won't actually fail because sizeof(*resize) is small, but
static checkers complain.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

David Gibson March 20, 2017, 4:20 a.m. UTC | #1
On Fri, Mar 17, 2017 at 11:41:14PM +0300, Dan Carpenter wrote:
> kzalloc() won't actually fail because sizeof(*resize) is small, but
> static checkers complain.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Oops, that's an embarrassing mistake.

Acked-by: David Gibson <david@gibson.dropbear.id.au>

> 
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 8c68145ba1bd..710e491206ed 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -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);
>
diff mbox

Patch

diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
index 8c68145ba1bd..710e491206ed 100644
--- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
+++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
@@ -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);