From: Zheng Wang Date: Fri, 30 Sep 2022 17:57:25 +0000 (+0800) Subject: eth: sp7021: fix use after free bug in spl2sw_nvmem_get_mac_address X-Git-Tag: v5.19.17~427 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b47bc8202b31a2677a344322b3c4b7f8750c5e66;p=thirdparty%2Fkernel%2Fstable.git eth: sp7021: fix use after free bug in spl2sw_nvmem_get_mac_address [ 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c index 3773ce5e12cc0..37711331ba0f4 100644 --- a/drivers/net/ethernet/sunplus/spl2sw_driver.c +++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c @@ -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; }