[2/8] common/cnxk: use for loop in shaper profiles cleanup

Message ID 20211209091342.27017-2-ndabilpuram@marvell.com (mailing list archive)
State Changes Requested, archived
Delegated to: Jerin Jacob
Headers
Series [1/8] common/cnxk: fix shift offset for tl3 length disable |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Nithin Dabilpuram Dec. 9, 2021, 9:13 a.m. UTC
  From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>

In shaper profiles cleanup, KW reports infinite loop although existing
loop condition is alright. False positive may be due to tqh_first not
checked in loop, hence switching to FOREACH_SAFE to make KW happy.

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Signed-off-by: Shijith Thotton <sthotton@marvell.com>
---
 drivers/common/cnxk/roc_nix_tm.c   | 8 ++++----
 drivers/common/cnxk/roc_platform.h | 2 ++
 2 files changed, 6 insertions(+), 4 deletions(-)
  

Comments

Jerin Jacob Jan. 19, 2022, 4:20 p.m. UTC | #1
On Thu, Dec 9, 2021 at 2:44 PM Nithin Dabilpuram
<ndabilpuram@marvell.com> wrote:
>
> From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
>
> In shaper profiles cleanup, KW reports infinite loop although existing
> loop condition is alright. False positive may be due to tqh_first not
> checked in loop, hence switching to FOREACH_SAFE to make KW happy.
>
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
> Signed-off-by: Shijith Thotton <sthotton@marvell.com>

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

Changed the git log to:


common/cnxk: use for loop in shaper profiles cleanup

In shaper profiles cleanup, Klockwork static analyzer tool reports
infinite loop although existing loop condition is alright.
False positive may be due to tqh_first not checked in loop,
hence switching to FOREACH_SAFE to make Klockwork happy.

> ---
>  drivers/common/cnxk/roc_nix_tm.c   | 8 ++++----
>  drivers/common/cnxk/roc_platform.h | 2 ++
>  2 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/common/cnxk/roc_nix_tm.c b/drivers/common/cnxk/roc_nix_tm.c
> index b3d8ebd..fe9e83f 100644
> --- a/drivers/common/cnxk/roc_nix_tm.c
> +++ b/drivers/common/cnxk/roc_nix_tm.c
> @@ -17,16 +17,16 @@ bitmap_ctzll(uint64_t slab)
>  void
>  nix_tm_clear_shaper_profiles(struct nix *nix)
>  {
> -       struct nix_tm_shaper_profile *shaper_profile;
> +       struct nix_tm_shaper_profile *shaper_profile, *tmp;
> +       struct nix_tm_shaper_profile_list *list;
>
> -       shaper_profile = TAILQ_FIRST(&nix->shaper_profile_list);
> -       while (shaper_profile != NULL) {
> +       list = &nix->shaper_profile_list;
> +       PLT_TAILQ_FOREACH_SAFE(shaper_profile, list, shaper, tmp) {
>                 if (shaper_profile->ref_cnt)
>                         plt_warn("Shaper profile %u has non zero references",
>                                  shaper_profile->id);
>                 TAILQ_REMOVE(&nix->shaper_profile_list, shaper_profile, shaper);
>                 nix_tm_shaper_profile_free(shaper_profile);
> -               shaper_profile = TAILQ_FIRST(&nix->shaper_profile_list);
>         }
>  }
>
> diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h
> index 61d4781..3648e84 100644
> --- a/drivers/common/cnxk/roc_platform.h
> +++ b/drivers/common/cnxk/roc_platform.h
> @@ -19,6 +19,7 @@
>  #include <rte_pci.h>
>  #include <rte_spinlock.h>
>  #include <rte_string_fns.h>
> +#include <rte_tailq.h>
>  #include <rte_telemetry.h>
>
>  #include "roc_bits.h"
> @@ -53,6 +54,7 @@
>  #define BITMASK_ULL             GENMASK_ULL
>  #define PLT_ALIGN_CEIL          RTE_ALIGN_CEIL
>  #define PLT_INIT                RTE_INIT
> +#define PLT_TAILQ_FOREACH_SAFE  RTE_TAILQ_FOREACH_SAFE
>
>  /** Divide ceil */
>  #define PLT_DIV_CEIL(x, y)                     \
> --
> 2.8.4
>
  

Patch

diff --git a/drivers/common/cnxk/roc_nix_tm.c b/drivers/common/cnxk/roc_nix_tm.c
index b3d8ebd..fe9e83f 100644
--- a/drivers/common/cnxk/roc_nix_tm.c
+++ b/drivers/common/cnxk/roc_nix_tm.c
@@ -17,16 +17,16 @@  bitmap_ctzll(uint64_t slab)
 void
 nix_tm_clear_shaper_profiles(struct nix *nix)
 {
-	struct nix_tm_shaper_profile *shaper_profile;
+	struct nix_tm_shaper_profile *shaper_profile, *tmp;
+	struct nix_tm_shaper_profile_list *list;
 
-	shaper_profile = TAILQ_FIRST(&nix->shaper_profile_list);
-	while (shaper_profile != NULL) {
+	list = &nix->shaper_profile_list;
+	PLT_TAILQ_FOREACH_SAFE(shaper_profile, list, shaper, tmp) {
 		if (shaper_profile->ref_cnt)
 			plt_warn("Shaper profile %u has non zero references",
 				 shaper_profile->id);
 		TAILQ_REMOVE(&nix->shaper_profile_list, shaper_profile, shaper);
 		nix_tm_shaper_profile_free(shaper_profile);
-		shaper_profile = TAILQ_FIRST(&nix->shaper_profile_list);
 	}
 }
 
diff --git a/drivers/common/cnxk/roc_platform.h b/drivers/common/cnxk/roc_platform.h
index 61d4781..3648e84 100644
--- a/drivers/common/cnxk/roc_platform.h
+++ b/drivers/common/cnxk/roc_platform.h
@@ -19,6 +19,7 @@ 
 #include <rte_pci.h>
 #include <rte_spinlock.h>
 #include <rte_string_fns.h>
+#include <rte_tailq.h>
 #include <rte_telemetry.h>
 
 #include "roc_bits.h"
@@ -53,6 +54,7 @@ 
 #define BITMASK_ULL		 GENMASK_ULL
 #define PLT_ALIGN_CEIL		 RTE_ALIGN_CEIL
 #define PLT_INIT		 RTE_INIT
+#define PLT_TAILQ_FOREACH_SAFE	 RTE_TAILQ_FOREACH_SAFE
 
 /** Divide ceil */
 #define PLT_DIV_CEIL(x, y)			\