[PATCH v1] phy: tegra: xusb: Check for NULL return of devm_kzalloc()

QintaoShen posted 1 patch 4 years, 2 months ago
drivers/phy/tegra/xusb.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH v1] phy: tegra: xusb: Check for NULL return of devm_kzalloc()
Posted by QintaoShen 4 years, 2 months ago
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().

Signed-off-by: QintaoShen <unSimple1993@163.com>
---
 drivers/phy/tegra/xusb.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index aa5237e..f32b3cf 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -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,
-- 
2.7.4