[PATCH 3/6] tools/nolibc: transform makedev() and friends into functions

Thomas Weißschuh posted 6 patches 14 hours ago
[PATCH 3/6] tools/nolibc: transform makedev() and friends into functions
Posted by Thomas Weißschuh 14 hours ago
Functions make it easier to keep the input and output types straight and
avoid duplicate evaluations of their arguments.

Also these functions will become a bit more complex to handle full
64-bit 'dev_t' which is easier to read in a function.

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
 tools/include/nolibc/sys/sysmacros.h | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/tools/include/nolibc/sys/sysmacros.h b/tools/include/nolibc/sys/sysmacros.h
index 37c33f030f02..eb4a9197546e 100644
--- a/tools/include/nolibc/sys/sysmacros.h
+++ b/tools/include/nolibc/sys/sysmacros.h
@@ -13,8 +13,19 @@
 #include "../std.h"
 
 /* WARNING, it only deals with the 4096 first majors and 256 first minors */
-#define makedev(major, minor) ((dev_t)((((major) & 0xfff) << 8) | ((minor) & 0xff)))
-#define major(dev) ((unsigned int)(((dev) >> 8) & 0xfff))
-#define minor(dev) ((unsigned int)((dev) & 0xff))
+static __inline__ dev_t makedev(unsigned int maj, unsigned int min)
+{
+	return ((maj & 0xfff) << 8) | (min & 0xff);
+}
+
+static __inline__ unsigned int major(dev_t dev)
+{
+	return (dev >> 8) & 0xfff;
+}
+
+static __inline__ unsigned int minor(dev_t dev)
+{
+	return dev & 0xff;
+}
 
 #endif /* _NOLIBC_SYS_SYSMACROS_H */

-- 
2.53.0