linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions
@ 2024-08-13 17:25 Uros Bizjak
  2024-08-13 17:25 ` [PATCH 2/2] mm/kmemleak: Use IS_ERR_PCPU() for pointer in the percpu address space Uros Bizjak
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Uros Bizjak @ 2024-08-13 17:25 UTC (permalink / raw)
  To: linux-mm, linux-kernel; +Cc: Uros Bizjak, Catalin Marinas, Andrew Morton

Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions that
operate on pointers in the percpu address space.

These functions remove the need for (__force void *) function
argument casts (to avoid sparse -Wcast-from-as warnings).

The patch will also avoid future build errors due to pointer address
space mismatch with enabled strict percpu address space checks.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 include/linux/err.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/include/linux/err.h b/include/linux/err.h
index b5d9bb2a2349..997fd6fe1d0c 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -6,6 +6,7 @@
 #include <linux/types.h>
 
 #include <asm/errno.h>
+#include <asm/percpu.h>
 
 /*
  * Kernel pointers have redundant information, so we can use a
@@ -41,6 +42,22 @@ static inline void * __must_check ERR_PTR(long error)
 	return (void *) error;
 }
 
+/**
+ * ERR_PTR_PCPU - Create an error pointer in the percpu address space.
+ * @error: A negative error code.
+ *
+ * Encodes @error into a pointer value in the percpu address space.
+ * Users should consider the result opaque and not assume anything
+ * about how the error is encoded.
+ *
+ * Return: A pointer in the percpu address space with @error encoded
+ *	   within its value.
+ */
+static inline void __percpu * __must_check ERR_PTR_PCPU(long error)
+{
+	return (void __percpu *) error;
+}
+
 /**
  * PTR_ERR - Extract the error code from an error pointer.
  * @ptr: An error pointer.
@@ -51,6 +68,17 @@ static inline long __must_check PTR_ERR(__force const void *ptr)
 	return (long) ptr;
 }
 
+/**
+ * PTR_ERR_PCPU - Extract the error code from an error pointer in the
+ *		  percpu address space.
+ * @ptr: An error pointer in the percpu address space.
+ * Return: The error code within @ptr.
+ */
+static inline long __must_check PTR_ERR_PCPU(const void __percpu *ptr)
+{
+	return (__force long) ptr;
+}
+
 /**
  * IS_ERR - Detect an error pointer.
  * @ptr: The pointer to check.
@@ -61,6 +89,16 @@ static inline bool __must_check IS_ERR(__force const void *ptr)
 	return IS_ERR_VALUE((unsigned long)ptr);
 }
 
+/**
+ * IS_ERR_PCPU - Detect an error pointer in the percpu address space.
+ * @ptr: The pointer in the percpu address space to check.
+ * Return: true if @ptr is an error pointer, false otherwise.
+ */
+static inline bool __must_check IS_ERR_PCPU(const void __percpu *ptr)
+{
+	return IS_ERR_VALUE((__force unsigned long)ptr);
+}
+
 /**
  * IS_ERR_OR_NULL - Detect an error pointer or a null pointer.
  * @ptr: The pointer to check.
-- 
2.42.0



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-08-15  4:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-13 17:25 [PATCH 1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions Uros Bizjak
2024-08-13 17:25 ` [PATCH 2/2] mm/kmemleak: Use IS_ERR_PCPU() for pointer in the percpu address space Uros Bizjak
2024-08-14 12:15   ` Catalin Marinas
2024-08-14 12:15 ` [PATCH 1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions Catalin Marinas
2024-08-15  1:52 ` kernel test robot
2024-08-15  4:29 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox