[PATCH] pid_namespace: Add stub for to_pid_ns() when CONFIG_PID_NS is disabled
From: Pengpeng Hou
Date: Mon Mar 02 2026 - 03:51:11 EST
Currently, to_pid_ns() is only defined when CONFIG_PID_NS is enabled. This
leads to compilation errors in subsystems that attempt to retrieve a PID
namespace from an ns_common structure in a non-namespace-aware kernel
configuration.
This patch adds a static inline stub for to_pid_ns() in the #else block,
returning the address of the global init_pid_ns. This ensures consistent
API availability and fixes potential build failures.
Signed-off-by: Pengpeng Hou <pengpeng.hou@xxxxxxxxxxxxxxxx>
---
include/linux/pid_namespace.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
index b20baaa7e..ca6032db8 100644
--- a/include/linux/pid_namespace.h
+++ b/include/linux/pid_namespace.h
@@ -103,7 +103,10 @@ static inline int pidns_memfd_noexec_scope(struct pid_namespace *ns)
{
return 0;
}
-
+static inline struct pid_namespace *to_pid_ns(struct ns_common *ns)
+{
+ return &init_pid_ns;
+}
static inline struct pid_namespace *copy_pid_ns(u64 flags,
struct user_namespace *user_ns, struct pid_namespace *ns)
{
--
2.25.1