2022-07-23 03:56:00

by williamsukatube

[permalink] [raw]
Subject: [PATCH] phy: tegra: xusb: check the return value of devm_kzalloc() in tegra_xusb_setup_usb_role_switch()

From: William Dean <[email protected]>

The function devm_kzalloc() in tegra_xusb_setup_usb_role_switch()
can fail, so its return value should be checked.

Fixes: f67213cee2b35 ("phy: tegra: xusb: Add usb-role-switch support")
Reported-by: Hacash Robot <[email protected]>
Signed-off-by: William Dean <[email protected]>
---
drivers/phy/tegra/xusb.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index aa5237eacd29..e3611fb4c779 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -668,6 +668,8 @@ 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.25.1


2022-08-30 08:06:50

by Vinod Koul

[permalink] [raw]
Subject: Re: [PATCH] phy: tegra: xusb: check the return value of devm_kzalloc() in tegra_xusb_setup_usb_role_switch()

On 23-07-22, 11:41, [email protected] wrote:
> From: William Dean <[email protected]>
>
> The function devm_kzalloc() in tegra_xusb_setup_usb_role_switch()
> can fail, so its return value should be checked.
>
> Fixes: f67213cee2b35 ("phy: tegra: xusb: Add usb-role-switch support")
> Reported-by: Hacash Robot <[email protected]>

Where is this bug report?

> Signed-off-by: William Dean <[email protected]>
> ---
> drivers/phy/tegra/xusb.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
> index aa5237eacd29..e3611fb4c779 100644
> --- a/drivers/phy/tegra/xusb.c
> +++ b/drivers/phy/tegra/xusb.c
> @@ -668,6 +668,8 @@ 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.25.1

--
~Vinod