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)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Oct 2022 11:47:42 +0000 (12:47 +0100)
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>
drivers/net/ethernet/sunplus/spl2sw_driver.c

index 546206640492b318f57fd3c5b5c8d1bbad9c757b..61d1d07dc07044803b8225978b54fe635341a367 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;
        }