Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: wangxun: fix kernel panic due to null pointer

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>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jiawen Wu and committed by
David S. Miller
8ba2c459 76df934c

+7 -9
+5 -3
drivers/net/ethernet/wangxun/libwx/wx_hw.c
··· 1769 1769 wx->subsystem_device_id = pdev->subsystem_device; 1770 1770 } else { 1771 1771 err = wx_flash_read_dword(wx, 0xfffdc, &ssid); 1772 - if (!err) 1773 - wx->subsystem_device_id = swab16((u16)ssid); 1772 + if (err < 0) { 1773 + wx_err(wx, "read of internal subsystem device id failed\n"); 1774 + return err; 1775 + } 1774 1776 1775 - return err; 1777 + wx->subsystem_device_id = swab16((u16)ssid); 1776 1778 } 1777 1779 1778 1780 wx->mac_table = kcalloc(wx->mac.num_rar_entries,
+1 -3
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
··· 121 121 122 122 /* PCI config space info */ 123 123 err = wx_sw_init(wx); 124 - if (err < 0) { 125 - wx_err(wx, "read of internal subsystem device id failed\n"); 124 + if (err < 0) 126 125 return err; 127 - } 128 126 129 127 /* mac type, phy type , oem type */ 130 128 ngbe_init_type_code(wx);
+1 -3
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c
··· 364 364 365 365 /* PCI config space info */ 366 366 err = wx_sw_init(wx); 367 - if (err < 0) { 368 - wx_err(wx, "read of internal subsystem device id failed\n"); 367 + if (err < 0) 369 368 return err; 370 - } 371 369 372 370 txgbe_init_type_code(wx); 373 371