]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: mscc: ocelot: fix memory leak on ocelot_port_add_txtstamp_skb()
authorVladimir Oltean <vladimir.oltean@nxp.com>
Thu, 5 Dec 2024 14:55:15 +0000 (16:55 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sun, 8 Dec 2024 01:56:46 +0000 (17:56 -0800)
If ocelot_port_add_txtstamp_skb() fails, for example due to a full PTP
timestamp FIFO, we must undo the skb_clone_sk() call with kfree_skb().
Otherwise, the reference to the skb clone is lost.

Fixes: 52849bcf0029 ("net: mscc: ocelot: avoid overflowing the PTP timestamp FIFO")
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://patch.msgid.link/20241205145519.1236778-2-vladimir.oltean@nxp.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mscc/ocelot_ptp.c

index e172638b0601025688ba229589df847b669b0039..db00a51a7430f41c99e9f6854a7f29e359c1248d 100644 (file)
@@ -688,8 +688,10 @@ int ocelot_port_txtstamp_request(struct ocelot *ocelot, int port,
                        return -ENOMEM;
 
                err = ocelot_port_add_txtstamp_skb(ocelot, port, *clone);
-               if (err)
+               if (err) {
+                       kfree_skb(*clone);
                        return err;
+               }
 
                OCELOT_SKB_CB(skb)->ptp_cmd = ptp_cmd;
                OCELOT_SKB_CB(*clone)->ptp_class = ptp_class;