aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorInsu Yun <wuninsu@gmail.com>2015-10-17 15:25:07 -0400
committerSebastian Reichel <sre@kernel.org>2015-10-19 05:42:02 -0400
commitd2c85ac24ed7636934f469fac8836b87c7e6cb40 (patch)
treed40442df29f9704604f316735ac9f2997d4a05d6
parente74eba049356fdad6713ab66322d9aeb0e85608b (diff)
hsi: correctly handle return value of kzalloc
Since kzalloc can be failed in memory pressure, its return value should be checked and handled. Signed-off-by: Insu Yun <wuninsu@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
-rw-r--r--drivers/hsi/hsi.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/hsi/hsi.c b/drivers/hsi/hsi.c
index 35d631e91908..df380d55c58f 100644
--- a/drivers/hsi/hsi.c
+++ b/drivers/hsi/hsi.c
@@ -85,12 +85,14 @@ struct hsi_client *hsi_new_client(struct hsi_port *port,
85 85
86 cl = kzalloc(sizeof(*cl), GFP_KERNEL); 86 cl = kzalloc(sizeof(*cl), GFP_KERNEL);
87 if (!cl) 87 if (!cl)
88 return NULL; 88 goto err;
89 89
90 cl->tx_cfg = info->tx_cfg; 90 cl->tx_cfg = info->tx_cfg;
91 if (cl->tx_cfg.channels) { 91 if (cl->tx_cfg.channels) {
92 size = cl->tx_cfg.num_channels * sizeof(*cl->tx_cfg.channels); 92 size = cl->tx_cfg.num_channels * sizeof(*cl->tx_cfg.channels);
93 cl->tx_cfg.channels = kzalloc(size , GFP_KERNEL); 93 cl->tx_cfg.channels = kzalloc(size , GFP_KERNEL);
94 if (!cl->tx_cfg.channels)
95 goto err_tx;
94 memcpy(cl->tx_cfg.channels, info->tx_cfg.channels, size); 96 memcpy(cl->tx_cfg.channels, info->tx_cfg.channels, size);
95 } 97 }
96 98
@@ -98,6 +100,8 @@ struct hsi_client *hsi_new_client(struct hsi_port *port,
98 if (cl->rx_cfg.channels) { 100 if (cl->rx_cfg.channels) {
99 size = cl->rx_cfg.num_channels * sizeof(*cl->rx_cfg.channels); 101 size = cl->rx_cfg.num_channels * sizeof(*cl->rx_cfg.channels);
100 cl->rx_cfg.channels = kzalloc(size , GFP_KERNEL); 102 cl->rx_cfg.channels = kzalloc(size , GFP_KERNEL);
103 if (!cl->rx_cfg.channels)
104 goto err_rx;
101 memcpy(cl->rx_cfg.channels, info->rx_cfg.channels, size); 105 memcpy(cl->rx_cfg.channels, info->rx_cfg.channels, size);
102 } 106 }
103 107
@@ -114,6 +118,12 @@ struct hsi_client *hsi_new_client(struct hsi_port *port,
114 } 118 }
115 119
116 return cl; 120 return cl;
121err_rx:
122 kfree(cl->tx_cfg.channels);
123err_tx:
124 kfree(cl);
125err:
126 return NULL;
117} 127}
118EXPORT_SYMBOL_GPL(hsi_new_client); 128EXPORT_SYMBOL_GPL(hsi_new_client);
119 129