[PATCH] fjes: Check possible NULL pointer returned by vzalloc

Subsystems: networking drivers, the rest

STALE1754d

2 messages, 2 authors, 2021-12-30 · open the first message on its own page

[PATCH] fjes: Check possible NULL pointer returned by vzalloc

From: Jiasheng Jiang <hidden>
Date: 2021-12-29 10:22:11

As the possible alloc failure of the vzalloc(), the 'hw->hw_info.trace'
could be NULL pointer.
Therefore it should be better to check it to guarantee the complete
success of the initiation.

Fixes: 8cdc3f6c5d22 ("fjes: Hardware initialization routine")
Signed-off-by: Jiasheng Jiang <redacted>
---
 drivers/net/fjes/fjes_hw.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c
index 065bb0a40b1d..4c83f637a135 100644
--- a/drivers/net/fjes/fjes_hw.c
+++ b/drivers/net/fjes/fjes_hw.c
@@ -329,6 +329,9 @@ int fjes_hw_init(struct fjes_hw *hw)
 	ret = fjes_hw_setup(hw);
 
 	hw->hw_info.trace = vzalloc(FJES_DEBUG_BUFFER_SIZE);
+	if (!hw->hw_info.trace)
+		return -ENOMEM;
+
 	hw->hw_info.trace_size = FJES_DEBUG_BUFFER_SIZE;
 
 	return ret;
-- 
2.25.1

Re: [PATCH] fjes: Check possible NULL pointer returned by vzalloc

From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-12-30 02:33:28

On Wed, 29 Dec 2021 18:21:40 +0800 Jiasheng Jiang wrote:
quoted hunk
As the possible alloc failure of the vzalloc(), the 'hw->hw_info.trace'
could be NULL pointer.
Therefore it should be better to check it to guarantee the complete
success of the initiation.

Fixes: 8cdc3f6c5d22 ("fjes: Hardware initialization routine")
Signed-off-by: Jiasheng Jiang <redacted>
---
 drivers/net/fjes/fjes_hw.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c
index 065bb0a40b1d..4c83f637a135 100644
--- a/drivers/net/fjes/fjes_hw.c
+++ b/drivers/net/fjes/fjes_hw.c
@@ -329,6 +329,9 @@ int fjes_hw_init(struct fjes_hw *hw)
 	ret = fjes_hw_setup(hw);
 
 	hw->hw_info.trace = vzalloc(FJES_DEBUG_BUFFER_SIZE);
+	if (!hw->hw_info.trace)
+		return -ENOMEM;
+
 	hw->hw_info.trace_size = FJES_DEBUG_BUFFER_SIZE;
 
 	return ret;
The rest of this driver is clearly written expecting that
hw_info.trace may be NULL. This change is unnecessary at 
best and may even introduce a regression.

Please do bare minimum of sanity checking your patches.
Your submissions are consistently of very low quality.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help