linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port()
@ 2025-05-08 14:52 Christophe JAILLET
  2025-05-08 14:52 ` [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe() Christophe JAILLET
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Christophe JAILLET @ 2025-05-08 14:52 UTC (permalink / raw)
  To: Lorenzo Bianconi, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	linux-arm-kernel, linux-mediatek, netdev

If register_netdev() fails, the error handling path of the probe will not
free the memory allocated by the previous airoha_metadata_dst_alloc() call
because port->dev->reg_state will not be NETREG_REGISTERED.

So, an explicit airoha_metadata_dst_free() call is needed in this case to
avoid a memory leak.

Fixes: af3cf757d5c9 ("net: airoha: Move DSA tag in DMA descriptor")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Changes in v2:
  - New patch

Compile tested only.
---
 drivers/net/ethernet/airoha/airoha_eth.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index 16c7896f931f..af8c4015938c 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -2873,7 +2873,15 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
 	if (err)
 		return err;
 
-	return register_netdev(dev);
+	err = register_netdev(dev);
+	if (err)
+		goto free_metadata_dst;
+
+	return 0;
+
+free_metadata_dst:
+	airoha_metadata_dst_free(port);
+	return err;
 }
 
 static int airoha_probe(struct platform_device *pdev)
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe()
  2025-05-08 14:52 [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Christophe JAILLET
@ 2025-05-08 14:52 ` Christophe JAILLET
  2025-05-08 15:10   ` Lorenzo Bianconi
  2025-05-08 14:52 ` [PATCH v2 3/4] net: airoha: Use for_each_child_of_node_scoped() Christophe JAILLET
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Christophe JAILLET @ 2025-05-08 14:52 UTC (permalink / raw)
  To: Lorenzo Bianconi, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	linux-arm-kernel, linux-mediatek, netdev

If an error occurs after a successful airoha_hw_init() call,
airoha_ppe_deinit() needs to be called as already done in the remove
function.

Fixes: 00a7678310fe ("net: airoha: Introduce flowtable offload support")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Changes in v2:
  - Call airoha_ppe_init() at the right place in the error handling path
    of the probe   [Lorenzo Bianconi]

Compile tested only.
---
 drivers/net/ethernet/airoha/airoha_eth.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index af8c4015938c..d435179875df 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -2967,6 +2967,7 @@ static int airoha_probe(struct platform_device *pdev)
 error_napi_stop:
 	for (i = 0; i < ARRAY_SIZE(eth->qdma); i++)
 		airoha_qdma_stop_napi(&eth->qdma[i]);
