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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



commit 0ff0e21b89e24d29f7d1eec9b83f9eebc75ca316
Author: H<C3><A5>kon Bugge <Haakon.Bugge@xxxxxxxxxx>
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@xxxxxxxxxx>

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@xxxxxxxxxxxx>
---
 libibumad/umad_sa.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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));
 }
 
-- 
2.8.4




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux