]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: enetc: Fix use after free issue in fsl_enetc.c
authorSiarhei Yasinski <siarhei.yasinski@sintecs.eu>
Wed, 31 Aug 2022 10:57:37 +0000 (10:57 +0000)
committerPeng Fan <peng.fan@nxp.com>
Tue, 6 Sep 2022 01:28:47 +0000 (09:28 +0800)
If ethernet connected to SFP, like this:

&enetc_port0 {
            phy-connection-type = "sgmii";
            sfp = <&sfp0>;
            managed = "in-band-status";
            status = "okay";
};

Then enetc_config_phy returns -ENODEV and the memory containing the mdio interface is freed.
It's better to unregister and free mdio resources.

Signed-off-by: Siarhei Yasinski <siarhei.yasinski@sintecs.eu>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/net/fsl_enetc.c

index cd4c2c29a6536a5aba36c89edcda0061ab69fef3..835e5bd8bd59f45a52314ac1d0f154bcbcc445d1 100644 (file)
@@ -22,6 +22,8 @@
 
 #define ENETC_DRIVER_NAME      "enetc_eth"
 
+static int enetc_remove(struct udevice *dev);
+
 /*
  * sets the MAC address in IERB registers, this setting is persistent and
  * carried over to Linux.
@@ -319,6 +321,7 @@ static int enetc_config_phy(struct udevice *dev)
 static int enetc_probe(struct udevice *dev)
 {
        struct enetc_priv *priv = dev_get_priv(dev);
+       int res;
 
        if (ofnode_valid(dev_ofnode(dev)) && !ofnode_is_available(dev_ofnode(dev))) {
                enetc_dbg(dev, "interface disabled\n");
@@ -350,7 +353,10 @@ static int enetc_probe(struct udevice *dev)
 
        enetc_start_pcs(dev);
 
-       return enetc_config_phy(dev);
+       res = enetc_config_phy(dev);
+       if(res)
+               enetc_remove(dev);
+       return res;
 }
 
 /*