[PATCH v4 34/35] linux/kernel.h: move PTR_IF() to ptr_util.h

From: Max Kellermann
Date: Sun Feb 11 2024 - 18:21:57 EST


Reducing dependencies on the header linux/kernel.h.

Signed-off-by: Max Kellermann <max.kellermann@xxxxxxxxx>
---
include/linux/kernel.h | 3 +--
include/linux/pm.h | 2 +-
include/linux/ptr_util.h | 7 +++++++
3 files changed, 9 insertions(+), 3 deletions(-)
create mode 100644 include/linux/ptr_util.h

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 6f436367dd16..e323fe139cc8 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -32,6 +32,7 @@
#include <linux/sprintf.h>
#include <linux/static_call_types.h>
#include <linux/instruction_pointer.h>
+#include <linux/ptr_util.h>
#include <linux/wordpart.h>
#include <asm/byteorder.h>

@@ -39,8 +40,6 @@

#define STACK_MAGIC 0xdeadbeef

-#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
-
#define u64_to_user_ptr(x) ( \
{ \
typecheck(u64, (x)); \
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 34cf20dd1ad1..cccf320b67f6 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -9,7 +9,7 @@
#define _LINUX_PM_H

#include <linux/export.h>
-#include <linux/kernel.h> // for PTR_IF()
+#include <linux/ptr_util.h> // for PTR_IF()
#include <linux/list.h>
#include <linux/workqueue_types.h>
#include <linux/spinlock_types.h>
diff --git a/include/linux/ptr_util.h b/include/linux/ptr_util.h
new file mode 100644
index 000000000000..7469aff978a9
--- /dev/null
+++ b/include/linux/ptr_util.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_PTR_UTIL_H
+#define _LINUX_PTR_UTIL_H
+
+#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL)
+
+#endif /* _LINUX_PTR_UTIL_H */
--
2.39.2