linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: vt: keyboard: Free dynamic-memory only if kmalloc'ed.
@ 2021-11-06  9:32 Ajay Garg
  2021-11-06  9:41 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Ajay Garg @ 2021-11-06  9:32 UTC (permalink / raw)
  To: linux-serial, linux-kernel; +Cc: Ajay Garg

In "vt_do_kdgkb_ioctl", kbs is kmalloced, if cmd is one of
KDGKBSENT or KDGSKBSENT.

If cmd is none of the above, no kbs is kmalloced, and thus,
kbs must only be kfreed if it is really kmalloced.

Signed-off-by: Ajay Garg <ajaygargnsit@gmail.com>
---
 drivers/tty/vt/keyboard.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index dfef7de8a057..95839987c79c 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -2049,7 +2049,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
 {
 	unsigned char kb_func;
 	unsigned long flags;
-	char *kbs;
+	char *kbs = NULL;
 	int ret;
 
 	if (get_user(kb_func, &user_kdgkb->kb_func))
@@ -2092,7 +2092,8 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
 		break;
 	}
 
-	kfree(kbs);
+        if(kbs)
+            kfree(kbs);
 
 	return ret;
 }
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] tty: vt: keyboard: Free dynamic-memory only if kmalloc'ed.
  2021-11-06  9:32 [PATCH] tty: vt: keyboard: Free dynamic-memory only if kmalloc'ed Ajay Garg
@ 2021-11-06  9:41 ` Greg KH
  2021-11-06 10:43   ` Ajay Garg
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2021-11-06  9:41 UTC (permalink / raw)
  To: Ajay Garg; +Cc: linux-serial, linux-kernel

On Sat, Nov 06, 2021 at 03:02:02PM +0530, Ajay Garg wrote:
> In "vt_do_kdgkb_ioctl", kbs is kmalloced, if cmd is one of
> KDGKBSENT or KDGSKBSENT.
> 
> If cmd is none of the above, no kbs is kmalloced, and thus,
> kbs must only be kfreed if it is really kmalloced.
> 
> Signed-off-by: Ajay Garg <ajaygargnsit@gmail.com>
> ---
>  drivers/tty/vt/keyboard.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> index dfef7de8a057..95839987c79c 100644
> --- a/drivers/tty/vt/keyboard.c
> +++ b/drivers/tty/vt/keyboard.c
> @@ -2049,7 +2049,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
>  {
>  	unsigned char kb_func;
>  	unsigned long flags;
> -	char *kbs;
> +	char *kbs = NULL;
>  	int ret;
>  
>  	if (get_user(kb_func, &user_kdgkb->kb_func))
> @@ -2092,7 +2092,8 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
>  		break;
>  	}
>  
> -	kfree(kbs);
> +        if(kbs)
> +            kfree(kbs);
>  
>  	return ret;
>  }
> -- 
> 2.30.2
> 


Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch contains warnings and/or errors noticed by the
  scripts/checkpatch.pl tool.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] tty: vt: keyboard: Free dynamic-memory only if kmalloc'ed.
  2021-11-06  9:41 ` Greg KH
@ 2021-11-06 10:43   ` Ajay Garg
  0 siblings, 0 replies; 3+ messages in thread
From: Ajay Garg @ 2021-11-06 10:43 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-serial, linux-kernel

Thanks, will ensure that I run scripts/checkpatch.pl before posting
any patch from now on.

The v2 patch is posted at :
https://lore.kernel.org/linux-serial/20211106104053.98761-1-ajaygargnsit@gmail.com/T/#u

On Sat, Nov 6, 2021 at 3:11 PM Greg KH <gregkh@linuxfoundation.org> wrote:
>
> On Sat, Nov 06, 2021 at 03:02:02PM +0530, Ajay Garg wrote:
> > In "vt_do_kdgkb_ioctl", kbs is kmalloced, if cmd is one of
> > KDGKBSENT or KDGSKBSENT.
> >
> > If cmd is none of the above, no kbs is kmalloced, and thus,
> > kbs must only be kfreed if it is really kmalloced.
> >
> > Signed-off-by: Ajay Garg <ajaygargnsit@gmail.com>
> > ---
> >  drivers/tty/vt/keyboard.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
> > index dfef7de8a057..95839987c79c 100644
> > --- a/drivers/tty/vt/keyboard.c
> > +++ b/drivers/tty/vt/keyboard.c
> > @@ -2049,7 +2049,7 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
> >  {
> >       unsigned char kb_func;
> >       unsigned long flags;
> > -     char *kbs;
> > +     char *kbs = NULL;
> >       int ret;
> >
> >       if (get_user(kb_func, &user_kdgkb->kb_func))
> > @@ -2092,7 +2092,8 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
> >               break;
> >       }
> >
> > -     kfree(kbs);
> > +        if(kbs)
> > +            kfree(kbs);
> >
> >       return ret;
> >  }
> > --
> > 2.30.2
> >
>
>
> Hi,
>
> This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
> a patch that has triggered this response.  He used to manually respond
> to these common problems, but in order to save his sanity (he kept
> writing the same thing over and over, yet to different people), I was
> created.  Hopefully you will not take offence and will fix the problem
> in your patch and resubmit it so that it can be accepted into the Linux
> kernel tree.
>
> You are receiving this message because of the following common error(s)
> as indicated below:
>
> - Your patch contains warnings and/or errors noticed by the
>   scripts/checkpatch.pl tool.
>
> If you wish to discuss this problem further, or you have questions about
> how to resolve this issue, please feel free to respond to this email and
> Greg will reply once he has dug out from the pending patches received
> from other developers.
>
> thanks,
>
> greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-06 10:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-06  9:32 [PATCH] tty: vt: keyboard: Free dynamic-memory only if kmalloc'ed Ajay Garg
2021-11-06  9:41 ` Greg KH
2021-11-06 10:43   ` Ajay Garg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).