diff options
author | Souptick Joarder <jrdr.linux@gmail.com> | 2016-11-03 10:06:54 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-11-10 08:50:46 -0500 |
commit | 7f8b4ebeb2a1e7bf7af80926db012c9356f7a662 (patch) | |
tree | 16e1406251fedc28785f49d25c7c573f329d2620 /drivers/tty | |
parent | 65dabaf532ba632d3660fc7943f3fe47c7c56dc0 (diff) |
serial: ioc4_serial: Free memory when kzalloc fails during probe
Inside ioc4_attach_local() 4 memory was allocated using kzalloc and
assign it to ports[] within loop. When kzalloc fails inside loop,
it returns error without freeing previously allocated memory and we
may have memory leak. Fix this by freeing ports[] before return.
Signed-off-by: Souptick joarder <jrdr.linux@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty')
-rw-r--r-- | drivers/tty/serial/ioc4_serial.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c index e5c42fef69d2..3be051abb2a2 100644 --- a/drivers/tty/serial/ioc4_serial.c +++ b/drivers/tty/serial/ioc4_serial.c | |||
@@ -1082,7 +1082,7 @@ static int inline ioc4_attach_local(struct ioc4_driver_data *idd) | |||
1082 | if (!port) { | 1082 | if (!port) { |
1083 | printk(KERN_WARNING | 1083 | printk(KERN_WARNING |
1084 | "IOC4 serial memory not available for port\n"); | 1084 | "IOC4 serial memory not available for port\n"); |
1085 | return -ENOMEM; | 1085 | goto free; |
1086 | } | 1086 | } |
1087 | spin_lock_init(&port->ip_lock); | 1087 | spin_lock_init(&port->ip_lock); |
1088 | 1088 | ||
@@ -1190,6 +1190,11 @@ static int inline ioc4_attach_local(struct ioc4_driver_data *idd) | |||
1190 | handle_dma_error_intr, port); | 1190 | handle_dma_error_intr, port); |
1191 | } | 1191 | } |
1192 | return 0; | 1192 | return 0; |
1193 | |||
1194 | free: | ||
1195 | while (port_number) | ||
1196 | kfree(ports[--port_number]); | ||
1197 | return -ENOMEM; | ||
1193 | } | 1198 | } |
1194 | 1199 | ||
1195 | /** | 1200 | /** |