diff mbox series

[net,2/2] net: sfc: siena: fix memory leak in siena_mtd_probe()

Message ID 20220510153619.32464-3-ap420073@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: sfc: fix memory leak in ->mtd_probe() callback | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
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: 0 this patch: 0
netdev/cc_maintainers fail 1 blamed authors not CCed: bhutchings@solarflare.com; 1 maintainers not CCed: bhutchings@solarflare.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: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 11 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Taehee Yoo May 10, 2022, 3:36 p.m. UTC
In the NIC ->probe callback, ->mtd_probe() callback is called.
If NIC has 2 ports, ->probe() is called twice and ->mtd_probe() too.
In the ->mtd_probe(), which is siena_mtd_probe() it allocates and
initializes mtd partiion.
But mtd partition for sfc is shared data.
So that allocated mtd partition data from last called
siena_mtd_probe() will not be used.
Therefore it must be freed.
But it doesn't free a not used mtd partition data in siena_mtd_probe().

Fixes: 8880f4ec21e6 ("sfc: Add support for SFC9000 family (2)")
Signed-off-by: Taehee Yoo <ap420073@gmail.com>
---
 drivers/net/ethernet/sfc/siena.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Martin Habets May 11, 2022, 6:25 a.m. UTC | #1
On Tue, May 10, 2022 at 03:36:19PM +0000, Taehee Yoo wrote:
> In the NIC ->probe callback, ->mtd_probe() callback is called.
> If NIC has 2 ports, ->probe() is called twice and ->mtd_probe() too.
> In the ->mtd_probe(), which is siena_mtd_probe() it allocates and
> initializes mtd partiion.
> But mtd partition for sfc is shared data.
> So that allocated mtd partition data from last called
> siena_mtd_probe() will not be used.

On Siena the 2nd port does have MTD partitions. In the output
from /proc/mtd below eth3 is the 1st port and eth4 is the 2nd
port:

mtd12: 00030000 00010000 "eth3 sfc_mcfw:0b"
mtd13: 00010000 00010000 "eth3 sfc_dynamic_cfg:00"
mtd14: 00030000 00010000 "eth3 sfc_exp_rom:01"
mtd15: 00010000 00010000 "eth3 sfc_exp_rom_cfg:00"
mtd16: 00120000 00010000 "eth3 sfc_fpga:01"
mtd17: 00010000 00010000 "eth4 sfc_dynamic_cfg:00"
mtd18: 00010000 00010000 "eth4 sfc_exp_rom_cfg:00"

So this patch is not needed, and efx_mtd_remove() will free
the memory for both ports.

Martin

> Therefore it must be freed.
> But it doesn't free a not used mtd partition data in siena_mtd_probe().
> 
> Fixes: 8880f4ec21e6 ("sfc: Add support for SFC9000 family (2)")
> Signed-off-by: Taehee Yoo <ap420073@gmail.com>
> ---
>  drivers/net/ethernet/sfc/siena.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/net/ethernet/sfc/siena.c b/drivers/net/ethernet/sfc/siena.c
> index ce3060e15b54..8b42951e34d6 100644
> --- a/drivers/net/ethernet/sfc/siena.c
> +++ b/drivers/net/ethernet/sfc/siena.c
> @@ -939,6 +939,11 @@ static int siena_mtd_probe(struct efx_nic *efx)
>  		nvram_types >>= 1;
>  	}
>  
> +	if (!n_parts) {
> +		kfree(parts);
> +		return 0;
> +	}
> +
>  	rc = siena_mtd_get_fw_subtypes(efx, parts, n_parts);
>  	if (rc)
>  		goto fail;
> -- 
> 2.17.1
Taehee Yoo May 11, 2022, 8:14 a.m. UTC | #2
2022. 5. 11. 오후 3:25에 Martin Habets 이(가) 쓴 글:

Hi Martin,
Thanks a lot for your review!

 > On Tue, May 10, 2022 at 03:36:19PM +0000, Taehee Yoo wrote:
 >> In the NIC ->probe callback, ->mtd_probe() callback is called.
 >> If NIC has 2 ports, ->probe() is called twice and ->mtd_probe() too.
 >> In the ->mtd_probe(), which is siena_mtd_probe() it allocates and
 >> initializes mtd partiion.
 >> But mtd partition for sfc is shared data.
 >> So that allocated mtd partition data from last called
 >> siena_mtd_probe() will not be used.
 >
 > On Siena the 2nd port does have MTD partitions. In the output
 > from /proc/mtd below eth3 is the 1st port and eth4 is the 2nd
 > port:
 >
 > mtd12: 00030000 00010000 "eth3 sfc_mcfw:0b"
 > mtd13: 00010000 00010000 "eth3 sfc_dynamic_cfg:00"
 > mtd14: 00030000 00010000 "eth3 sfc_exp_rom:01"
 > mtd15: 00010000 00010000 "eth3 sfc_exp_rom_cfg:00"
 > mtd16: 00120000 00010000 "eth3 sfc_fpga:01"
 > mtd17: 00010000 00010000 "eth4 sfc_dynamic_cfg:00"
 > mtd18: 00010000 00010000 "eth4 sfc_exp_rom_cfg:00"
 >
 > So this patch is not needed, and efx_mtd_remove() will free
 > the memory for both ports.
 >

Okay, I will send a v2 patch tomorrow, that will drop this patch and 
unnecessary cover-letter.

Thanks!
Taehee Yoo

 > Martin
 >
 >> Therefore it must be freed.
 >> But it doesn't free a not used mtd partition data in siena_mtd_probe().
 >>
 >> Fixes: 8880f4ec21e6 ("sfc: Add support for SFC9000 family (2)")
 >> Signed-off-by: Taehee Yoo <ap420073@gmail.com>
 >> ---
 >>   drivers/net/ethernet/sfc/siena.c | 5 +++++
 >>   1 file changed, 5 insertions(+)
 >>
 >> diff --git a/drivers/net/ethernet/sfc/siena.c 
b/drivers/net/ethernet/sfc/siena.c
 >> index ce3060e15b54..8b42951e34d6 100644
 >> --- a/drivers/net/ethernet/sfc/siena.c
 >> +++ b/drivers/net/ethernet/sfc/siena.c
 >> @@ -939,6 +939,11 @@ static int siena_mtd_probe(struct efx_nic *efx)
 >>   		nvram_types >>= 1;
 >>   	}
 >>
 >> +	if (!n_parts) {
 >> +		kfree(parts);
 >> +		return 0;
 >> +	}
 >> +
 >>   	rc = siena_mtd_get_fw_subtypes(efx, parts, n_parts);
 >>   	if (rc)
 >>   		goto fail;
 >> --
 >> 2.17.1
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/siena.c b/drivers/net/ethernet/sfc/siena.c
index ce3060e15b54..8b42951e34d6 100644
--- a/drivers/net/ethernet/sfc/siena.c
+++ b/drivers/net/ethernet/sfc/siena.c
@@ -939,6 +939,11 @@  static int siena_mtd_probe(struct efx_nic *efx)
 		nvram_types >>= 1;
 	}
 
+	if (!n_parts) {
+		kfree(parts);
+		return 0;
+	}
+
 	rc = siena_mtd_get_fw_subtypes(efx, parts, n_parts);
 	if (rc)
 		goto fail;