public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: wangxun: fix kernel panic due to null pointer
@ 2023-11-17 10:11 Jiawen Wu
  2023-11-17 10:11 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jiawen Wu @ 2023-11-17 10:11 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, netdev; +Cc: mengyuanlou, stable, Jiawen Wu

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(-)

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);
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: wangxun: fix kernel panic due to null pointer
  2023-11-17 10:11 [PATCH net] net: wangxun: fix kernel panic due to null pointer Jiawen Wu
@ 2023-11-17 10:11 ` kernel test robot
  2023-11-19 19:27 ` Simon Horman
  2023-11-19 19:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2023-11-17 10:11 UTC (permalink / raw)
  To: Jiawen Wu; +Cc: stable, oe-kbuild-all

Hi,

Thanks for your patch.

FYI: kernel test robot notices the stable kernel rule is not satisfied.

The check is based on https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html#option-1

Rule: add the tag "Cc: stable@vger.kernel.org" in the sign-off area to have the patch automatically included in the stable tree.
Subject: [PATCH net] net: wangxun: fix kernel panic due to null pointer
Link: https://lore.kernel.org/stable/20231117101108.893335-1-jiawenwu%40trustnetic.com

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: wangxun: fix kernel panic due to null pointer
  2023-11-17 10:11 [PATCH net] net: wangxun: fix kernel panic due to null pointer Jiawen Wu
  2023-11-17 10:11 ` kernel test robot
@ 2023-11-19 19:27 ` Simon Horman
  2023-11-19 19:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Simon Horman @ 2023-11-19 19:27 UTC (permalink / raw)
  To: Jiawen Wu; +Cc: davem, edumazet, kuba, pabeni, netdev, mengyuanlou, stable

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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] net: wangxun: fix kernel panic due to null pointer
  2023-11-17 10:11 [PATCH net] net: wangxun: fix kernel panic due to null pointer Jiawen Wu
  2023-11-17 10:11 ` kernel test robot
  2023-11-19 19:27 ` Simon Horman
@ 2023-11-19 19:50 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-11-19 19:50 UTC (permalink / raw)
  To: Jiawen Wu; +Cc: davem, edumazet, kuba, pabeni, netdev, mengyuanlou, stable

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-19 19:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 10:11 [PATCH net] net: wangxun: fix kernel panic due to null pointer Jiawen Wu
2023-11-17 10:11 ` kernel test robot
2023-11-19 19:27 ` Simon Horman
2023-11-19 19:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox