[dpdk-dev] [PATCH v6 08/12] net/dpaa2: fix possible use of uninitialized vars
Hemant Agrawal
hemant.agrawal at nxp.com
Mon Nov 4 12:46:29 CET 2019
Hi Andrzej
> -----Original Message-----
> From: Andrzej Ostruszka <aostruszka at marvell.com>
> Sent: Tuesday, October 29, 2019 7:42 PM
> To: dev at dpdk.org; Hemant Agrawal <hemant.agrawal at nxp.com>; Sachin
> Saxena <sachin.saxena at nxp.com>
> Cc: mattias.ronnblom at ericsson.com; stephen at networkplumber.org
> Subject: [PATCH v6 08/12] net/dpaa2: fix possible use of uninitialized vars
> Importance: High
>
> 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 at marvell.com>
> ---
> drivers/net/dpaa2/base/dpaa2_hw_dpni.c | 1 +
> drivers/net/dpaa2/mc/dpkg.c | 2 +-
> drivers/net/dpaa2/mc/dpni.c | 9 ++++++---
> 3 files changed, 8 insertions(+), 4 deletions(-)
>
> 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..7aa63ea12 100644
> --- a/drivers/net/dpaa2/mc/dpkg.c
> +++ b/drivers/net/dpaa2/mc/dpkg.c
> @@ -63,7 +63,7 @@ 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);
>
[Hemant] Please add a check here to avoid array overrun
+ if (extr->num_of_byte_masks > DPKG_NUM_OF_MASKS)
+ return -EINVAL;
+
> - for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
> + 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;
> diff --git a/drivers/net/dpaa2/mc/dpni.c b/drivers/net/dpaa2/mc/dpni.c
> index 0950ee007..89a64b0ab 100644
> --- a/drivers/net/dpaa2/mc/dpni.c
> +++ b/drivers/net/dpaa2/mc/dpni.c
> @@ -1839,10 +1839,13 @@ int dpni_set_congestion_notification(struct
> fsl_mc_io *mc_io,
> cmd_params->qtype = qtype;
> cmd_params->tc = tc_id;
> cmd_params->congestion_point = cfg->cg_point;
> - cmd_params->cgid = (uint8_t)cfg->cgid;
> - cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
> + if (cfg->cg_point == DPNI_CP_CONGESTION_GROUP)
> + cmd_params->cgid = (uint8_t)cfg->cgid;
> + if (cfg->dest_cfg.dest_type != DPNI_DEST_NONE) {
> + cmd_params->dest_id = cpu_to_le32(cfg-
> >dest_cfg.dest_id);
> + cmd_params->dest_priority = cfg->dest_cfg.priority;
> + }
[Hemant] What is the explicit error you got here?
In the calling function, we are resetting the structure to 0. Which should have avoided
Any un-initialized var errors?
struct dpni_congestion_notification_cfg cong_notif_cfg = {0};
> cmd_params->notification_mode = cpu_to_le16(cfg-
> >notification_mode);
> - cmd_params->dest_priority = cfg->dest_cfg.priority;
> cmd_params->message_iova = cpu_to_le64(cfg->message_iova);
> cmd_params->message_ctx = cpu_to_le64(cfg->message_ctx);
> cmd_params->threshold_entry = cpu_to_le32(cfg-
> >threshold_entry);
> --
> 2.17.1
More information about the dev
mailing list