Skip to contentSkip to conversation

phy: tegra: xusb: Check for NULL return of devm_kzalloc()

PATCH New QintaoShen 1 participant 1 message Mar 24, 2022

Subsystems (3)
lore
Share & tools
lore

QintaoShen

author
#0 lore raw

PATCH 1/1 phy: tegra: xusb: Check for NULL return of devm_kzalloc()

The allocation of devm_kzalloc() may return a NULL pointer, can cause a NULL-pointer dereference in the follow lines of code.

To avoid this, it is better to check the return value of devm_kzalloc().

---
 drivers/phy/tegra/xusb.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/phy/tegra/xusb.c +3 -0
index aa5237e..f32b3cf 100644
@@ -668,6 +668,9 @@ static int tegra_xusb_setup_usb_role_switch(struct tegra_xusb_port *port)
 	port->dev.driver = devm_kzalloc(&port->dev,
 					sizeof(struct device_driver),
 					GFP_KERNEL);
+	if (!port->dev.driver)
+		return -ENOMEM;
+
 	port->dev.driver->owner	 = THIS_MODULE;
 
 	port->usb_role_sw = usb_role_switch_register(&port->dev,
Signature · 1 line
2.7.4