diff options
| author | Insu Yun <wuninsu@gmail.com> | 2015-10-17 15:25:07 -0400 |
|---|---|---|
| committer | Sebastian Reichel <sre@kernel.org> | 2015-10-19 05:42:02 -0400 |
| commit | d2c85ac24ed7636934f469fac8836b87c7e6cb40 (patch) | |
| tree | d40442df29f9704604f316735ac9f2997d4a05d6 /drivers/hsi | |
| parent | e74eba049356fdad6713ab66322d9aeb0e85608b (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>
Diffstat (limited to 'drivers/hsi')
| -rw-r--r-- | drivers/hsi/hsi.c | 12 |
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; |
| 121 | err_rx: | ||
| 122 | kfree(cl->tx_cfg.channels); | ||
| 123 | err_tx: | ||
| 124 | kfree(cl); | ||
| 125 | err: | ||
| 126 | return NULL; | ||
| 117 | } | 127 | } |
| 118 | EXPORT_SYMBOL_GPL(hsi_new_client); | 128 | EXPORT_SYMBOL_GPL(hsi_new_client); |
| 119 | 129 | ||
