Skip to contentSkip to conversation

net: mscc: ocelot: null check devm_kcalloc

PATCH In review Navid Emamdoost 2 participants 2 messages Jul 25, 2019 – Jul 26, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: mscc: ocelot: null check devm_kcalloc

devm_kcalloc may fail and return NULL. Added the null check.

---
 drivers/net/ethernet/mscc/ocelot_board.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/mscc/ocelot_board.c +2 -0
index 58bde1a9eacb..52377cfdc31a 100644
@@ -257,6 +257,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 
 	ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports,
 				     sizeof(struct ocelot_port *), GFP_KERNEL);
+	if (!ocelot->ports)
+		return -ENOMEM;
 
 	INIT_LIST_HEAD(&ocelot->multicast);
 	ocelot_init(ocelot);
Signature · 1 line
2.17.1
maintainer
#1 lore raw

From: Navid Emamdoost <[email protected]>
Date: Wed, 24 Jul 2019 20:56:09 -0500

Quoted 12 lines

devm_kcalloc may fail and return NULL. Added the null check.

---
 drivers/net/ethernet/mscc/ocelot_board.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/mscc/ocelot_board.c +0 -0
index 58bde1a9eacb..52377cfdc31a 100644

drivers/net/ethernet/mscc/ocelot_board.c static int mscc_ocelot_probe(struct platform_device *pdev) · line 262

Quoted 6 lines
drivers/net/ethernet/mscc/ocelot_board.c +2 -0
@@ -257,6 +257,8 @@ static int mscc_ocelot_probe(struct platform_device *pdev)
 
 	ocelot->ports = devm_kcalloc(&pdev->dev, ocelot->num_phys_ports,
 				     sizeof(struct ocelot_port *), GFP_KERNEL);
+	if (!ocelot->ports)
+		return -ENOMEM;
 

At the very least this leaks a reference to 'ports'. I didn't check what other resources obtained by this function are leaked as well by this change, please audit before resubmitting.