All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] common/cnxk: check return value for error
@ 2022-02-12 12:38 Gowrishankar Muthukrishnan
  2022-02-12 12:38 ` [PATCH 2/3] common/cnx: fix unintended sign extension Gowrishankar Muthukrishnan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-02-12 12:38 UTC (permalink / raw)
  To: dev
  Cc: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	jerinj, Gowrishankar Muthukrishnan

This patch fixes coverity issue by adding checks on return values.

Coverity issue: 373628, 374858, 370213, 370215
Fixes: af75aac78978 ("common/cnxk: support telemetry for NIX")
Fixes: d61138d4f0e ("drivers: remove direct access to interrupt handle")
Fixes: fcdef46b669 ("common/cnxk: support NIX TM debug and misc utils")
Fixes: df405df95ee ("common/cnxk: add NIX TM helper to alloc/free resource")

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 drivers/common/cnxk/cnxk_telemetry_nix.c | 3 +++
 drivers/common/cnxk/roc_irq.c            | 5 ++++-
 drivers/common/cnxk/roc_nix_debug.c      | 4 +++-
 drivers/common/cnxk/roc_nix_tm.c         | 6 ++++--
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c
index df6458039d..4119e9ee4f 100644
--- a/drivers/common/cnxk/cnxk_telemetry_nix.c
+++ b/drivers/common/cnxk/cnxk_telemetry_nix.c
@@ -765,6 +765,9 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
 
 	plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
 	name = strtok(buf, ",");
+	if (name == NULL)
+		goto exit;
+
 	param = strtok(NULL, "\0");
 
 	node = nix_tel_node_get_by_pcidev_name(name);
diff --git a/drivers/common/cnxk/roc_irq.c b/drivers/common/cnxk/roc_irq.c
index 7a24297d72..010b121176 100644
--- a/drivers/common/cnxk/roc_irq.c
+++ b/drivers/common/cnxk/roc_irq.c
@@ -160,7 +160,10 @@ dev_irq_register(struct plt_intr_handle *intr_handle, plt_intr_callback_fn cb,
 		return rc;
 	}
 
-	plt_intr_efds_index_set(intr_handle, vec, fd);
+	rc = plt_intr_efds_index_set(intr_handle, vec, fd);
+	if (rc)
+		return rc;
+
 	nb_efd = (vec > (uint32_t)plt_intr_nb_efd_get(intr_handle)) ?
 		vec : (uint32_t)plt_intr_nb_efd_get(intr_handle);
 	plt_intr_nb_efd_set(intr_handle, nb_efd);
diff --git a/drivers/common/cnxk/roc_nix_debug.c b/drivers/common/cnxk/roc_nix_debug.c
index d5143882f5..1ae045172e 100644
--- a/drivers/common/cnxk/roc_nix_debug.c
+++ b/drivers/common/cnxk/roc_nix_debug.c
@@ -52,7 +52,9 @@ nix_bitmap_dump(struct plt_bitmap *bmp)
 	int i;
 
 	plt_bitmap_scan_init(bmp);
-	plt_bitmap_scan(bmp, &pos, &slab);
+	if (!plt_bitmap_scan(bmp, &pos, &slab))
+		return;
+
 	start_pos = pos;
 
 	nix_dump_no_nl("  \t\t[");
diff --git a/drivers/common/cnxk/roc_nix_tm.c b/drivers/common/cnxk/roc_nix_tm.c
index a0448bec61..517502b1af 100644
--- a/drivers/common/cnxk/roc_nix_tm.c
+++ b/drivers/common/cnxk/roc_nix_tm.c
@@ -1016,8 +1016,10 @@ nix_tm_assign_hw_id(struct nix *nix, struct nix_tm_node *parent,
 			return -EFAULT;
 		}
 
-		if (!slab)
-			plt_bitmap_scan(bmp, &pos, &slab);
+		if (!slab) {
+			if (!plt_bitmap_scan(bmp, &pos, &slab))
+				return -ENOENT;
+		}
 
 		if (child->priority == parent->rr_prio && spare_schq != -1) {
 			/* Use spare schq first if present */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] common/cnx: fix unintended sign extension
  2022-02-12 12:38 [PATCH 1/3] common/cnxk: check return value for error Gowrishankar Muthukrishnan
@ 2022-02-12 12:38 ` Gowrishankar Muthukrishnan
  2022-02-12 12:38 ` [PATCH 3/3] common/cnxk: fix uninitialized pointer read Gowrishankar Muthukrishnan
  2022-02-18  4:20 ` [PATCH 1/3] common/cnxk: check return value for error Jerin Jacob
  2 siblings, 0 replies; 4+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-02-12 12:38 UTC (permalink / raw)
  To: dev
  Cc: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	jerinj, Gowrishankar Muthukrishnan

