Add helpers for checking alignment to util/size.h.

Signed-off-by: Dan Williams <[email protected]>
---
 ndctl/lib/ars.c |    6 +-----
 util/size.h     |    7 +++++++
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/ndctl/lib/ars.c b/ndctl/lib/ars.c
index bd75131081ba..d91a99d00d10 100644
--- a/ndctl/lib/ars.c
+++ b/ndctl/lib/ars.c
@@ -11,6 +11,7 @@
  * more details.
  */
 #include <stdlib.h>
+#include <util/size.h>
 #include <ndctl/libndctl.h>
 #include "private.h"
 
@@ -43,11 +44,6 @@ NDCTL_EXPORT struct ndctl_cmd 
*ndctl_bus_cmd_new_ars_cap(struct ndctl_bus *bus,
        return cmd;
 }
 
-static bool is_power_of_2(unsigned int v)
-{
-       return v && ((v & (v - 1)) == 0);
-}
-
 static bool validate_clear_error(struct ndctl_cmd *ars_cap)
 {
        if (!is_power_of_2(ars_cap->ars_cap->clear_err_unit))
diff --git a/util/size.h b/util/size.h
index 34fac58d6945..2f36c2c85ca7 100644
--- a/util/size.h
+++ b/util/size.h
@@ -13,6 +13,7 @@
 
 #ifndef _NDCTL_SIZE_H_
 #define _NDCTL_SIZE_H_
+#include <stdbool.h>
 
 #define SZ_1K     0x00000400
 #define SZ_4K     0x00001000
@@ -27,8 +28,14 @@
 unsigned long long parse_size64(const char *str);
 unsigned long long __parse_size64(const char *str, unsigned long long *units);
 
+static inline bool is_power_of_2(unsigned long long v)
+{
+       return v && ((v & (v - 1)) == 0);
+}
+
 #define ALIGN(x, a) ((((unsigned long long) x) + (a - 1)) & ~(a - 1))
 #define ALIGN_DOWN(x, a) (((((unsigned long long) x) + a) & ~(a - 1)) - a)
+#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
 #define BITS_PER_LONG (sizeof(unsigned long) * 8)
 #define HPAGE_SIZE (2 << 20)
 
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to