diff mbox series

[rdma-core] libibumad/umad_sa.h: Change to umad_sa_set_rate_mtu_or_life

Message ID 07ec40ba-583e-f738-3251-e06aaf6020be@dev.mellanox.co.il (mailing list archive)
State Not Applicable
Headers show
Series [rdma-core] libibumad/umad_sa.h: Change to umad_sa_set_rate_mtu_or_life | expand

Commit Message

Hal Rosenstock Nov. 21, 2018, 3:51 p.m. UTC
commit 0ff0e21b89e24d29f7d1eec9b83f9eebc75ca316
Author: H<C3><A5>kon Bugge <Haakon.Bugge@oracle.com>
Date:   Tue Nov 20 13:42:11 2018 +0100

    ibacm: Use helper functions and existing defines to avoid literal use

    Use existing helper functions to avoid the use of literal
    constants. Took the liberty to also use those defines in some helper
    functions where appropriate.

    Added an enum for the Multicast Address Scope values.

    Signed-off-by: H<C3><A5>kon Bugge <haakon.bugge@oracle.com>

changed umad_sa_set_rate_mtu_or_life as follows:

static inline uint8_t
 umad_sa_set_rate_mtu_or_life(uint8_t selector, uint8_t rate_mtu_or_life)
 {
-       return (((selector & 0x3) << 6) | (rate_mtu_or_life & 0x3f));
+       return (((selector & UMAD_SA_RATE_MTU_PKT_LIFE_MASK) << UMAD_SA_SELECTOR
_SHIFT) |
+               (rate_mtu_or_life & UMAD_SA_RATE_MTU_PKT_LIFE_MASK));
 }

so 0x3 was changed to 0x3f (UMAD_SA_RATE_MTU_PKT_LIFE_MASK).
While this should work due to using left shift by 6 on 8 bit variable,
a more literal translation is better IMO.

Signed-off-by: Hal Rosenstock <hal@mellanox.com>
---
 libibumad/umad_sa.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/libibumad/umad_sa.h b/libibumad/umad_sa.h
index 4ade055..b07774b 100644
--- a/libibumad/umad_sa.h
+++ b/libibumad/umad_sa.h
@@ -138,6 +138,7 @@  enum {
 
 #define UMAD_SA_SELECTOR_SHIFT		6
 #define UMAD_SA_RATE_MTU_PKT_LIFE_MASK	0x3f
+#define UMAD_SA_SELECTOR_MASK		0x3
 
 /*
  *  sm_key is not aligned on an 8-byte boundary, so is defined as a byte array
@@ -161,7 +162,7 @@  umad_sa_get_rate_mtu_or_life(uint8_t rate_mtu_or_life)
 static inline uint8_t
 umad_sa_set_rate_mtu_or_life(uint8_t selector, uint8_t rate_mtu_or_life)
 {
-	return (((selector & UMAD_SA_RATE_MTU_PKT_LIFE_MASK) << UMAD_SA_SELECTOR_SHIFT) |
+	return (((selector & UMAD_SA_SELECTOR_MASK) << UMAD_SA_SELECTOR_SHIFT) |
 		(rate_mtu_or_life & UMAD_SA_RATE_MTU_PKT_LIFE_MASK));
 }