]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
eth: sp7021: fix use after free bug in spl2sw_nvmem_get_mac_address
authorZheng Wang <zyytlz.wz@163.com>
Fri, 30 Sep 2022 17:57:25 +0000 (01:57 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Oct 2022 07:57:16 +0000 (09:57 +0200)
[ Upstream commit 12aece8b01507a2d357a1861f470e83621fbb6f2 ]

This frees "mac" and tries to display its address as part of the error
message on the next line.  Swap the order.

Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
Signed-off-by: Zheng Wang <zyytlz.wz@163.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/sunplus/spl2sw_driver.c

index 3773ce5e12cc04923f7315fb63c54f700b2c3c4f..37711331ba0f4cbd92c44c80567ef14015fba98c 100644 (file)
@@ -248,8 +248,8 @@ static int spl2sw_nvmem_get_mac_address(struct device *dev, struct device_node *
 
        /* Check if mac address is valid */
        if (!is_valid_ether_addr(mac)) {
-               kfree(mac);
                dev_info(dev, "Invalid mac address in nvmem (%pM)!\n", mac);
+               kfree(mac);
                return -EINVAL;
        }