kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path
@ 2021-05-09  8:28 Christophe JAILLET
  2021-05-13 14:19 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2021-05-09  8:28 UTC (permalink / raw)
  To: gregkh, hjk, jirislaby, lee.jones
  Cc: linux-serial, linux-kernel, kernel-janitors, Christophe JAILLET

In the probe function, if the final 'serial_config()' fails, 'info' is
leaking.

Use 'devm_kzalloc' instead to fix the leak and simplify the .remove
function.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
I've not been able to find a Fixes tag. All I know is that it is old!
---
 drivers/tty/serial/8250/serial_cs.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/tty/serial/8250/serial_cs.c b/drivers/tty/serial/8250/serial_cs.c
index 63ea9c4da3d5..d18c98e0d0b0 100644
--- a/drivers/tty/serial/8250/serial_cs.c
+++ b/drivers/tty/serial/8250/serial_cs.c
@@ -310,7 +310,7 @@ static int serial_probe(struct pcmcia_device *link)
 	dev_dbg(&link->dev, "serial_attach()\n");
 
 	/* Create new serial device */
-	info = kzalloc(sizeof(*info), GFP_KERNEL);
+	info = devm_kzalloc(&link->dev, sizeof(*info), GFP_KERNEL);
 	if (!info)
 		return -ENOMEM;
 	info->p_dev = link;
@@ -325,17 +325,12 @@ static int serial_probe(struct pcmcia_device *link)
 
 static void serial_detach(struct pcmcia_device *link)
 {
-	struct serial_info *info = link->priv;
-
 	dev_dbg(&link->dev, "serial_detach\n");
 
 	/*
 	 * Ensure that the ports have been released.
 	 */
 	serial_remove(link);
-
-	/* free bits */
-	kfree(info);
 }
 
 /*====================================================================*/
-- 
2.30.2


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

* Re: [PATCH] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path
  2021-05-09  8:28 [PATCH] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path Christophe JAILLET
@ 2021-05-13 14:19 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2021-05-13 14:19 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: hjk, jirislaby, lee.jones, linux-serial, linux-kernel, kernel-janitors

On Sun, May 09, 2021 at 10:28:18AM +0200, Christophe JAILLET wrote:
> In the probe function, if the final 'serial_config()' fails, 'info' is
> leaking.
> 
> Use 'devm_kzalloc' instead to fix the leak and simplify the .remove
> function.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> I've not been able to find a Fixes tag. All I know is that it is old!
> ---
>  drivers/tty/serial/8250/serial_cs.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/serial_cs.c b/drivers/tty/serial/8250/serial_cs.c
> index 63ea9c4da3d5..d18c98e0d0b0 100644
> --- a/drivers/tty/serial/8250/serial_cs.c
> +++ b/drivers/tty/serial/8250/serial_cs.c
> @@ -310,7 +310,7 @@ static int serial_probe(struct pcmcia_device *link)
>  	dev_dbg(&link->dev, "serial_attach()\n");
>  
>  	/* Create new serial device */
> -	info = kzalloc(sizeof(*info), GFP_KERNEL);
> +	info = devm_kzalloc(&link->dev, sizeof(*info), GFP_KERNEL);

Ick, let's not mix and only use some devm_ calls here, why not just fix
it up and free it in the error path?


thanks,

greg k-h

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

end of thread, other threads:[~2021-05-13 14:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-09  8:28 [PATCH] tty: serial: 8250: serial_cs: Fix a memory leak in error handling path Christophe JAILLET
2021-05-13 14:19 ` Greg KH

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).