net/hns3: fix build warning

Message ID 20230404065525.3313249-1-jerinj@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/hns3: fix build warning |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-x86_64-compile-testing success Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-abi-testing success Testing PASS

Commit Message

Jerin Jacob Kollanukkaran April 4, 2023, 6:55 a.m. UTC
  From: Jerin Jacob <jerinj@marvell.com>

aarch64 gcc 12.2.0 build complain with below warning[1].
Move the new_link initialization upwards to fix the warning.

Compiling C object drivers/libtmp_rte_net_hns3.a.p/net_hns3_hns3_ethdev.c.o
drivers/net/hns3/hns3_ethdev.c: In function ‘hns3_dev_link_update’:
drivers/net/hns3/hns3_ethdev.c:2249:1: warning: ‘new_link’ may be
used uninitialized [-Wmaybe-uninitialized]

Fixes: 64308555d5bf ("net/hns3: fix link status when port is stopped")
Cc: stable@dpdk.org

Signed-off-by: Jerin Jacob <jerinj@marvell.com>
---
 drivers/net/hns3/hns3_ethdev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Dongdong Liu April 4, 2023, 8:22 a.m. UTC | #1
Hi Jerin

Many thanks for fixing the warning.
On 2023/4/4 14:55, jerinj@marvell.com wrote:
> From: Jerin Jacob <jerinj@marvell.com>
>
> aarch64 gcc 12.2.0 build complain with below warning[1].
> Move the new_link initialization upwards to fix the warning.
>
> Compiling C object drivers/libtmp_rte_net_hns3.a.p/net_hns3_hns3_ethdev.c.o
> drivers/net/hns3/hns3_ethdev.c: In function ‘hns3_dev_link_update’:
> drivers/net/hns3/hns3_ethdev.c:2249:1: warning: ‘new_link’ may be
> used uninitialized [-Wmaybe-uninitialized]
It looks like a false positive from the logic of the code.
Anyway, this warning can be fixed by this patch, so
Acked-by: Dongdong Liu <liudongdong3@huawei.com>

Thanks,
Dongdong
>
> Fixes: 64308555d5bf ("net/hns3: fix link status when port is stopped")
> Cc: stable@dpdk.org
>
> Signed-off-by: Jerin Jacob <jerinj@marvell.com>
> ---
>  drivers/net/hns3/hns3_ethdev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
> index 36896f8989..a872cb8dd7 100644
> --- a/drivers/net/hns3/hns3_ethdev.c
> +++ b/drivers/net/hns3/hns3_ethdev.c
> @@ -2257,6 +2257,7 @@ hns3_dev_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
>  	struct rte_eth_link new_link;
>  	int ret;
>
> +	memset(&new_link, 0, sizeof(new_link));
>  	/* When port is stopped, report link down. */
>  	if (eth_dev->data->dev_started == 0) {
>  		new_link.link_autoneg = mac->link_autoneg;
> @@ -2280,7 +2281,6 @@ hns3_dev_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
>  		rte_delay_ms(HNS3_LINK_CHECK_INTERVAL);
>  	} while (retry_cnt--);
>
> -	memset(&new_link, 0, sizeof(new_link));
>  	hns3_setup_linkstatus(eth_dev, &new_link);
>
>  out:
>
  
Ferruh Yigit April 7, 2023, 5:08 p.m. UTC | #2
On 4/4/2023 9:22 AM, Dongdong Liu wrote:
> Hi Jerin
> 
> Many thanks for fixing the warning.
> On 2023/4/4 14:55, jerinj@marvell.com wrote:
>> From: Jerin Jacob <jerinj@marvell.com>
>>
>> aarch64 gcc 12.2.0 build complain with below warning[1].
>> Move the new_link initialization upwards to fix the warning.
>>
>> Compiling C object
>> drivers/libtmp_rte_net_hns3.a.p/net_hns3_hns3_ethdev.c.o
>> drivers/net/hns3/hns3_ethdev.c: In function ‘hns3_dev_link_update’:
>> drivers/net/hns3/hns3_ethdev.c:2249:1: warning: ‘new_link’ may be
>> used uninitialized [-Wmaybe-uninitialized]
> It looks like a false positive from the logic of the code.
> Anyway, this warning can be fixed by this patch, so
> Acked-by: Dongdong Liu <liudongdong3@huawei.com>
> 

Agree that it looks false positive.
Moving memset upwards does unnecessary memset for some case but this can
be OK for control path function.

Applied to dpdk-next-net/main, thanks.
  

Patch

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 36896f8989..a872cb8dd7 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2257,6 +2257,7 @@  hns3_dev_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
 	struct rte_eth_link new_link;
 	int ret;
 
+	memset(&new_link, 0, sizeof(new_link));
 	/* When port is stopped, report link down. */
 	if (eth_dev->data->dev_started == 0) {
 		new_link.link_autoneg = mac->link_autoneg;
@@ -2280,7 +2281,6 @@  hns3_dev_link_update(struct rte_eth_dev *eth_dev, int wait_to_complete)
 		rte_delay_ms(HNS3_LINK_CHECK_INTERVAL);
 	} while (retry_cnt--);
 
-	memset(&new_link, 0, sizeof(new_link));
 	hns3_setup_linkstatus(eth_dev, &new_link);
 
 out: