diff mbox series

fjes: Add missing check for vzalloc

Message ID 20230925085318.1228225-1-nichen@iscas.ac.cn (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series fjes: Add missing check for vzalloc | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1357 this patch: 1357
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1363 this patch: 1363
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1380 this patch: 1380
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

Chen Ni Sept. 25, 2023, 8:53 a.m. UTC
Because of the potential failure of the vzalloc(), the hw->hw_info.trace
could be NULL.
Therefore, we need to check it and return -ENOMEM in order to transfer
the error.

Fixes: b6ba737d0b29 ("fjes: ethtool -w and -W support for fjes driver")
Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
 drivers/net/fjes/fjes_hw.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Petr Machata Sept. 25, 2023, 2:40 p.m. UTC | #1
Chen Ni <nichen@iscas.ac.cn> writes:

> Because of the potential failure of the vzalloc(), the hw->hw_info.trace
> could be NULL.
> Therefore, we need to check it and return -ENOMEM in order to transfer
> the error.
>
> Fixes: b6ba737d0b29 ("fjes: ethtool -w and -W support for fjes driver")
> Signed-off-by: Chen Ni <nichen@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 704e949484d0..3a06a3cf021d 100644
> --- a/drivers/net/fjes/fjes_hw.c
> +++ b/drivers/net/fjes/fjes_hw.c
> @@ -330,6 +330,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;
> +

I'm not sure, but shouldn't this call fjes_hw_cleanup() to mirror the
setup() above? Also only if ret=0 I suppose.

>  	hw->hw_info.trace_size = FJES_DEBUG_BUFFER_SIZE;
>  
>  	return ret;
Paolo Abeni Oct. 3, 2023, 11:07 a.m. UTC | #2
On Mon, 2023-09-25 at 16:40 +0200, Petr Machata wrote:
> Chen Ni <nichen@iscas.ac.cn> writes:
> 
> > Because of the potential failure of the vzalloc(), the hw->hw_info.trace
> > could be NULL.
> > Therefore, we need to check it and return -ENOMEM in order to transfer
> > the error.
> > 
> > Fixes: b6ba737d0b29 ("fjes: ethtool -w and -W support for fjes driver")
> > Signed-off-by: Chen Ni <nichen@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 704e949484d0..3a06a3cf021d 100644
> > --- a/drivers/net/fjes/fjes_hw.c
> > +++ b/drivers/net/fjes/fjes_hw.c
> > @@ -330,6 +330,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;
> > +
> 
> I'm not sure, but shouldn't this call fjes_hw_cleanup() to mirror the
> setup() above? Also only if ret=0 I suppose.

Yes, that looks needed, or memory will be leaked. Additionally it looks
like the rest of the driver handles correctly the case where
hw_info.trace is NULL, so this fix is likely not needed at all.

Cheers,

Paolo
diff mbox series

Patch

diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c
index 704e949484d0..3a06a3cf021d 100644
--- a/drivers/net/fjes/fjes_hw.c
+++ b/drivers/net/fjes/fjes_hw.c
@@ -330,6 +330,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;