[v7,08/12] net/dpaa2: fix possible use of uninitialized vars

Message ID 20191107150318.3677-9-aostruszka@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series Add an option to use LTO for DPDK build |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply issues

Commit Message

Andrzej Ostruszka [C] Nov. 7, 2019, 3:03 p.m. UTC
  This patch fixes 'maybe-uninitialized' warnings reported by compiler
when using LTO.

Compiler warning pointing to this error (with LTO enabled):
error: ‘kg_cfg.extracts[0].masks[0].mask’ may be used uninitialized in
this function [-Werror=maybe-uninitialized]
    extr->masks[j].mask = cfg->extracts[i].masks[j].mask;

Fixes: 16bbc98a3e63 ("bus/fslmc: update MC to 10.3.x")
Signed-off-by: Andrzej Ostruszka <aostruszka@marvell.com>
---
 drivers/net/dpaa2/base/dpaa2_hw_dpni.c | 1 +
 drivers/net/dpaa2/mc/dpkg.c            | 5 ++++-
 2 files changed, 5 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/net/dpaa2/base/dpaa2_hw_dpni.c b/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
index 16555d7b0..47a8bda6a 100644
--- a/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
+++ b/drivers/net/dpaa2/base/dpaa2_hw_dpni.c
@@ -51,6 +51,7 @@  rte_pmd_dpaa2_set_custom_hash(uint16_t port_id,
 	kg_cfg.extracts[0].type = DPKG_EXTRACT_FROM_DATA;
 	kg_cfg.extracts[0].extract.from_data.offset = offset;
 	kg_cfg.extracts[0].extract.from_data.size = size;
+	kg_cfg.extracts[0].num_of_byte_masks = 0;
 	kg_cfg.num_extracts = 1;
 
 	ret = dpkg_prepare_key_cfg(&kg_cfg, p_params);
diff --git a/drivers/net/dpaa2/mc/dpkg.c b/drivers/net/dpaa2/mc/dpkg.c
index 80f94f40e..1e171eedc 100644
--- a/drivers/net/dpaa2/mc/dpkg.c
+++ b/drivers/net/dpaa2/mc/dpkg.c
@@ -63,7 +63,10 @@  dpkg_prepare_key_cfg(const struct dpkg_profile_cfg *cfg, uint8_t *key_cfg_buf)
 		dpkg_set_field(extr->extract_type, EXTRACT_TYPE,
 			       cfg->extracts[i].type);
 
-		for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
+		if (extr->num_of_byte_masks > DPKG_NUM_OF_MASKS)
+			return -EINVAL;
+
+		for (j = 0; j < extr->num_of_byte_masks; j++) {
 			extr->masks[j].mask = cfg->extracts[i].masks[j].mask;
 			extr->masks[j].offset =
 				cfg->extracts[i].masks[j].offset;