net/enic: fix build with GCC 7.5

Message ID 20211015102819.4101559-1-ferruh.yigit@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series net/enic: fix build with GCC 7.5 |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing warning apply patch failure
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional fail Functional Testing issues
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS

Commit Message

Ferruh Yigit Oct. 15, 2021, 10:28 a.m. UTC
  Build error:
../drivers/net/enic/enic_fm_flow.c: In function 'enic_fm_flow_parse':
../drivers/net/enic/enic_fm_flow.c:1467:24:
	error: 'dev' may be used uninitialized in this function
	[-Werror=maybe-uninitialized]
    struct rte_eth_dev *dev;
                        ^~~
../drivers/net/enic/enic_fm_flow.c:1580:24:
	error: 'dev' may be used uninitialized in this function
	[-Werror=maybe-uninitialized]
    struct rte_eth_dev *dev;
                        ^~~
../drivers/net/enic/enic_fm_flow.c:1599:24:
	error: 'dev' may be used uninitialized in this function
	[-Werror=maybe-uninitialized]
    struct rte_eth_dev *dev;
                        ^~~

Build error looks like false positive, but to silence the compiler
initializing the pointer with NULL.

Fixes: 7968917ccf64 ("net/enic: support meta flow actions to overrule destinations")

Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
Cc: andrew.rybchenko@oktetlabs.ru

I am not sure about the solution and I don't have environment to verify,
sending this patch to verify the solution in CI and trigger discussion
for fix.
The patch is still in next-net, when a proper fix is found, it can be
squashed in next-net.
---
 drivers/net/enic/enic_fm_flow.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

David Marchand Oct. 15, 2021, 11:16 a.m. UTC | #1
On Fri, Oct 15, 2021 at 12:28 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>
> Build error:
> ../drivers/net/enic/enic_fm_flow.c: In function 'enic_fm_flow_parse':
> ../drivers/net/enic/enic_fm_flow.c:1467:24:
>         error: 'dev' may be used uninitialized in this function
>         [-Werror=maybe-uninitialized]
>     struct rte_eth_dev *dev;
>                         ^~~
> ../drivers/net/enic/enic_fm_flow.c:1580:24:
>         error: 'dev' may be used uninitialized in this function
>         [-Werror=maybe-uninitialized]
>     struct rte_eth_dev *dev;
>                         ^~~
> ../drivers/net/enic/enic_fm_flow.c:1599:24:
>         error: 'dev' may be used uninitialized in this function
>         [-Werror=maybe-uninitialized]
>     struct rte_eth_dev *dev;
>                         ^~~
>
> Build error looks like false positive, but to silence the compiler
> initializing the pointer with NULL.

enic_fm_check_transfer_dst() contains branches where dev is not set
and those branches return rte_flow_error_set return value.
dev is dereferenced later based on this return value == 0.

So the compiler probably thinks that rte_flow_error_set may return 0.
rte_flow_error_set is outside of compiler "view" at the moment it
compiles enic_fm_flow.c, so the compiler making the assumption this
function can return 0 is being prudent from my pov.


>
> Fixes: 7968917ccf64 ("net/enic: support meta flow actions to overrule destinations")
>
> Reported-by: David Marchand <david.marchand@redhat.com>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Your fix looks good in any case.

Reviewed-by: David Marchand <david.marchand@redhat.com>
  
Ferruh Yigit Oct. 18, 2021, 11:16 a.m. UTC | #2
On 10/15/2021 12:16 PM, David Marchand wrote:
> On Fri, Oct 15, 2021 at 12:28 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>>
>> Build error:
>> ../drivers/net/enic/enic_fm_flow.c: In function 'enic_fm_flow_parse':
>> ../drivers/net/enic/enic_fm_flow.c:1467:24:
>>          error: 'dev' may be used uninitialized in this function
>>          [-Werror=maybe-uninitialized]
>>      struct rte_eth_dev *dev;
>>                          ^~~
>> ../drivers/net/enic/enic_fm_flow.c:1580:24:
>>          error: 'dev' may be used uninitialized in this function
>>          [-Werror=maybe-uninitialized]
>>      struct rte_eth_dev *dev;
>>                          ^~~
>> ../drivers/net/enic/enic_fm_flow.c:1599:24:
>>          error: 'dev' may be used uninitialized in this function
>>          [-Werror=maybe-uninitialized]
>>      struct rte_eth_dev *dev;
>>                          ^~~
>>
>> Build error looks like false positive, but to silence the compiler
>> initializing the pointer with NULL.
> 
> enic_fm_check_transfer_dst() contains branches where dev is not set
> and those branches return rte_flow_error_set return value.
> dev is dereferenced later based on this return value == 0.
> 
> So the compiler probably thinks that rte_flow_error_set may return 0.
> rte_flow_error_set is outside of compiler "view" at the moment it
> compiles enic_fm_flow.c, so the compiler making the assumption this
> function can return 0 is being prudent from my pov.
> 
> 
>>
>> Fixes: 7968917ccf64 ("net/enic: support meta flow actions to overrule destinations")
>>
>> Reported-by: David Marchand <david.marchand@redhat.com>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> Your fix looks good in any case.
> 
> Reviewed-by: David Marchand <david.marchand@redhat.com>
> 

