Skip to content

Commit

Permalink
serial: vt8500: fix possible memory leak in vt8500_serial_probe()
Browse files Browse the repository at this point in the history
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.
Fix it by move the allocation of vt8500_port after those test.

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

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
Acked-by: Tony Prisk <linux@prisktech.co.nz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Wei Yongjun authored and Greg Kroah-Hartman committed Oct 24, 2012
1 parent 54ec52b commit 59c2e85
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/tty/serial/vt8500_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,6 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev)
if (!mmres || !irqres)
return -ENODEV;

vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL);
if (!vt8500_port)
return -ENOMEM;

if (np)
port = of_alias_get_id(np, "serial");
if (port > VT8500_MAX_PORTS)
Expand All @@ -593,6 +589,10 @@ static int __devinit vt8500_serial_probe(struct platform_device *pdev)
return -EBUSY;
}

vt8500_port = kzalloc(sizeof(struct vt8500_port), GFP_KERNEL);
if (!vt8500_port)
return -ENOMEM;

vt8500_port->uart.type = PORT_VT8500;
vt8500_port->uart.iotype = UPIO_MEM;
vt8500_port->uart.mapbase = mmres->start;
Expand Down

0 comments on commit 59c2e85

Please sign in to comment.