Skip to content

Commit 8ba2c45

Browse files
Jiawen Wudavem330
authored andcommitted
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: 79625f4 ("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>
1 parent 76df934 commit 8ba2c45

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

drivers/net/ethernet/wangxun/libwx/wx_hw.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,10 +1769,12 @@ int wx_sw_init(struct wx *wx)
17691769
wx->subsystem_device_id = pdev->subsystem_device;
17701770
} else {
17711771
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+
}
17741776

1775-
return err;
1777+
wx->subsystem_device_id = swab16((u16)ssid);
17761778
}
17771779

17781780
wx->mac_table = kcalloc(wx->mac.num_rar_entries,

drivers/net/ethernet/wangxun/ngbe/ngbe_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,8 @@ static int ngbe_sw_init(struct wx *wx)
121121

122122
/* PCI config space info */
123123
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)
126125
return err;
127-
}
128126

129127
/* mac type, phy type , oem type */
130128
ngbe_init_type_code(wx);

drivers/net/ethernet/wangxun/txgbe/txgbe_main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,8 @@ static int txgbe_sw_init(struct wx *wx)
364364

365365
/* PCI config space info */
366366
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)
369368
return err;
370-
}
371369

372370
txgbe_init_type_code(wx);
373371

0 commit comments

Comments
 (0)