[02/16] common/cnxk: use previous value atomic fetch operations

Message ID 1678486530-20688-3-git-send-email-roretzla@linux.microsoft.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series use __atomic operations returning new value |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Tyler Retzlaff March 10, 2023, 10:15 p.m. UTC
  Use __atomic_fetch_{add,and,or,sub,xor} instead of
__atomic_{add,and,or,sub,xor}_fetch adding the necessary code to
allow consumption of the resulting value.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 drivers/common/cnxk/roc_ae.c            | 2 +-
 drivers/common/cnxk/roc_ae_fpm_tables.c | 2 +-
 drivers/common/cnxk/roc_npa.c           | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/common/cnxk/roc_ae.c b/drivers/common/cnxk/roc_ae.c
index 929da05..336b927 100644
--- a/drivers/common/cnxk/roc_ae.c
+++ b/drivers/common/cnxk/roc_ae.c
@@ -203,6 +203,6 @@  struct ae_ec_grp_tbl {
 
 	ec_grp = mz->addr;
 	/* Decrement number of devices using EC grp table */
-	if (__atomic_sub_fetch(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&ec_grp->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
diff --git a/drivers/common/cnxk/roc_ae_fpm_tables.c b/drivers/common/cnxk/roc_ae_fpm_tables.c
index afb2a50..f915702 100644
--- a/drivers/common/cnxk/roc_ae_fpm_tables.c
+++ b/drivers/common/cnxk/roc_ae_fpm_tables.c
@@ -1135,6 +1135,6 @@  struct ae_fpm_tbl {
 
 	fpm = (struct ae_fpm_tbl *)mz->addr;
 	/* Decrement number of devices using FPM table */
-	if (__atomic_sub_fetch(&fpm->refcount, 1, __ATOMIC_SEQ_CST) == 0)
+	if (__atomic_fetch_sub(&fpm->refcount, 1, __ATOMIC_SEQ_CST) - 1 == 0)
 		plt_memzone_free(mz);
 }
diff --git a/drivers/common/cnxk/roc_npa.c b/drivers/common/cnxk/roc_npa.c
index 69c3d8d..20637fb 100644
--- a/drivers/common/cnxk/roc_npa.c
+++ b/drivers/common/cnxk/roc_npa.c
@@ -946,7 +946,7 @@ 
 		return NPA_ERR_ALLOC;
 
 	/* Not the last PCI device */
-	if (__atomic_sub_fetch(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) != 0)
+	if (__atomic_fetch_sub(&idev->npa_refcnt, 1, __ATOMIC_SEQ_CST) - 1 != 0)
 		return 0;
 
 	npa_unregister_irqs(idev->npa);