]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
err.h: add INIT_ERR_PTR() macro
authorChristian Marangi <ansuelsmth@gmail.com>
Fri, 31 Oct 2025 13:08:32 +0000 (14:08 +0100)
committerBjorn Andersson <andersson@kernel.org>
Sat, 1 Nov 2025 17:44:49 +0000 (12:44 -0500)
Add INIT_ERR_PTR() macro to initialize static variables with error
pointers. This might be useful for specific case where there is a static
variable initialized to an error condition and then later set to the
real handle once probe finish/completes.

This is to handle compilation problems like:

error: initializer element is not constant

where ERR_PTR() can't be used.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20251031130835.7953-2-ansuelsmth@gmail.com
[bjorn: Added () suffix on macro references]
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
include/linux/err.h

index 1d60aa86db53b51e2902c0abf1778604ebd769c9..8c37be0620abfc6738b56419a41e88f8f9d767d2 100644 (file)
@@ -41,6 +41,14 @@ static inline void * __must_check ERR_PTR(long error)
        return (void *) error;
 }
 
+/**
+ * INIT_ERR_PTR - Init a const error pointer.
+ * @error: A negative error code.
+ *
+ * Like ERR_PTR(), but usable to initialize static variables.
+ */
+#define INIT_ERR_PTR(error) ((void *)(error))
+
 /* Return the pointer in the percpu address space. */
 #define ERR_PTR_PCPU(error) ((void __percpu *)(unsigned long)ERR_PTR(error))