Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2c85ac2 authored by Insu Yun's avatar Insu Yun Committed by Sebastian Reichel
Browse files

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: default avatarInsu Yun <wuninsu@gmail.com>
Signed-off-by: default avatarSebastian Reichel <sre@kernel.org>
parent e74eba04
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -85,12 +85,14 @@ struct hsi_client *hsi_new_client(struct hsi_port *port,

	cl = kzalloc(sizeof(*cl), GFP_KERNEL);
	if (!cl)
		return NULL;
		goto err;

	cl->tx_cfg = info->tx_cfg;
	if (cl->tx_cfg.channels) {
		size = cl->tx_cfg.num_channels * sizeof(*cl->tx_cfg.channels);
		cl->tx_cfg.channels = kzalloc(size , GFP_KERNEL);
		if (!cl->tx_cfg.channels)
			goto err_tx;
		memcpy(cl->tx_cfg.channels, info->tx_cfg.channels, size);
	}

@@ -98,6 +100,8 @@ struct hsi_client *hsi_new_client(struct hsi_port *port,
	if (cl->rx_cfg.channels) {
		size = cl->rx_cfg.num_channels * sizeof(*cl->rx_cfg.channels);
		cl->rx_cfg.channels = kzalloc(size , GFP_KERNEL);
		if (!cl->rx_cfg.channels)
			goto err_rx;
		memcpy(cl->rx_cfg.channels, info->rx_cfg.channels, size);
	}

@@ -114,6 +118,12 @@ struct hsi_client *hsi_new_client(struct hsi_port *port,
	}

	return cl;
err_rx:
	kfree(cl->tx_cfg.channels);
err_tx:
	kfree(cl);
err:
	return NULL;
}
EXPORT_SYMBOL_GPL(hsi_new_client);