block: change ioprio_valid() to an inline function
authorDamien Le Moal <damien.lemoal@wdc.com>
Wed, 11 Aug 2021 03:36:59 +0000 (12:36 +0900)
committerJens Axboe <axboe@kernel.dk>
Wed, 18 Aug 2021 13:21:11 +0000 (07:21 -0600)
Change the ioprio_valid() macro in include/usapi/linux/ioprio.h to an
inline function declared on the kernel side in include/linux/ioprio.h.
Also improve checks on the class value by checking the upper bound
value.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Link: https://lore.kernel.org/r/20210811033702.368488-4-damien.lemoal@wdc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/linux/ioprio.h
include/uapi/linux/ioprio.h

index ef9ad4fb245fe72b6b656059d35b5245d91ddfdb..2ee3373684b115384cece8e901e3e76771b5cc8b 100644 (file)
@@ -8,6 +8,16 @@
 
 #include <uapi/linux/ioprio.h>
 
+/*
+ * Check that a priority value has a valid class.
+ */
+static inline bool ioprio_valid(unsigned short ioprio)
+{
+       unsigned short class = IOPRIO_PRIO_CLASS(ioprio);
+
+       return class > IOPRIO_CLASS_NONE && class <= IOPRIO_CLASS_IDLE;
+}
+
 /*
  * if process has set io priority explicitly, use that. if not, convert
  * the cpu scheduler nice value to an io priority
index 6b735854aebd292e33aa6ea6f772a1e1536be6a4..5064e230374c4dcdbac7a52ad180fe0bdbb8f141 100644 (file)
@@ -27,8 +27,6 @@ enum {
        IOPRIO_CLASS_IDLE,
 };
 
-#define ioprio_valid(mask)     (IOPRIO_PRIO_CLASS((mask)) != IOPRIO_CLASS_NONE)
-
 /*
  * 8 best effort priority levels are supported
  */