From: Zhipeng Lu <hidden> Date: 2024-01-22 17:25:03
In fjes_hw_setup, it allocates several memory and delay the deallocation
to the fjes_hw_exit in fjes_probe through the following call chain:
fjes_probe
|-> fjes_hw_init
|-> fjes_hw_setup
|-> fjes_hw_exit
However, when fjes_hw_setup fails, fjes_hw_exit won't be called and thus
all the resources allocated in fjes_hw_setup will be leaked. In this
patch, we free those resources in fjes_hw_setup and prevents such leaks.
Fixes: 2fcbca687702 ("fjes: platform_driver's .probe and .remove routine")
Signed-off-by: Zhipeng Lu <redacted>
---
drivers/net/fjes/fjes_hw.c | 37 ++++++++++++++++++++++++++++++-------
1 file changed, 30 insertions(+), 7 deletions(-)
From: Simon Horman <horms@kernel.org> Date: 2024-01-22 21:05:42
On Tue, Jan 23, 2024 at 01:24:42AM +0800, Zhipeng Lu wrote:
In fjes_hw_setup, it allocates several memory and delay the deallocation
to the fjes_hw_exit in fjes_probe through the following call chain:
fjes_probe
|-> fjes_hw_init
|-> fjes_hw_setup
|-> fjes_hw_exit
However, when fjes_hw_setup fails, fjes_hw_exit won't be called and thus
all the resources allocated in fjes_hw_setup will be leaked. In this
patch, we free those resources in fjes_hw_setup and prevents such leaks.
Fixes: 2fcbca687702 ("fjes: platform_driver's .probe and .remove routine")
Signed-off-by: Zhipeng Lu <redacted>
Hi Zhipeng Lu,
It looks like the last non-trivial change to this driver was in 2016.
So perhaps it is better to leave it be.
But if not, this patch does look correct to me.
Reviewed-by: Simon Horman <horms@kernel.org>
...
FWIIW, I'm not sure it is necessary to set these pointers NULL,
although it doesn't do any harm.
Also, if this function returns an error,
does the caller (fjes_hw_init()) leak hw->hw_info.trace?
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski [off-list ref]:
On Tue, 23 Jan 2024 01:24:42 +0800 you wrote:
In fjes_hw_setup, it allocates several memory and delay the deallocation
to the fjes_hw_exit in fjes_probe through the following call chain:
fjes_probe
|-> fjes_hw_init
|-> fjes_hw_setup
|-> fjes_hw_exit
[...]
On Tue, Jan 23, 2024 at 01:24:42AM +0800, Zhipeng Lu wrote:
quoted
In fjes_hw_setup, it allocates several memory and delay the deallocation
to the fjes_hw_exit in fjes_probe through the following call chain:
fjes_probe
|-> fjes_hw_init
|-> fjes_hw_setup
|-> fjes_hw_exit
However, when fjes_hw_setup fails, fjes_hw_exit won't be called and thus
all the resources allocated in fjes_hw_setup will be leaked. In this
patch, we free those resources in fjes_hw_setup and prevents such leaks.
Fixes: 2fcbca687702 ("fjes: platform_driver's .probe and .remove routine")
Signed-off-by: Zhipeng Lu <redacted>
Hi Zhipeng Lu,
It looks like the last non-trivial change to this driver was in 2016.
So perhaps it is better to leave it be.
But if not, this patch does look correct to me.
Reviewed-by: Simon Horman <horms@kernel.org>
I think this patch doesn't change a lot since it just refactor the deallocation
ways into unwind ladders while fix a memleak.
FWIIW, I'm not sure it is necessary to set these pointers NULL,
although it doesn't do any harm.
I set these pointers to NULL since its clean up function fjes_hw_cleanup
do so. Personally, I tend to following the existing code style in the
same module.
Also, if this function returns an error,
does the caller (fjes_hw_init()) leak hw->hw_info.trace?
Well, yes, it's a little bit wired that fjes_hw_init doesn't handle
errors of fjes_hw_setup and vzalloc of hw->hw_info.trace as normal
functions do.
Maybe another patch need to be submitted to deal with this problem.