net: wangxun: fix kernel panic due to null pointer
authorJiawen Wu <jiawenwu@trustnetic.com>
Fri, 17 Nov 2023 10:11:08 +0000 (18:11 +0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 19 Nov 2023 19:43:54 +0000 (19:43 +0000)
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>
drivers/net/ethernet/wangxun/libwx/wx_hw.c
drivers/net/ethernet/wangxun/ngbe/ngbe_main.c
drivers/net/ethernet/wangxun/txgbe/txgbe_main.c

index a3c5de9d547a4b082cb52e60dc23ff721cf66b27..533e912af0893a0786a7436b88512cb65e9a5d63 100644 (file)
@@ -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,
index 3d43f808c86b784d60aaa1eb8d90769fcedbafba..8db804543e66da8a39e1246a95d0e0622c1f5d94 100644 (file)
@@ -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);
index 70f0b5c01dacf2dbd29c2322551ae146fa07baa4..526250102db27c139c140fac7dfd0117c566426b 100644 (file)
@@ -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);