Skip to contentSkip to conversation

kernel.h: Split out min()/max() et al. helpers

PATCH New Andy Shevchenko 1 participant 1 message Sep 10, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel.h: Split out min()/max() et al. helpers

kernel.h is being used as a dump for all kinds of stuff for a long time. Here is the attempt to start cleaning it up by splitting out min()/max() et al. helpers.

At the same time convert users in header and lib folder to use new header. Though for time being include new header back to kernel.h to avoid twisted indirected includes for other existing users.

---

This header being standalone makes possible to avoid unnecessary inclusion of kernel.h and its content to many places which would like to use min()/max() helpers and/or related without being poisoned like [1].

I heard earlier opinions about this, like [2] or [3] and would like to see if this is a way to go.

I have Cc'ed parties gathered from all previous submissions of this + Linus.

[1]: https://lore.kernel.org/linux-acpi/[email protected]/
[2]: https://lore.kernel.org/patchwork/patch/1189564/
[3]: https://lore.kernel.org/lkml/[email protected]/

 include/linux/blkdev.h    |   1 +
 include/linux/bvec.h      |   6 +-
 include/linux/jiffies.h   |   3 +-
 include/linux/kernel.h    | 150 +------------------------------------
 include/linux/minmax.h    | 153 ++++++++++++++++++++++++++++++++++++++
 include/linux/nodemask.h  |   2 +-
 include/linux/uaccess.h   |   1 +
 kernel/range.c            |   3 +-
 lib/find_bit.c            |   1 +
 lib/hexdump.c             |   1 +
 lib/math/rational.c       |   2 +-
 lib/math/reciprocal_div.c |   1 +
 12 files changed, 170 insertions(+), 154 deletions(-)
 create mode 100644 include/linux/minmax.h
include/linux/blkdev.h +1 -0
index 37ec5a73d027..7d5dc329c41c 100644
@@ -8,6 +8,7 @@
 #include <linux/genhd.h>
 #include <linux/list.h>
 #include <linux/llist.h>
+#include <linux/minmax.h>
 #include <linux/timer.h>
 #include <linux/workqueue.h>
 #include <linux/pagemap.h>
include/linux/bvec.h +5 -1
index dd74503f7e5e..2efec10bf792 100644
@@ -7,10 +7,14 @@
 #ifndef __LINUX_BVEC_ITER_H
 #define __LINUX_BVEC_ITER_H
 
-#include <linux/kernel.h>
 #include <linux/bug.h>
 #include <linux/errno.h>
+#include <linux/limits.h>
+#include <linux/minmax.h>
 #include <linux/mm.h>
+#include <linux/types.h>
+
+struct page;
 
 /**
  * struct bio_vec - a contiguous range of physical memory addresses
include/linux/jiffies.h +2 -1
index fed6ba96c527..5e13f801c902 100644
@@ -3,8 +3,9 @@
 #define _LINUX_JIFFIES_H
 
 #include <linux/cache.h>
+#include <linux/limits.h>
 #include <linux/math64.h>
-#include <linux/kernel.h>
+#include <linux/minmax.h>
 #include <linux/types.h>
 #include <linux/time.h>
 #include <linux/timex.h>
include/linux/kernel.h +1 -149

162 lines not on this page · raw message

include/linux/minmax.h new file +153 -0

153 lines not on this page · raw message

include/linux/nodemask.h +1 -1
index 27e7fa36f707..7f38399cc9fe 100644
@@ -90,9 +90,9 @@
  * for such situations. See below and CPUMASK_ALLOC also.
  */
 
-#include <linux/kernel.h>
 #include <linux/threads.h>
 #include <linux/bitmap.h>
+#include <linux/minmax.h>
 #include <linux/numa.h>
 
 typedef struct { DECLARE_BITMAP(bits, MAX_NUMNODES); } nodemask_t;
include/linux/uaccess.h +1 -0
index 8a004bcd6c20..6deff827dc9d 100644
@@ -4,6 +4,7 @@
 
 #include <linux/fault-inject-usercopy.h>
 #include <linux/instrumented.h>
+#include <linux/minmax.h>
 #include <linux/sched.h>
 #include <linux/thread_info.h>
 
kernel/range.c +2 -1
index d84de6766472..56435f96da73 100644
@@ -2,8 +2,9 @@
 /*
  * Range add and subtract
  */
-#include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/minmax.h>
+#include <linux/printk.h>
 #include <linux/sort.h>
 #include <linux/string.h>
 #include <linux/range.h>
lib/find_bit.c +1 -0
index 49f875f1baf7..4a8751010d59 100644
@@ -16,6 +16,7 @@
 #include <linux/bitmap.h>
 #include <linux/export.h>
 #include <linux/kernel.h>
+#include <linux/minmax.h>
 
 #if !defined(find_next_bit) || !defined(find_next_zero_bit) ||			\
 	!defined(find_next_bit_le) || !defined(find_next_zero_bit_le) ||	\
lib/hexdump.c +1 -0
index 147133f8eb2f..9301578f98e8 100644
@@ -7,6 +7,7 @@
 #include <linux/ctype.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
+#include <linux/minmax.h>
 #include <linux/export.h>
 #include <asm/unaligned.h>
 
lib/math/rational.c +1 -1
index df75c8809693..9781d521963d 100644
@@ -11,7 +11,7 @@
 #include <linux/rational.h>
 #include <linux/compiler.h>
 #include <linux/export.h>
-#include <linux/kernel.h>
+#include <linux/minmax.h>
 
 /*
  * calculate best rational approximation for a given fraction
lib/math/reciprocal_div.c +1 -0
index bf043258fa00..32436dd4171e 100644
@@ -4,6 +4,7 @@
 #include <asm/div64.h>
 #include <linux/reciprocal_div.h>
 #include <linux/export.h>
+#include <linux/minmax.h>
 
 /*
  * For a description of the algorithm please have a look at
Signature · 1 line
2.28.0