trace_pid_list_alloc() checks pid_max against a magic number referencing
an (obsolete) source file when it actually should check against the
capacity of pid_list tree. Turn definition of MAX_PID around -- derive
it from tree parameters and replace references to magic value and
header files with so defined MAX_PID.
Should PID_MAX_LIMIT change in future or pid_max escapes PID_MAX_LIMIT,
appropriate checks remain in place. No functional change intended.

Signed-off-by: Michal Koutný <mkou...@suse.com>
---
 kernel/trace/pid_list.c | 6 +++---
 kernel/trace/pid_list.h | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/kernel/trace/pid_list.c b/kernel/trace/pid_list.c
index 95106d02b32d..b968f0b65dc1 100644
--- a/kernel/trace/pid_list.c
+++ b/kernel/trace/pid_list.c
@@ -93,7 +93,7 @@ static inline bool upper_empty(union upper_chunk *chunk)
 static inline int pid_split(unsigned int pid, unsigned int *upper1,
                             unsigned int *upper2, unsigned int *lower)
 {
-       /* MAX_PID should cover all pids */
+       /* MAX_PID must cover all possible pids */
        BUILD_BUG_ON(MAX_PID < PID_MAX_LIMIT);
 
        /* In case a bad pid is passed in, then fail */
@@ -413,8 +413,8 @@ struct trace_pid_list *trace_pid_list_alloc(void)
        struct trace_pid_list *pid_list;
        int i;
 
-       /* According to linux/thread.h, pids can be no bigger that 30 bits */
-       WARN_ON_ONCE(pid_max > (1 << 30));
+       /* See pid_split(), equal to pid_max > PID_MAX_LIMIT */
+       WARN_ON_ONCE(pid_max > MAX_PID);
 
        pid_list = kzalloc(sizeof(*pid_list), GFP_KERNEL);
        if (!pid_list)
diff --git a/kernel/trace/pid_list.h b/kernel/trace/pid_list.h
index 62e73f1ac85f..28562a9a3d01 100644
--- a/kernel/trace/pid_list.h
+++ b/kernel/trace/pid_list.h
@@ -56,8 +56,8 @@
 
 #define UPPER_MASK     (UPPER_MAX - 1)
 
-/* According to linux/thread.h pids can not be bigger than or equal to 1 << 30 
*/
-#define MAX_PID                (1 << 30)
+/* Structure can hold only pids strictly below this limit */
+#define MAX_PID                (1 << (UPPER_BITS + UPPER_BITS + LOWER_BITS))
 
 /* Just keep 6 chunks of both upper and lower in the cache on alloc */
 #define CHUNK_ALLOC 6
-- 
2.44.0


Reply via email to