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 <[email protected]>
---
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