Commit 8ba2c459 authored by Jiawen Wu's avatar Jiawen Wu Committed by David S. Miller
Browse files

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: 79625f45 ("net: wangxun: Move MAC address handling to libwx")
Signed-off-by: default avatarJiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 76df934c
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -1769,12 +1769,14 @@ 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;
		}

		wx->subsystem_device_id = swab16((u16)ssid);
	}

	wx->mac_table = kcalloc(wx->mac.num_rar_entries,
				sizeof(struct wx_mac_addr),
				GFP_KERNEL);
+1 −3
Original line number Diff line number Diff line
@@ -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);
+1 −3
Original line number Diff line number Diff line
@@ -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);