This patch fixes unintended sign extensions reported in coverity
scan.

Fixes: 8ca851cdc59 ("common/cnxk: support dual VLAN insert and strip actions")
Coverity issue: 373258

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 drivers/common/cnxk/roc_npc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/common/cnxk/roc_npc.c b/drivers/common/cnxk/roc_npc.c
index e3961bfbc6..453fd5d3e0 100644
--- a/drivers/common/cnxk/roc_npc.c
+++ b/drivers/common/cnxk/roc_npc.c
@@ -969,14 +969,14 @@ npc_vtag_insert_action_configure(struct mbox *mbox, struct roc_npc_flow *flow,
 	vtag_cfg->cfg_type = VTAG_TX;
 	vtag_cfg->vtag_size = NIX_VTAGSIZE_T4;
 	vtag_cfg->tx.vtag0 =
-		((vlan_info[0].vlan_ethtype << 16) |
+		(((uint32_t)vlan_info[0].vlan_ethtype << 16) |
 		 (vlan_info[0].vlan_pcp << 13) | vlan_info[0].vlan_id);
 
 	vtag_cfg->tx.cfg_vtag0 = 1;
 
 	if (flow->vtag_insert_count == 2) {
 		vtag_cfg->tx.vtag1 =
-			((vlan_info[1].vlan_ethtype << 16) |
+			(((uint32_t)vlan_info[1].vlan_ethtype << 16) |
 			 (vlan_info[1].vlan_pcp << 13) | vlan_info[1].vlan_id);
 
 		vtag_cfg->tx.cfg_vtag1 = 1;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] common/cnxk: fix uninitialized pointer read
  2022-02-12 12:38 [PATCH 1/3] common/cnxk: check return value for error Gowrishankar Muthukrishnan
  2022-02-12 12:38 ` [PATCH 2/3] common/cnx: fix unintended sign extension Gowrishankar Muthukrishnan
@ 2022-02-12 12:38 ` Gowrishankar Muthukrishnan
  2022-02-18  4:20 ` [PATCH 1/3] common/cnxk: check return value for error Jerin Jacob
  2 siblings, 0 replies; 4+ messages in thread
From: Gowrishankar Muthukrishnan @ 2022-02-12 12:38 UTC (permalink / raw)
  To: dev
  Cc: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
	jerinj, Gowrishankar Muthukrishnan

Fix uninitialized pointer read reported in coverity scan.

Fixes: c34ea71b878 ("common/cnxk: add NPC parsing API")
Coverity issue: 370214, 370217, 370219, 370220, 370221, 370223,
                370224, 370225, 372065

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 drivers/common/cnxk/roc_npc_parse.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/common/cnxk/roc_npc_parse.c b/drivers/common/cnxk/roc_npc_parse.c
index 1f21693369..41ff0fcc6b 100644
--- a/drivers/common/cnxk/roc_npc_parse.c
+++ b/drivers/common/cnxk/roc_npc_parse.c
@@ -112,6 +112,7 @@ npc_parse_cpt_hdr(struct npc_parse_state *pst)
 	info.hw_hdr_len = 0;
 
 	/* Prepare for parsing the item */
+	info.def_mask = NULL;
 	info.hw_mask = &hw_mask;
 	info.len = pst->pattern->size;
 	npc_get_hw_supp_mask(pst, &info, lid, lt);
@@ -149,6 +150,7 @@ npc_parse_higig2_hdr(struct npc_parse_state *pst)
 	}
 
 	/* Prepare for parsing the item */
+	info.def_mask = NULL;
 	info.hw_mask = &hw_mask;
 	info.len = pst->pattern->size;
 	npc_get_hw_supp_mask(pst, &info, lid, lt);
@@ -198,6 +200,7 @@ npc_parse_la(struct npc_parse_state *pst)
 	}
 
 	/* Prepare for parsing the item */
+	info.def_mask = NULL;
 	info.hw_mask = &hw_mask;
 	info.len = sizeof(eth_item->hdr);
 	npc_get_hw_supp_mask(pst, &info, lid, lt);
@@ -236,6 +239,7 @@ npc_parse_lb(struct npc_parse_state *pst)
 	int nr_vlans = 0;
 	int rc;
 
+	info.def_mask = NULL;
 	info.spec = NULL;
 	info.mask = NULL;
 	info.def_mask = NULL;
@@ -396,12 +400,12 @@ npc_parse_mpls_label_stack(struct npc_parse_state *pst, int *flag)
 	 * pst->pattern points to first MPLS label. We only check
 	 * that subsequent labels do not have anything to match.
 	 */
+	info.def_mask = NULL;
 	info.hw_mask = NULL;
 	info.len = pattern->size;
 	info.spec = NULL;
 	info.mask = NULL;
 	info.hw_hdr_len = 0;
-	info.def_mask = NULL;
 
 	while (pattern->type == ROC_NPC_ITEM_TYPE_MPLS) {
 		nr_labels++;
@@ -447,6 +451,7 @@ npc_parse_mpls(struct npc_parse_state *pst, int lid)
 	info.len = pst->pattern->size;
 	info.spec = NULL;
 	info.mask = NULL;
+	info.def_mask = NULL;
 	info.hw_hdr_len = 0;
 
 	npc_get_hw_supp_mask(pst, &info, lid, lt);
@@ -547,6 +552,7 @@ npc_parse_lc(struct npc_parse_state *pst)
 	if (pst->pattern->type == ROC_NPC_ITEM_TYPE_MPLS)
 		return npc_parse_mpls(pst, NPC_LID_LC);
 
+	info.def_mask = NULL;
 	info.hw_mask = &hw_mask;
 	info.spec = NULL;
 	info.mask = NULL;
@@ -638,10 +644,10 @@ npc_parse_ld(struct npc_parse_state *pst)
 			return npc_parse_mpls(pst, NPC_LID_LD);
 		return 0;
 	}
+	info.def_mask = NULL;
 	info.hw_mask = &hw_mask;
 	info.spec = NULL;
 	info.mask = NULL;
-	info.def_mask = NULL;
 	info.len = 0;
 	info.hw_hdr_len = 0;
 
@@ -797,6 +803,7 @@ npc_parse_lf(struct npc_parse_state *pst)
 	lflags = 0;
 
 	/* No match support for vlan tags */
+	info.def_mask = NULL;
 	info.hw_mask = NULL;
 	info.len = pst->pattern->size;
 	info.spec = NULL;
@@ -855,6 +862,7 @@ npc_parse_lg(struct npc_parse_state *pst)
 	if (!pst->tunnel)
 		return 0;
 
+	info.def_mask = NULL;
 	info.hw_mask = &hw_mask;
 	info.spec = NULL;
 	info.mask = NULL;
@@ -891,6 +899,7 @@ npc_parse_lh(struct npc_parse_state *pst)
 	if (!pst->tunnel)
 		return 0;
 
+	info.def_mask = NULL;
 	info.hw_mask = &hw_mask;
 	info.spec = NULL;
 	info.mask = NULL;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] common/cnxk: check return value for error
  2022-02-12 12:38 [PATCH 1/3] common/cnxk: check return value for error Gowrishankar Muthukrishnan
  2022-02-12 12:38 ` [PATCH 2/3] common/cnx: fix unintended sign extension Gowrishankar Muthukrishnan
  2022-02-12 12:38 ` [PATCH 3/3] common/cnxk: fix uninitialized pointer read Gowrishankar Muthukrishnan
@ 2022-02-18  4:20 ` Jerin Jacob
  2 siblings, 0 replies; 4+ messages in thread
From: Jerin Jacob @ 2022-02-18  4:20 UTC (permalink / raw)
  To: Gowrishankar Muthukrishnan, Ferruh Yigit
  Cc: dpdk-dev, Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori,
	Satha Rao, Jerin Jacob

On Sat, Feb 12, 2022 at 6:08 PM Gowrishankar Muthukrishnan
<gmuthukrishn@marvell.com> wrote:
>
> This patch fixes coverity issue by adding checks on return values.
>
> Coverity issue: 373628, 374858, 370213, 370215
> Fixes: af75aac78978 ("common/cnxk: support telemetry for NIX")
> Fixes: d61138d4f0e ("drivers: remove direct access to interrupt handle")
> Fixes: fcdef46b669 ("common/cnxk: support NIX TM debug and misc utils")
> Fixes: df405df95ee ("common/cnxk: add NIX TM helper to alloc/free resource")
>
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>

Series Acked-by: Jerin Jacob <jerinj@marvell.com>
Series applied to dpdk-next-net-mrvl/for-next-net. Thanks.

> ---
>  drivers/common/cnxk/cnxk_telemetry_nix.c | 3 +++
>  drivers/common/cnxk/roc_irq.c            | 5 ++++-
>  drivers/common/cnxk/roc_nix_debug.c      | 4 +++-
>  drivers/common/cnxk/roc_nix_tm.c         | 6 ++++--
>  4 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/common/cnxk/cnxk_telemetry_nix.c b/drivers/common/cnxk/cnxk_telemetry_nix.c
> index df6458039d..4119e9ee4f 100644
> --- a/drivers/common/cnxk/cnxk_telemetry_nix.c
> +++ b/drivers/common/cnxk/cnxk_telemetry_nix.c
> @@ -765,6 +765,9 @@ cnxk_nix_tel_handle_info_x(const char *cmd, const char *params,
>
>         plt_strlcpy(buf, params, PCI_PRI_STR_SIZE + 1);
>         name = strtok(buf, ",");
> +       if (name == NULL)
> +               goto exit;
> +
>         param = strtok(NULL, "\0");
>
>         node = nix_tel_node_get_by_pcidev_name(name);
> diff --git a/drivers/common/cnxk/roc_irq.c b/drivers/common/cnxk/roc_irq.c
> index 7a24297d72..010b121176 100644
> --- a/drivers/common/cnxk/roc_irq.c
> +++ b/drivers/common/cnxk/roc_irq.c
> @@ -160,7 +160,10 @@ dev_irq_register(struct plt_intr_handle *intr_handle, plt_intr_callback_fn cb,
>                 return rc;
>         }
>
> -       plt_intr_efds_index_set(intr_handle, vec, fd);
> +       rc = plt_intr_efds_index_set(intr_handle, vec, fd);
> +       if (rc)
> +               return rc;
> +
>         nb_efd = (vec > (uint32_t)plt_intr_nb_efd_get(intr_handle)) ?
>                 vec : (uint32_t)plt_intr_nb_efd_get(intr_handle);
>         plt_intr_nb_efd_set(intr_handle, nb_efd);
> diff --git a/drivers/common/cnxk/roc_nix_debug.c b/drivers/common/cnxk/roc_nix_debug.c
> index d5143882f5..1ae045172e 100644
> --- a/drivers/common/cnxk/roc_nix_debug.c
> +++ b/drivers/common/cnxk/roc_nix_debug.c
> @@ -52,7 +52,9 @@ nix_bitmap_dump(struct plt_bitmap *bmp)
>         int i;
>
>         plt_bitmap_scan_init(bmp);
> -       plt_bitmap_scan(bmp, &pos, &slab);
> +       if (!plt_bitmap_scan(bmp, &pos, &slab))
> +               return;
> +
>         start_pos = pos;
>
>         nix_dump_no_nl("  \t\t[");
> diff --git a/drivers/common/cnxk/roc_nix_tm.c b/drivers/common/cnxk/roc_nix_tm.c
> index a0448bec61..517502b1af 100644
> --- a/drivers/common/cnxk/roc_nix_tm.c
> +++ b/drivers/common/cnxk/roc_nix_tm.c
> @@ -1016,8 +1016,10 @@ nix_tm_assign_hw_id(struct nix *nix, struct nix_tm_node *parent,
>                         return -EFAULT;
>                 }
>
> -               if (!slab)
> -                       plt_bitmap_scan(bmp, &pos, &slab);
> +               if (!slab) {
> +                       if (!plt_bitmap_scan(bmp, &pos, &slab))
> +                               return -ENOENT;
> +               }
>
>                 if (child->priority == parent->rr_prio && spare_schq != -1) {
>                         /* Use spare schq first if present */
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-18  4:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-12 12:38 [PATCH 1/3] common/cnxk: check return value for error Gowrishankar Muthukrishnan
2022-02-12 12:38 ` [PATCH 2/3] common/cnx: fix unintended sign extension Gowrishankar Muthukrishnan
2022-02-12 12:38 ` [PATCH 3/3] common/cnxk: fix uninitialized pointer read Gowrishankar Muthukrishnan
2022-02-18  4:20 ` [PATCH 1/3] common/cnxk: check return value for error Jerin Jacob

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.