[v2,13/14] net/octeon_ep: avoid warning on uninitialized variable

Message ID 20240912082643.1532679-14-david.marchand@redhat.com (mailing list archive)
State Accepted
Delegated to: David Marchand
Headers
Series Use RTE_LOG_LINE in drivers |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand Sept. 12, 2024, 8:26 a.m. UTC
In the next commit, a (unrelated) change will be done on the logging
macros in this driver.

After this change, compilation with O3 fails with the following warning:
../drivers/net/octeon_ep/otx_ep_ethdev.c: In function
	‘otx_ep_dev_mtu_set’:
../drivers/net/octeon_ep/otx_ep_ethdev.c:200:12: error: ‘devinfo.max_mtu’
	may be used uninitialized [-Werror=maybe-uninitialized]
  200 |         if (mtu > devinfo.max_mtu) {
      |            ^
../drivers/net/octeon_ep/otx_ep_ethdev.c:186:33: note: ‘devinfo.max_mtu’
	was declared here
  186 |         struct rte_eth_dev_info devinfo;
      |                                 ^~~~~~~
cc1: all warnings being treated as errors

The devinfo object is passed through otx_ep_dev_info_get() which
initializes devinfo.max_mtu and returns 0.
This return code is checked at line 189 and so devinfo.max_mtu is
supposed to be initialized at this point.
This seems like a compiler optimisation bug, but we will have to live
with it.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 drivers/net/octeon_ep/otx_ep_ethdev.c | 1 +
 1 file changed, 1 insertion(+)
  

Patch

diff --git a/drivers/net/octeon_ep/otx_ep_ethdev.c b/drivers/net/octeon_ep/otx_ep_ethdev.c
index c4a5a67c79..adc19c72b0 100644
--- a/drivers/net/octeon_ep/otx_ep_ethdev.c
+++ b/drivers/net/octeon_ep/otx_ep_ethdev.c
@@ -186,6 +186,7 @@  otx_ep_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 	struct rte_eth_dev_info devinfo;
 	int32_t ret = 0;
 
+	memset(&devinfo, 0, sizeof(devinfo));
 	if (otx_ep_dev_info_get(eth_dev, &devinfo)) {
 		otx_ep_err("Cannot set MTU to %u: failed to get device info", mtu);
 		return -EPERM;