[PATCH 06/29] reset: mediatek: check malloc return valaue before use

Weijie Gao weijie.gao at mediatek.com
Wed Jul 19 11:16:11 CEST 2023


This patch add missing return value check for allocating the driver's
private data. -ENOMEM will be returned if malloc() fails.

Signed-off-by: Sam Shih <sam.shih at mediatek.com>
Signed-off-by: Weijie Gao <weijie.gao at mediatek.com>
---
 drivers/reset/reset-mediatek.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/reset/reset-mediatek.c b/drivers/reset/reset-mediatek.c
index 8b62d91777..97ed221f73 100644
--- a/drivers/reset/reset-mediatek.c
+++ b/drivers/reset/reset-mediatek.c
@@ -79,6 +79,9 @@ int mediatek_reset_bind(struct udevice *pdev, u32 regofs, u32 num_regs)
 		return ret;
 
 	priv = malloc(sizeof(struct mediatek_reset_priv));
+	if (!priv)
+		return -ENOMEM;
+
 	priv->regofs = regofs;
 	priv->nr_resets = num_regs * 32;
 	dev_set_priv(rst_dev, priv);
-- 
2.17.1



More information about the U-Boot mailing list