diff options
author | Davidlohr Bueso <dave@gnu.org> | 2010-09-13 12:08:11 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-10-22 13:20:03 -0400 |
commit | 68707539df1e9d12435e5d54ffedc7ded50fcd01 (patch) | |
tree | 5121df6107dce229fca976f7b4d87d5ff177d4fa | |
parent | 91efa75ce14db63d1eb47a2935bc7332de243f8d (diff) |
serial: max3107: Fix memory leaks when returning on error
Fix memory leaks in max3107_probe() when returning on error.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | drivers/serial/max3107.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/drivers/serial/max3107.c b/drivers/serial/max3107.c index 67283c1a57ff..910870edf708 100644 --- a/drivers/serial/max3107.c +++ b/drivers/serial/max3107.c | |||
@@ -986,12 +986,14 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | |||
986 | s->rxbuf = kzalloc(sizeof(u16) * (MAX3107_RX_FIFO_SIZE+2), GFP_KERNEL); | 986 | s->rxbuf = kzalloc(sizeof(u16) * (MAX3107_RX_FIFO_SIZE+2), GFP_KERNEL); |
987 | if (!s->rxbuf) { | 987 | if (!s->rxbuf) { |
988 | pr_err("Allocating RX buffer failed\n"); | 988 | pr_err("Allocating RX buffer failed\n"); |
989 | return -ENOMEM; | 989 | retval = -ENOMEM; |
990 | goto err_free4; | ||
990 | } | 991 | } |
991 | s->rxstr = kzalloc(sizeof(u8) * MAX3107_RX_FIFO_SIZE, GFP_KERNEL); | 992 | s->rxstr = kzalloc(sizeof(u8) * MAX3107_RX_FIFO_SIZE, GFP_KERNEL); |
992 | if (!s->rxstr) { | 993 | if (!s->rxstr) { |
993 | pr_err("Allocating RX buffer failed\n"); | 994 | pr_err("Allocating RX buffer failed\n"); |
994 | return -ENOMEM; | 995 | retval = -ENOMEM; |
996 | goto err_free3; | ||
995 | } | 997 | } |
996 | /* SPI Tx buffer | 998 | /* SPI Tx buffer |
997 | * SPI transfer buffer | 999 | * SPI transfer buffer |
@@ -1002,7 +1004,8 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | |||
1002 | s->txbuf = kzalloc(sizeof(u16) * MAX3107_TX_FIFO_SIZE + 3, GFP_KERNEL); | 1004 | s->txbuf = kzalloc(sizeof(u16) * MAX3107_TX_FIFO_SIZE + 3, GFP_KERNEL); |
1003 | if (!s->txbuf) { | 1005 | if (!s->txbuf) { |
1004 | pr_err("Allocating TX buffer failed\n"); | 1006 | pr_err("Allocating TX buffer failed\n"); |
1005 | return -ENOMEM; | 1007 | retval = -ENOMEM; |
1008 | goto err_free2; | ||
1006 | } | 1009 | } |
1007 | /* Initialize shared data lock */ | 1010 | /* Initialize shared data lock */ |
1008 | spin_lock_init(&s->data_lock); | 1011 | spin_lock_init(&s->data_lock); |
@@ -1021,13 +1024,15 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | |||
1021 | buf[0] = MAX3107_REVID_REG; | 1024 | buf[0] = MAX3107_REVID_REG; |
1022 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) { | 1025 | if (max3107_rw(s, (u8 *)buf, (u8 *)buf, 2)) { |
1023 | dev_err(&s->spi->dev, "SPI transfer for REVID read failed\n"); | 1026 | dev_err(&s->spi->dev, "SPI transfer for REVID read failed\n"); |
1024 | return -EIO; | 1027 | retval = -EIO; |
1028 | goto err_free1; | ||
1025 | } | 1029 | } |
1026 | if ((buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID1 && | 1030 | if ((buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID1 && |
1027 | (buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID2) { | 1031 | (buf[0] & MAX3107_SPI_RX_DATA_MASK) != MAX3107_REVID2) { |
1028 | dev_err(&s->spi->dev, "REVID %x does not match\n", | 1032 | dev_err(&s->spi->dev, "REVID %x does not match\n", |
1029 | (buf[0] & MAX3107_SPI_RX_DATA_MASK)); | 1033 | (buf[0] & MAX3107_SPI_RX_DATA_MASK)); |
1030 | return -ENODEV; | 1034 | retval = -ENODEV; |
1035 | goto err_free1; | ||
1031 | } | 1036 | } |
1032 | 1037 | ||
1033 | /* Disable all interrupts */ | 1038 | /* Disable all interrupts */ |
@@ -1047,7 +1052,8 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | |||
1047 | /* Perform SPI transfer */ | 1052 | /* Perform SPI transfer */ |
1048 | if (max3107_rw(s, (u8 *)buf, NULL, 4)) { | 1053 | if (max3107_rw(s, (u8 *)buf, NULL, 4)) { |
1049 | dev_err(&s->spi->dev, "SPI transfer for init failed\n"); | 1054 | dev_err(&s->spi->dev, "SPI transfer for init failed\n"); |
1050 | return -EIO; | 1055 | retval = -EIO; |
1056 | goto err_free1; | ||
1051 | } | 1057 | } |
1052 | 1058 | ||
1053 | /* Register UART driver */ | 1059 | /* Register UART driver */ |
@@ -1055,7 +1061,7 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | |||
1055 | retval = uart_register_driver(&max3107_uart_driver); | 1061 | retval = uart_register_driver(&max3107_uart_driver); |
1056 | if (retval) { | 1062 | if (retval) { |
1057 | dev_err(&s->spi->dev, "Registering UART driver failed\n"); | 1063 | dev_err(&s->spi->dev, "Registering UART driver failed\n"); |
1058 | return retval; | 1064 | goto err_free1; |
1059 | } | 1065 | } |
1060 | driver_registered = 1; | 1066 | driver_registered = 1; |
1061 | } | 1067 | } |
@@ -1074,13 +1080,13 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | |||
1074 | retval = uart_add_one_port(&max3107_uart_driver, &s->port); | 1080 | retval = uart_add_one_port(&max3107_uart_driver, &s->port); |
1075 | if (retval < 0) { | 1081 | if (retval < 0) { |
1076 | dev_err(&s->spi->dev, "Adding UART port failed\n"); | 1082 | dev_err(&s->spi->dev, "Adding UART port failed\n"); |
1077 | return retval; | 1083 | goto err_free1; |
1078 | } | 1084 | } |
1079 | 1085 | ||
1080 | if (pdata->configure) { | 1086 | if (pdata->configure) { |
1081 | retval = pdata->configure(s); | 1087 | retval = pdata->configure(s); |
1082 | if (retval < 0) | 1088 | if (retval < 0) |
1083 | return retval; | 1089 | goto err_free1; |
1084 | } | 1090 | } |
1085 | 1091 | ||
1086 | /* Go to suspend mode */ | 1092 | /* Go to suspend mode */ |
@@ -1088,6 +1094,16 @@ int max3107_probe(struct spi_device *spi, struct max3107_plat *pdata) | |||
1088 | pdata->hw_suspend(s, 1); | 1094 | pdata->hw_suspend(s, 1); |
1089 | 1095 | ||
1090 | return 0; | 1096 | return 0; |
1097 | |||
1098 | err_free1: | ||
1099 | kfree(s->txbuf); | ||
1100 | err_free2: | ||
1101 | kfree(s->rxstr); | ||
1102 | err_free3: | ||
1103 | kfree(s->rxbuf); | ||
1104 | err_free4: | ||
1105 | kfree(s); | ||
1106 | return retval; | ||
1091 | } | 1107 | } |
1092 | EXPORT_SYMBOL_GPL(max3107_probe); | 1108 | EXPORT_SYMBOL_GPL(max3107_probe); |
1093 | 1109 | ||