* [PATCH] fjes: Add missing check for vzalloc
@ 2023-09-25 8:53 Chen Ni
2023-09-25 14:40 ` Petr Machata
0 siblings, 1 reply; 3+ messages in thread
From: Chen Ni @ 2023-09-25 8:53 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, nichen, izumi.taku; +Cc: netdev, linux-kernel
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;
+
hw->hw_info.trace_size = FJES_DEBUG_BUFFER_SIZE;
return ret;
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] fjes: Add missing check for vzalloc
2023-09-25 8:53 [PATCH] fjes: Add missing check for vzalloc Chen Ni
@ 2023-09-25 14:40 ` Petr Machata
2023-10-03 11:07 ` Paolo Abeni
0 siblings, 1 reply; 3+ messages in thread
From: Petr Machata @ 2023-09-25 14:40 UTC (permalink / raw)
To: Chen Ni; +Cc: davem, edumazet, kuba, pabeni, izumi.taku, netdev, linux-kernel
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;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] fjes: Add missing check for vzalloc
2023-09-25 14:40 ` Petr Machata
@ 2023-10-03 11:07 ` Paolo Abeni
0 siblings, 0 replies; 3+ messages in thread
From: Paolo Abeni @ 2023-10-03 11:07 UTC (permalink / raw)
To: Petr Machata, Chen Ni
Cc: davem, edumazet, kuba, izumi.taku, netdev, linux-kernel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-10-03 11:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-25 8:53 [PATCH] fjes: Add missing check for vzalloc Chen Ni
2023-09-25 14:40 ` Petr Machata
2023-10-03 11:07 ` Paolo Abeni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).