Message ID | 20231117101108.893335-1-jiawenwu@trustnetic.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 8ba2c459668cfe2aaacc5ebcd35b4b9ef8643013 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] net: wangxun: fix kernel panic due to null pointer | expand |
On Fri, Nov 17, 2023 at 06:11:08PM +0800, Jiawen Wu wrote: > When the device uses a custom subsystem vendor ID, the function > wx_sw_init() returns before the memory of 'wx->mac_table' is allocated. > The null pointer will causes the kernel panic. > > Fixes: 79625f45ca73 ("net: wangxun: Move MAC address handling to libwx") > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> Thanks Jiawen Wu, I agree with your analysis and that the problem was introduced by the cited commit. The fix also looks good to me. Reviewed-by: Simon Horman <horms@kernel.org>
Hello: This patch was applied to netdev/net.git (main) by David S. Miller <davem@davemloft.net>: On Fri, 17 Nov 2023 18:11:08 +0800 you wrote: > When the device uses a custom subsystem vendor ID, the function > wx_sw_init() returns before the memory of 'wx->mac_table' is allocated. > The null pointer will causes the kernel panic. > > Fixes: 79625f45ca73 ("net: wangxun: Move MAC address handling to libwx") > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> > > [...] Here is the summary with links: - [net] net: wangxun: fix kernel panic due to null pointer https://git.kernel.org/netdev/net/c/8ba2c459668c You are awesome, thank you!
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_hw.c b/drivers/net/ethernet/wangxun/libwx/wx_hw.c index a3c5de9d547a..533e912af089 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_hw.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_hw.c @@ -1769,10 +1769,12 @@ int wx_sw_init(struct wx *wx) wx->subsystem_device_id = pdev->subsystem_device; } else { err = wx_flash_read_dword(wx, 0xfffdc, &ssid); - if (!err) - wx->subsystem_device_id = swab16((u16)ssid); + if (err < 0) { + wx_err(wx, "read of internal subsystem device id failed\n"); + return err; + } - return err; + wx->subsystem_device_id = swab16((u16)ssid); } wx->mac_table = kcalloc(wx->mac.num_rar_entries, diff --git a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c index 3d43f808c86b..8db804543e66 100644 --- a/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c +++ b/drivers/net/ethernet/wangxun/ngbe/ngbe_main.c @@ -121,10 +121,8 @@ static int ngbe_sw_init(struct wx *wx) /* PCI config space info */ err = wx_sw_init(wx); - if (err < 0) { - wx_err(wx, "read of internal subsystem device id failed\n"); + if (err < 0) return err; - } /* mac type, phy type , oem type */ ngbe_init_type_code(wx); diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c index 70f0b5c01dac..526250102db2 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_main.c @@ -364,10 +364,8 @@ static int txgbe_sw_init(struct wx *wx) /* PCI config space info */ err = wx_sw_init(wx); - if (err < 0) { - wx_err(wx, "read of internal subsystem device id failed\n"); + if (err < 0) return err; - } txgbe_init_type_code(wx);
When the device uses a custom subsystem vendor ID, the function wx_sw_init() returns before the memory of 'wx->mac_table' is allocated. The null pointer will causes the kernel panic. Fixes: 79625f45ca73 ("net: wangxun: Move MAC address handling to libwx") Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> --- drivers/net/ethernet/wangxun/libwx/wx_hw.c | 8 +++++--- drivers/net/ethernet/wangxun/ngbe/ngbe_main.c | 4 +--- drivers/net/ethernet/wangxun/txgbe/txgbe_main.c | 4 +--- 3 files changed, 7 insertions(+), 9 deletions(-)