linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: vt8500: fix possible memory leak in vt8500_serial_probe()
@ 2012-10-08  0:47 Wei Yongjun
  2012-10-08  1:03 ` Tony Prisk
  0 siblings, 1 reply; 2+ messages in thread
From: Wei Yongjun @ 2012-10-08  0:47 UTC (permalink / raw)
  To: linux-arm-kernel

From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

vt8500_port is malloced in vt8500_serial_probe() and should be freed
before leaving from the error handling cases, otherwise it will
cause memory leak.

dpatch engine is used to auto generate this patch.
(https://github.com/weiyj/dpatch)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 drivers/tty/serial/vt8500_serial.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
index 205d4cf..43fc369 100644
--- a/drivers/tty/serial/vt8500_serial.c
+++ b/drivers/tty/serial/vt8500_serial.c
@@ -584,13 +584,16 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev)
 					sizeof(vt8500_ports_in_use));
 	}
 
-	if (port > VT8500_MAX_PORTS)
-		return -ENODEV;
+	if (port > VT8500_MAX_PORTS) {
+		ret = -ENODEV;
+		goto err;
+	}
 
 	/* reserve the port id */
 	if (test_and_set_bit(port, &vt8500_ports_in_use)) {
 		/* port already in use - shouldn't really happen */
-		return -EBUSY;
+		ret = -EBUSY;
+		goto err;
 	}
 
 	vt8500_port->uart.type = PORT_VT8500;

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

* [PATCH] serial: vt8500: fix possible memory leak in vt8500_serial_probe()
  2012-10-08  0:47 [PATCH] serial: vt8500: fix possible memory leak in vt8500_serial_probe() Wei Yongjun
@ 2012-10-08  1:03 ` Tony Prisk
  0 siblings, 0 replies; 2+ messages in thread
From: Tony Prisk @ 2012-10-08  1:03 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, 2012-10-08 at 08:47 +0800, Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> vt8500_port is malloced in vt8500_serial_probe() and should be freed
> before leaving from the error handling cases, otherwise it will
> cause memory leak.
> 
> dpatch engine is used to auto generate this patch.
> (https://github.com/weiyj/dpatch)
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
>  drivers/tty/serial/vt8500_serial.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/vt8500_serial.c b/drivers/tty/serial/vt8500_serial.c
> index 205d4cf..43fc369 100644
> --- a/drivers/tty/serial/vt8500_serial.c
> +++ b/drivers/tty/serial/vt8500_serial.c
> @@ -584,13 +584,16 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev)
>  					sizeof(vt8500_ports_in_use));
>  	}
>  
> -	if (port > VT8500_MAX_PORTS)
> -		return -ENODEV;
> +	if (port > VT8500_MAX_PORTS) {
> +		ret = -ENODEV;
> +		goto err;
> +	}
>  
>  	/* reserve the port id */
>  	if (test_and_set_bit(port, &vt8500_ports_in_use)) {
>  		/* port already in use - shouldn't really happen */
> -		return -EBUSY;
> +		ret = -EBUSY;
> +		goto err;
>  	}
>  
>  	vt8500_port->uart.type = PORT_VT8500;
> 

You are correct - this is an error but wouldn't it be better to simply
move the allocation of vt8500_port after these test since it's not used
until later.

It would save two possible instances of having to alloc/release a block
of memory that is never used and possibly create unnecessary memory
fragmentation.

Either way, this patch fixes the problem, so you can add my Ack'd if my
suggestion is considered nit-picky.

Acked-by: Tony Prisk <linux@prisktech.co.nz>


Regards
Tony P

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

end of thread, other threads:[~2012-10-08  1:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-08  0:47 [PATCH] serial: vt8500: fix possible memory leak in vt8500_serial_probe() Wei Yongjun
2012-10-08  1:03 ` Tony Prisk

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