+	airoha_ppe_init(eth);
 error_hw_cleanup:
 	for (i = 0; i < ARRAY_SIZE(eth->qdma); i++)
 		airoha_hw_cleanup(&eth->qdma[i]);
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/4] net: airoha: Use for_each_child_of_node_scoped()
  2025-05-08 14:52 [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Christophe JAILLET
  2025-05-08 14:52 ` [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe() Christophe JAILLET
@ 2025-05-08 14:52 ` Christophe JAILLET
  2025-05-08 14:52 ` [PATCH v2 4/4] net: airoha: Use dev_err_probe() Christophe JAILLET
  2025-05-08 15:31 ` [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Lorenzo Bianconi
  3 siblings, 0 replies; 11+ messages in thread
From: Christophe JAILLET @ 2025-05-08 14:52 UTC (permalink / raw)
  To: Lorenzo Bianconi, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	linux-arm-kernel, linux-mediatek, netdev

Use for_each_child_of_node_scoped() to slightly simplify the code.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Changes in v2:
  - New patch

Compile tested only.
---
 drivers/net/ethernet/airoha/airoha_eth.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index d435179875df..2335aa59b06f 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -2886,7 +2886,6 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
 
 static int airoha_probe(struct platform_device *pdev)
 {
-	struct device_node *np;
 	struct airoha_eth *eth;
 	int i, err;
 
@@ -2948,7 +2947,7 @@ static int airoha_probe(struct platform_device *pdev)
 		airoha_qdma_start_napi(&eth->qdma[i]);
 
 	i = 0;
-	for_each_child_of_node(pdev->dev.of_node, np) {
+	for_each_child_of_node_scoped(pdev->dev.of_node, np) {
 		if (!of_device_is_compatible(np, "airoha,eth-mac"))
 			continue;
 
@@ -2956,10 +2955,8 @@ static int airoha_probe(struct platform_device *pdev)
 			continue;
 
 		err = airoha_alloc_gdm_port(eth, np, i++);
-		if (err) {
-			of_node_put(np);
+		if (err)
 			goto error_napi_stop;
-		}
 	}
 
 	return 0;
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/4] net: airoha: Use dev_err_probe()
  2025-05-08 14:52 [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Christophe JAILLET
  2025-05-08 14:52 ` [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe() Christophe JAILLET
  2025-05-08 14:52 ` [PATCH v2 3/4] net: airoha: Use for_each_child_of_node_scoped() Christophe JAILLET
@ 2025-05-08 14:52 ` Christophe JAILLET
  2025-05-08 15:43   ` Lorenzo Bianconi
  2025-05-08 15:31 ` [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Lorenzo Bianconi
  3 siblings, 1 reply; 11+ messages in thread
From: Christophe JAILLET @ 2025-05-08 14:52 UTC (permalink / raw)
  To: Lorenzo Bianconi, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET,
	linux-arm-kernel, linux-mediatek, netdev

Use dev_err_probe() to slightly simplify the code.
It is less verbose, more informational and makes error logging more
consistent in the probe.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Changes in v2:
  - New patch

Compile tested only.
---
 drivers/net/ethernet/airoha/airoha_eth.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index 2335aa59b06f..7404ee894467 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -2896,10 +2896,9 @@ static int airoha_probe(struct platform_device *pdev)
 	eth->dev = &pdev->dev;
 
 	err = dma_set_mask_and_coherent(eth->dev, DMA_BIT_MASK(32));
-	if (err) {
-		dev_err(eth->dev, "failed configuring DMA mask\n");
-		return err;
-	}
+	if (err)
+		return dev_err_probe(eth->dev, err,
+				     "failed configuring DMA mask\n");
 
 	eth->fe_regs = devm_platform_ioremap_resource_byname(pdev, "fe");
 	if (IS_ERR(eth->fe_regs))
@@ -2912,10 +2911,9 @@ static int airoha_probe(struct platform_device *pdev)
 	err = devm_reset_control_bulk_get_exclusive(eth->dev,
 						    ARRAY_SIZE(eth->rsts),
 						    eth->rsts);
-	if (err) {
-		dev_err(eth->dev, "failed to get bulk reset lines\n");
-		return err;
-	}
+	if (err)
+		return dev_err_probe(eth->dev, err,
+				     "failed to get bulk reset lines\n");
 
 	eth->xsi_rsts[0].id = "xsi-mac";
 	eth->xsi_rsts[1].id = "hsi0-mac";
@@ -2925,10 +2923,9 @@ static int airoha_probe(struct platform_device *pdev)
 	err = devm_reset_control_bulk_get_exclusive(eth->dev,
 						    ARRAY_SIZE(eth->xsi_rsts),
 						    eth->xsi_rsts);
-	if (err) {
-		dev_err(eth->dev, "failed to get bulk xsi reset lines\n");
-		return err;
-	}
+	if (err)
+		return dev_err_probe(eth->dev, err,
+				     "failed to get bulk xsi reset lines\n");
 
 	eth->napi_dev = alloc_netdev_dummy(0);
 	if (!eth->napi_dev)
-- 
2.49.0



^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe()
  2025-05-08 14:52 ` [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe() Christophe JAILLET
@ 2025-05-08 15:10   ` Lorenzo Bianconi
  2025-05-08 15:21     ` Christophe JAILLET
  0 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2025-05-08 15:10 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, linux-arm-kernel,
	linux-mediatek, netdev

[-- Attachment #1: Type: text/plain, Size: 1279 bytes --]

> If an error occurs after a successful airoha_hw_init() call,
> airoha_ppe_deinit() needs to be called as already done in the remove
> function.
> 
> Fixes: 00a7678310fe ("net: airoha: Introduce flowtable offload support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Changes in v2:
>   - Call airoha_ppe_init() at the right place in the error handling path
>     of the probe   [Lorenzo Bianconi]
> 
> Compile tested only.
> ---
>  drivers/net/ethernet/airoha/airoha_eth.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> index af8c4015938c..d435179875df 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.c
> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> @@ -2967,6 +2967,7 @@ static int airoha_probe(struct platform_device *pdev)
>  error_napi_stop:
>  	for (i = 0; i < ARRAY_SIZE(eth->qdma); i++)
>  		airoha_qdma_stop_napi(&eth->qdma[i]);
> +	airoha_ppe_init(eth);

it was actually a typo in my previous email but this should be clearly
airoha_ppe_deinit().

Regards,
Lorenzo

>  error_hw_cleanup:
>  	for (i = 0; i < ARRAY_SIZE(eth->qdma); i++)
>  		airoha_hw_cleanup(&eth->qdma[i]);
> -- 
> 2.49.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe()
  2025-05-08 15:10   ` Lorenzo Bianconi
@ 2025-05-08 15:21     ` Christophe JAILLET
  0 siblings, 0 replies; 11+ messages in thread
From: Christophe JAILLET @ 2025-05-08 15:21 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, linux-arm-kernel,
	linux-mediatek, netdev


Le 08/05/2025 à 17:10, Lorenzo Bianconi a écrit :
>> If an error occurs after a successful airoha_hw_init() call,
>> airoha_ppe_deinit() needs to be called as already done in the remove
>> function.
>>
>> Fixes: 00a7678310fe ("net: airoha: Introduce flowtable offload support")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Changes in v2:
>>    - Call airoha_ppe_init() at the right place in the error handling path
>>      of the probe   [Lorenzo Bianconi]
>>
>> Compile tested only.
>> ---
>>   drivers/net/ethernet/airoha/airoha_eth.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
>> index af8c4015938c..d435179875df 100644
>> --- a/drivers/net/ethernet/airoha/airoha_eth.c
>> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
>> @@ -2967,6 +2967,7 @@ static int airoha_probe(struct platform_device *pdev)
>>   error_napi_stop:
>>   	for (i = 0; i < ARRAY_SIZE(eth->qdma); i++)
>>   		airoha_qdma_stop_napi(&eth->qdma[i]);
>> +	airoha_ppe_init(eth);
> it was actually a typo in my previous email but this should be clearly
> airoha_ppe_deinit().

My bad!
Sorry for not spotting myself it.

We can really trust no one, nowadays ! :)

The good news is that my cocci script would have spotted it the next 
time I would have run it, because it would still find a 
airoha_ppe_deinit() in the remove function, but none in the probe.

I give you some time to review the other patches, and I'll a v3 later.

CJ

>
> Regards,
> Lorenzo
>
>>   error_hw_cleanup:
>>   	for (i = 0; i < ARRAY_SIZE(eth->qdma); i++)
>>   		airoha_hw_cleanup(&eth->qdma[i]);
>> -- 
>> 2.49.0
>>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port()
  2025-05-08 14:52 [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Christophe JAILLET
                   ` (2 preceding siblings ...)
  2025-05-08 14:52 ` [PATCH v2 4/4] net: airoha: Use dev_err_probe() Christophe JAILLET
@ 2025-05-08 15:31 ` Lorenzo Bianconi
  2025-05-08 16:05   ` Christophe JAILLET
  3 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2025-05-08 15:31 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, linux-arm-kernel,
	linux-mediatek, netdev

[-- Attachment #1: Type: text/plain, Size: 2178 bytes --]

> If register_netdev() fails, the error handling path of the probe will not
> free the memory allocated by the previous airoha_metadata_dst_alloc() call
> because port->dev->reg_state will not be NETREG_REGISTERED.
> 
> So, an explicit airoha_metadata_dst_free() call is needed in this case to
> avoid a memory leak.
> 
> Fixes: af3cf757d5c9 ("net: airoha: Move DSA tag in DMA descriptor")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Changes in v2:
>   - New patch
> 
> Compile tested only.
> ---
>  drivers/net/ethernet/airoha/airoha_eth.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> index 16c7896f931f..af8c4015938c 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.c
> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> @@ -2873,7 +2873,15 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
>  	if (err)
>  		return err;
>  
> -	return register_netdev(dev);
> +	err = register_netdev(dev);
> +	if (err)
> +		goto free_metadata_dst;
> +
> +	return 0;
> +
> +free_metadata_dst:
> +	airoha_metadata_dst_free(port);
> +	return err;
>  }
>  
>  static int airoha_probe(struct platform_device *pdev)
> -- 
> 2.49.0
> 

I have not tested it but I think the right fix here would be something like:

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index b1ca8322d4eb..33f8926bba25 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -2996,10 +2996,12 @@ static int airoha_probe(struct platform_device *pdev)
 	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
 		struct airoha_gdm_port *port = eth->ports[i];
 
-		if (port && port->dev->reg_state == NETREG_REGISTERED) {
+		if (!port)
+			continue;
+
+		if (port->dev->reg_state == NETREG_REGISTERED)
 			unregister_netdev(port->dev);
-			airoha_metadata_dst_free(port);
-		}
+		airoha_metadata_dst_free(port);
 	}
 	free_netdev(eth->napi_dev);
 	platform_set_drvdata(pdev, NULL);

Regards,
Lorenzo

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 4/4] net: airoha: Use dev_err_probe()
  2025-05-08 14:52 ` [PATCH v2 4/4] net: airoha: Use dev_err_probe() Christophe JAILLET
@ 2025-05-08 15:43   ` Lorenzo Bianconi
  2025-05-08 16:00     ` Christophe JAILLET
  0 siblings, 1 reply; 11+ messages in thread
From: Lorenzo Bianconi @ 2025-05-08 15:43 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, linux-arm-kernel,
	linux-mediatek, netdev

[-- Attachment #1: Type: text/plain, Size: 2320 bytes --]

On May 08, Christophe JAILLET wrote:
> Use dev_err_probe() to slightly simplify the code.
> It is less verbose, more informational and makes error logging more
> consistent in the probe.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Changes in v2:
>   - New patch
> 
> Compile tested only.
> ---
>  drivers/net/ethernet/airoha/airoha_eth.c | 21 +++++++++------------
>  1 file changed, 9 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> index 2335aa59b06f..7404ee894467 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.c
> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> @@ -2896,10 +2896,9 @@ static int airoha_probe(struct platform_device *pdev)
>  	eth->dev = &pdev->dev;
>  
>  	err = dma_set_mask_and_coherent(eth->dev, DMA_BIT_MASK(32));
> -	if (err) {
> -		dev_err(eth->dev, "failed configuring DMA mask\n");
> -		return err;
> -	}
> +	if (err)
> +		return dev_err_probe(eth->dev, err,
> +				     "failed configuring DMA mask\n");

Can dma_set_mask_and_coherent() return -EPROBE_DEFER? The other parts are fine.

Regards,
Lorenzo

>  
>  	eth->fe_regs = devm_platform_ioremap_resource_byname(pdev, "fe");
>  	if (IS_ERR(eth->fe_regs))
> @@ -2912,10 +2911,9 @@ static int airoha_probe(struct platform_device *pdev)
>  	err = devm_reset_control_bulk_get_exclusive(eth->dev,
>  						    ARRAY_SIZE(eth->rsts),
>  						    eth->rsts);
> -	if (err) {
> -		dev_err(eth->dev, "failed to get bulk reset lines\n");
> -		return err;
> -	}
> +	if (err)
> +		return dev_err_probe(eth->dev, err,
> +				     "failed to get bulk reset lines\n");
>  
>  	eth->xsi_rsts[0].id = "xsi-mac";
>  	eth->xsi_rsts[1].id = "hsi0-mac";
> @@ -2925,10 +2923,9 @@ static int airoha_probe(struct platform_device *pdev)
>  	err = devm_reset_control_bulk_get_exclusive(eth->dev,
>  						    ARRAY_SIZE(eth->xsi_rsts),
>  						    eth->xsi_rsts);
> -	if (err) {
> -		dev_err(eth->dev, "failed to get bulk xsi reset lines\n");
> -		return err;
> -	}
> +	if (err)
> +		return dev_err_probe(eth->dev, err,
> +				     "failed to get bulk xsi reset lines\n");
>  
>  	eth->napi_dev = alloc_netdev_dummy(0);
>  	if (!eth->napi_dev)
> -- 
> 2.49.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 4/4] net: airoha: Use dev_err_probe()
  2025-05-08 15:43   ` Lorenzo Bianconi
@ 2025-05-08 16:00     ` Christophe JAILLET
  0 siblings, 0 replies; 11+ messages in thread
From: Christophe JAILLET @ 2025-05-08 16:00 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, linux-arm-kernel,
	linux-mediatek, netdev

Le 08/05/2025 à 17:43, Lorenzo Bianconi a écrit :
> On May 08, Christophe JAILLET wrote:
>> Use dev_err_probe() to slightly simplify the code.
>> It is less verbose, more informational and makes error logging more
>> consistent in the probe.
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Changes in v2:
>>    - New patch
>>
>> Compile tested only.
>> ---
>>   drivers/net/ethernet/airoha/airoha_eth.c | 21 +++++++++------------
>>   1 file changed, 9 insertions(+), 12 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
>> index 2335aa59b06f..7404ee894467 100644
>> --- a/drivers/net/ethernet/airoha/airoha_eth.c
>> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
>> @@ -2896,10 +2896,9 @@ static int airoha_probe(struct platform_device *pdev)
>>   	eth->dev = &pdev->dev;
>>   
>>   	err = dma_set_mask_and_coherent(eth->dev, DMA_BIT_MASK(32));
>> -	if (err) {
>> -		dev_err(eth->dev, "failed configuring DMA mask\n");
>> -		return err;
>> -	}
>> +	if (err)
>> +		return dev_err_probe(eth->dev, err,
>> +				     "failed configuring DMA mask\n");
> 
> Can dma_set_mask_and_coherent() return -EPROBE_DEFER? The other parts are fine.
> 
> Regards,
> Lorenzo
> 

No, it can't, but using dev_err_probe() does not hurt.

Using dev_err_probe():
   - saves 1 LoC
   - is consistent in the function
   - log the error code in a human readable format
   - generate smaller binaries (can easily be checked with size)

So, even if "unneeded", I think it is still a improvement.

CJ


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port()
  2025-05-08 15:31 ` [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Lorenzo Bianconi
@ 2025-05-08 16:05   ` Christophe JAILLET
  2025-05-10  8:20     ` Lorenzo Bianconi
  0 siblings, 1 reply; 11+ messages in thread
From: Christophe JAILLET @ 2025-05-08 16:05 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, linux-arm-kernel,
	linux-mediatek, netdev

Le 08/05/2025 à 17:31, Lorenzo Bianconi a écrit :
>> If register_netdev() fails, the error handling path of the probe will not
>> free the memory allocated by the previous airoha_metadata_dst_alloc() call
>> because port->dev->reg_state will not be NETREG_REGISTERED.
>>
>> So, an explicit airoha_metadata_dst_free() call is needed in this case to
>> avoid a memory leak.
>>
>> Fixes: af3cf757d5c9 ("net: airoha: Move DSA tag in DMA descriptor")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>> Changes in v2:
>>    - New patch
>>
>> Compile tested only.
>> ---
>>   drivers/net/ethernet/airoha/airoha_eth.c | 10 +++++++++-
>>   1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
>> index 16c7896f931f..af8c4015938c 100644
>> --- a/drivers/net/ethernet/airoha/airoha_eth.c
>> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
>> @@ -2873,7 +2873,15 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
>>   	if (err)
>>   		return err;
>>   
>> -	return register_netdev(dev);
>> +	err = register_netdev(dev);
>> +	if (err)
>> +		goto free_metadata_dst;
>> +
>> +	return 0;
>> +
>> +free_metadata_dst:
>> +	airoha_metadata_dst_free(port);
>> +	return err;
>>   }
>>   
>>   static int airoha_probe(struct platform_device *pdev)
>> -- 
>> 2.49.0
>>
> 
> I have not tested it but I think the right fix here would be something like:
> 
> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> index b1ca8322d4eb..33f8926bba25 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.c
> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> @@ -2996,10 +2996,12 @@ static int airoha_probe(struct platform_device *pdev)
>   	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
>   		struct airoha_gdm_port *port = eth->ports[i];
>   
> -		if (port && port->dev->reg_state == NETREG_REGISTERED) {
> +		if (!port)
> +			continue;

I think it works.

We can still have port non NULL and airoha_metadata_dst_alloc() which 
fails, but airoha_metadata_dst_free() seems to handle it correctly.

CJ


> +
> +		if (port->dev->reg_state == NETREG_REGISTERED)
>   			unregister_netdev(port->dev);
> -			airoha_metadata_dst_free(port);
> -		}
> +		airoha_metadata_dst_free(port);
>   	}
>   	free_netdev(eth->napi_dev);
>   	platform_set_drvdata(pdev, NULL);
> 
> Regards,
> Lorenzo



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port()
  2025-05-08 16:05   ` Christophe JAILLET
@ 2025-05-10  8:20     ` Lorenzo Bianconi
  0 siblings, 0 replies; 11+ messages in thread
From: Lorenzo Bianconi @ 2025-05-10  8:20 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, linux-kernel, kernel-janitors, linux-arm-kernel,
	linux-mediatek, netdev

[-- Attachment #1: Type: text/plain, Size: 2934 bytes --]

> Le 08/05/2025 à 17:31, Lorenzo Bianconi a écrit :
> > > If register_netdev() fails, the error handling path of the probe will not
> > > free the memory allocated by the previous airoha_metadata_dst_alloc() call
> > > because port->dev->reg_state will not be NETREG_REGISTERED.
> > > 
> > > So, an explicit airoha_metadata_dst_free() call is needed in this case to
> > > avoid a memory leak.
> > > 
> > > Fixes: af3cf757d5c9 ("net: airoha: Move DSA tag in DMA descriptor")
> > > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > > ---
> > > Changes in v2:
> > >    - New patch
> > > 
> > > Compile tested only.
> > > ---
> > >   drivers/net/ethernet/airoha/airoha_eth.c | 10 +++++++++-
> > >   1 file changed, 9 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> > > index 16c7896f931f..af8c4015938c 100644
> > > --- a/drivers/net/ethernet/airoha/airoha_eth.c
> > > +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> > > @@ -2873,7 +2873,15 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
> > >   	if (err)
> > >   		return err;
> > > -	return register_netdev(dev);
> > > +	err = register_netdev(dev);
> > > +	if (err)
> > > +		goto free_metadata_dst;
> > > +
> > > +	return 0;
> > > +
> > > +free_metadata_dst:
> > > +	airoha_metadata_dst_free(port);
> > > +	return err;
> > >   }
> > >   static int airoha_probe(struct platform_device *pdev)
> > > -- 
> > > 2.49.0
> > > 
> > 
> > I have not tested it but I think the right fix here would be something like:
> > 
> > diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> > index b1ca8322d4eb..33f8926bba25 100644
> > --- a/drivers/net/ethernet/airoha/airoha_eth.c
> > +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> > @@ -2996,10 +2996,12 @@ static int airoha_probe(struct platform_device *pdev)
> >   	for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
> >   		struct airoha_gdm_port *port = eth->ports[i];
> > -		if (port && port->dev->reg_state == NETREG_REGISTERED) {
> > +		if (!port)
> > +			continue;
> 
> I think it works.
> 
> We can still have port non NULL and airoha_metadata_dst_alloc() which fails,
> but airoha_metadata_dst_free() seems to handle it correctly.
> 
> CJ

Actually, in order to be consistent with the rest of the code where a
routine undoes changes in case of an internal failure, I would prefer your
approach. Can you please post your solution in the next iteration? Thanks.

Regards,
Lorenzo

> 
> 
> > +
> > +		if (port->dev->reg_state == NETREG_REGISTERED)
> >   			unregister_netdev(port->dev);
> > -			airoha_metadata_dst_free(port);
> > -		}
> > +		airoha_metadata_dst_free(port);
> >   	}
> >   	free_netdev(eth->napi_dev);
> >   	platform_set_drvdata(pdev, NULL);
> > 
> > Regards,
> > Lorenzo
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-05-10  8:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-08 14:52 [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Christophe JAILLET
2025-05-08 14:52 ` [PATCH v2 2/4] net: airoha: Fix an error handling path in airoha_probe() Christophe JAILLET
2025-05-08 15:10   ` Lorenzo Bianconi
2025-05-08 15:21     ` Christophe JAILLET
2025-05-08 14:52 ` [PATCH v2 3/4] net: airoha: Use for_each_child_of_node_scoped() Christophe JAILLET
2025-05-08 14:52 ` [PATCH v2 4/4] net: airoha: Use dev_err_probe() Christophe JAILLET
2025-05-08 15:43   ` Lorenzo Bianconi
2025-05-08 16:00     ` Christophe JAILLET
2025-05-08 15:31 ` [PATCH v2 1/4] net: airoha: Fix an error handling path in airoha_alloc_gdm_port() Lorenzo Bianconi
2025-05-08 16:05   ` Christophe JAILLET
2025-05-10  8:20     ` Lorenzo Bianconi

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).