Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Insu Yun and committed by
Sebastian Reichel
d2c85ac2 e74eba04

+11 -1
+11 -1
drivers/hsi/hsi.c
··· 85 85 86 86 cl = kzalloc(sizeof(*cl), GFP_KERNEL); 87 87 if (!cl) 88 - return NULL; 88 + goto err; 89 89 90 90 cl->tx_cfg = info->tx_cfg; 91 91 if (cl->tx_cfg.channels) { 92 92 size = cl->tx_cfg.num_channels * sizeof(*cl->tx_cfg.channels); 93 93 cl->tx_cfg.channels = kzalloc(size , GFP_KERNEL); 94 + if (!cl->tx_cfg.channels) 95 + goto err_tx; 94 96 memcpy(cl->tx_cfg.channels, info->tx_cfg.channels, size); 95 97 } 96 98 ··· 100 98 if (cl->rx_cfg.channels) { 101 99 size = cl->rx_cfg.num_channels * sizeof(*cl->rx_cfg.channels); 102 100 cl->rx_cfg.channels = kzalloc(size , GFP_KERNEL); 101 + if (!cl->rx_cfg.channels) 102 + goto err_rx; 103 103 memcpy(cl->rx_cfg.channels, info->rx_cfg.channels, size); 104 104 } 105 105 ··· 118 114 } 119 115 120 116 return cl; 117 + err_rx: 118 + kfree(cl->tx_cfg.channels); 119 + err_tx: 120 + kfree(cl); 121 + err: 122 + return NULL; 121 123 } 122 124 EXPORT_SYMBOL_GPL(hsi_new_client); 123 125