phy: tegra: xusb: check return value of devm_kzalloc()

Message ID 20230531073950.145339-1-claudiu.beznea@microchip.com
State New
Headers
Series phy: tegra: xusb: check return value of devm_kzalloc() |

Commit Message

Claudiu Beznea May 31, 2023, 7:39 a.m. UTC
  devm_kzalloc() returns a pointer to dynamically allocated memory.
Pointer could be NULL in case allocation fails. Check pointer validity.
Identified with coccinelle (kmerr.cocci script).

Fixes: f67213cee2b3 ("phy: tegra: xusb: Add usb-role-switch support")
Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
---

Hi,

This has been addressed using kmerr.cocci script proposed for update
at [1].

Thank you,
Claudiu Beznea

[1] https://lore.kernel.org/all/20230530074044.1603426-1-claudiu.beznea@microchip.com/

 drivers/phy/tegra/xusb.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Thierry Reding June 1, 2023, 9:39 a.m. UTC | #1
On Wed, May 31, 2023 at 10:39:50AM +0300, Claudiu Beznea wrote:
> devm_kzalloc() returns a pointer to dynamically allocated memory.
> Pointer could be NULL in case allocation fails. Check pointer validity.
> Identified with coccinelle (kmerr.cocci script).
> 
> Fixes: f67213cee2b3 ("phy: tegra: xusb: Add usb-role-switch support")
> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
> ---
> 
> Hi,
> 
> This has been addressed using kmerr.cocci script proposed for update
> at [1].
> 
> Thank you,
> Claudiu Beznea
> 
> [1] https://lore.kernel.org/all/20230530074044.1603426-1-claudiu.beznea@microchip.com/
> 
>  drivers/phy/tegra/xusb.c | 3 +++
>  1 file changed, 3 insertions(+)

Acked-by: Thierry Reding <treding@nvidia.com>
  
Vinod Koul June 21, 2023, 5:37 p.m. UTC | #2
On 31-05-23, 10:39, Claudiu Beznea wrote:
> devm_kzalloc() returns a pointer to dynamically allocated memory.
> Pointer could be NULL in case allocation fails. Check pointer validity.
> Identified with coccinelle (kmerr.cocci script).

Applied, thanks
  

Patch

diff --git a/drivers/phy/tegra/xusb.c b/drivers/phy/tegra/xusb.c
index ec335668563d..fe72bc74e7bc 100644
--- a/drivers/phy/tegra/xusb.c
+++ b/drivers/phy/tegra/xusb.c
@@ -675,6 +675,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,