diff mbox series

fjes: Check possible NULL pointer returned by vzalloc

Message ID 20211229102140.1776466-1-jiasheng@iscas.ac.cn (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series fjes: Check possible NULL pointer returned by vzalloc | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 17 this patch: 17
netdev/cc_maintainers fail 1 blamed authors not CCed: izumi.taku@jp.fujitsu.com; 1 maintainers not CCed: izumi.taku@jp.fujitsu.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 17 this patch: 17
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jiasheng Jiang Dec. 29, 2021, 10:21 a.m. UTC
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 <jiasheng@iscas.ac.cn>
---
 drivers/net/fjes/fjes_hw.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Jakub Kicinski Dec. 30, 2021, 2:33 a.m. UTC | #1
On Wed, 29 Dec 2021 18:21:40 +0800 Jiasheng Jiang wrote:
> 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 <jiasheng@iscas.ac.cn>
> ---
>  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.
diff mbox series

Patch

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;