net: octeontx: Free allocated memory on error
authorAndrew Goodbody <andrew.goodbody@linaro.org>
Tue, 5 Aug 2025 15:45:49 +0000 (16:45 +0100)
committerJerome Forissier <jerome.forissier@linaro.org>
Mon, 18 Aug 2025 12:08:57 +0000 (14:08 +0200)
In octeontx_smi_probe if an error is detected then memory that was
allocated is not freed. Small refactor of the code to use a common
return and free memory. Also return -ENOMEM for an allocation failure.

This issue was found by Smatch.

Signed-off-by: Andrew Goodbody <andrew.goodbody@linaro.org>
drivers/net/octeontx/smi.c

index 233c26f..217bcac 100644 (file)
@@ -338,7 +338,8 @@ int octeontx_smi_probe(struct udevice *dev)
                if (!bus || !priv) {
                        printf("Failed to allocate OcteonTX MDIO bus # %u\n",
                               dev_seq(dev));
-                       return -1;
+                       ret = -ENOMEM;
+                       goto error_ret;
                }
 
                bus->read = octeontx_phy_read;
@@ -355,9 +356,16 @@ int octeontx_smi_probe(struct udevice *dev)
 
                ret = mdio_register(bus);
                if (ret)
-                       return ret;
+                       goto error_ret;
        }
        return 0;
+
+error_ret:
+       if (bus)
+               free(bus);
+       if (priv)
+               free(priv);
+       return ret;
 }
 
 static const struct udevice_id octeontx_smi_ids[] = {