diff mbox series

x86: kvm: remove NULL check before kfree

Message ID 20220614085035.122521-1-dzm91@hust.edu.cn (mailing list archive)
State New, archived
Headers show
Series x86: kvm: remove NULL check before kfree | expand

Commit Message

Dongliang Mu June 14, 2022, 8:50 a.m. UTC
From: mudongliang <mudongliangabcd@gmail.com>

kfree can handle NULL pointer as its argument.
According to coccinelle isnullfree check, remove NULL check
before kfree operation.

Signed-off-by: mudongliang <mudongliangabcd@gmail.com>
---
 arch/x86/kernel/kvm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Vitaly Kuznetsov June 14, 2022, 12:01 p.m. UTC | #1
Dongliang Mu <dzm91@hust.edu.cn> writes:

> From: mudongliang <mudongliangabcd@gmail.com>
>
> kfree can handle NULL pointer as its argument.
> According to coccinelle isnullfree check, remove NULL check
> before kfree operation.
>
> Signed-off-by: mudongliang <mudongliangabcd@gmail.com>
> ---
>  arch/x86/kernel/kvm.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> index 1a3658f7e6d9..d4e48b4a438b 100644
> --- a/arch/x86/kernel/kvm.c
> +++ b/arch/x86/kernel/kvm.c
> @@ -236,8 +236,7 @@ void kvm_async_pf_task_wake(u32 token)
>  	raw_spin_unlock(&b->lock);
>  
>  	/* A dummy token might be allocated and ultimately not used.  */
> -	if (dummy)
> -		kfree(dummy);
> +	kfree(dummy);
>  }
>  EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Dongliang Mu June 14, 2022, 1:36 p.m. UTC | #2
On Tue, Jun 14, 2022 at 8:01 PM Vitaly Kuznetsov <vkuznets@redhat.com> wrote:
>
> Dongliang Mu <dzm91@hust.edu.cn> writes:
>
> > From: mudongliang <mudongliangabcd@gmail.com>
> >
> > kfree can handle NULL pointer as its argument.
> > According to coccinelle isnullfree check, remove NULL check
> > before kfree operation.
> >
> > Signed-off-by: mudongliang <mudongliangabcd@gmail.com>
> > ---
> >  arch/x86/kernel/kvm.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
> > index 1a3658f7e6d9..d4e48b4a438b 100644
> > --- a/arch/x86/kernel/kvm.c
> > +++ b/arch/x86/kernel/kvm.c
> > @@ -236,8 +236,7 @@ void kvm_async_pf_task_wake(u32 token)
> >       raw_spin_unlock(&b->lock);
> >
> >       /* A dummy token might be allocated and ultimately not used.  */
> > -     if (dummy)
> > -             kfree(dummy);
> > +     kfree(dummy);
> >  }
> >  EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);
>
> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

Thanks for your review. My signature seems with an incorrect format,
so I send a v2 patch.


>
> --
> Vitaly
>
diff mbox series

Patch

diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 1a3658f7e6d9..d4e48b4a438b 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -236,8 +236,7 @@  void kvm_async_pf_task_wake(u32 token)
 	raw_spin_unlock(&b->lock);
 
 	/* A dummy token might be allocated and ultimately not used.  */
-	if (dummy)
-		kfree(dummy);
+	kfree(dummy);
 }
 EXPORT_SYMBOL_GPL(kvm_async_pf_task_wake);