Applied to dpdk-next-net/main, thanks.
  
Ferruh Yigit Oct. 18, 2021, 3:55 p.m. UTC | #3
On 10/18/2021 12:16 PM, Ferruh Yigit wrote:
> On 10/15/2021 12:16 PM, David Marchand wrote:
>> On Fri, Oct 15, 2021 at 12:28 PM Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>>>
>>> Build error:
>>> ../drivers/net/enic/enic_fm_flow.c: In function 'enic_fm_flow_parse':
>>> ../drivers/net/enic/enic_fm_flow.c:1467:24:
>>>          error: 'dev' may be used uninitialized in this function
>>>          [-Werror=maybe-uninitialized]
>>>      struct rte_eth_dev *dev;
>>>                          ^~~
>>> ../drivers/net/enic/enic_fm_flow.c:1580:24:
>>>          error: 'dev' may be used uninitialized in this function
>>>          [-Werror=maybe-uninitialized]
>>>      struct rte_eth_dev *dev;
>>>                          ^~~
>>> ../drivers/net/enic/enic_fm_flow.c:1599:24:
>>>          error: 'dev' may be used uninitialized in this function
>>>          [-Werror=maybe-uninitialized]
>>>      struct rte_eth_dev *dev;
>>>                          ^~~
>>>
>>> Build error looks like false positive, but to silence the compiler
>>> initializing the pointer with NULL.
>>
>> enic_fm_check_transfer_dst() contains branches where dev is not set
>> and those branches return rte_flow_error_set return value.
>> dev is dereferenced later based on this return value == 0.
>>
>> So the compiler probably thinks that rte_flow_error_set may return 0.
>> rte_flow_error_set is outside of compiler "view" at the moment it
>> compiles enic_fm_flow.c, so the compiler making the assumption this
>> function can return 0 is being prudent from my pov.
>>
>>
>>>
>>> Fixes: 7968917ccf64 ("net/enic: support meta flow actions to overrule destinations")
>>>
>>> Reported-by: David Marchand <david.marchand@redhat.com>
>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>
>> Your fix looks good in any case.
>>
>> Reviewed-by: David Marchand <david.marchand@redhat.com>
>>
> 
> Applied to dpdk-next-net/main, thanks.
> 

     Bugzilla ID: 812

Updated in next-net.
  

Patch

diff --git a/drivers/net/enic/enic_fm_flow.c b/drivers/net/enic/enic_fm_flow.c
index 4092ff1f6154..2c60bb864e23 100644
--- a/drivers/net/enic/enic_fm_flow.c
+++ b/drivers/net/enic/enic_fm_flow.c
@@ -1464,7 +1464,7 @@  enic_fm_copy_action(struct enic_flowman *fm,
 		}
 		case RTE_FLOW_ACTION_TYPE_PORT_ID: {
 			const struct rte_flow_action_port_id *port;
-			struct rte_eth_dev *dev;
+			struct rte_eth_dev *dev = NULL;
 
 			if (!ingress && (overlap & PORT_ID)) {
 				ENICPMD_LOG(DEBUG, "cannot have multiple egress PORT_ID actions");
@@ -1577,7 +1577,7 @@  enic_fm_copy_action(struct enic_flowman *fm,
 		}
 		case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR: {
 			const struct rte_flow_action_ethdev *ethdev;
-			struct rte_eth_dev *dev;
+			struct rte_eth_dev *dev = NULL;
 
 			ethdev = actions->conf;
 			ret = enic_fm_check_transfer_dst(enic, ethdev->port_id,
@@ -1596,7 +1596,7 @@  enic_fm_copy_action(struct enic_flowman *fm,
 		}
 		case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT: {
 			const struct rte_flow_action_ethdev *ethdev;
-			struct rte_eth_dev *dev;
+			struct rte_eth_dev *dev = NULL;
 
 			if (overlap & PORT_ID) {
 				ENICPMD_LOG(DEBUG, "cannot have multiple egress PORT_ID actions");