cred/userns: define current_user_ns() as a function
Subsystems (2)
PATCH 1/1 cred/userns: define current_user_ns() as a function
The current_user_ns() macro currently returns &init_user_ns when user namespaces are disabled, and that causes several warnings when building with gcc-6.0 in code that compares the result of the macro to &init_user_ns itself:
fs/xfs/xfs_ioctl.c: In function 'xfs_ioctl_setattr_check_projid':fs/xfs/xfs_ioctl.c:1249:22: error: self-comparison always evaluates to true [-Werror=tautological-compare]
if (current_user_ns() == &init_user_ns)
This is a legitimate warning in principle, but here it isn't really helpful, so I'm reprasing the definition in a way that shuts up the warning. Apparently gcc only warns when comparing identical literals, but it can figure out that the result of an inline function can be identical to a constant expression in order to optimize a condition yet not warn about the fact that the condition is known at compile time. This is exactly what we want here, and it looks reasonable because we generally prefer inline functions over macros anyway.
--- include/linux/capability.h | 2 -- include/linux/cred.h | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-)
include/linux/capability.h +0 -2
@@ -40,8 +40,6 @@ struct inode;struct dentry ;struct user_namespace ; -struct user_namespace *current_user_ns (void ); -extern const kernel_cap_t __cap_empty_set;extern const kernel_cap_t __cap_init_eff_set;
include/linux/cred.h +4 -1
@@ -377,7 +377,10 @@ extern struct user_namespace init_user_ns;#ifdef CONFIG_USER_NS #define current_user_ns () (current_cred_xxx(user_ns))#else -#define current_user_ns () (&init_user_ns) +static inline struct user_namespace *current_user_ns (void ) +{ +return &init_user_ns; +}#endif
Signature · 1 line
2.7.0
Quoted 19 lines · Arnd Bergmann
The
current_user_ns()macro currently returns&init_user_nswhen user namespaces are disabled, and that causes several warnings when building with gcc-6.0 in code that compares the result of the macro to&init_user_nsitself:
fs/xfs/xfs_ioctl.c: In function 'xfs_ioctl_setattr_check_projid':fs/xfs/xfs_ioctl.c:1249:22: error: self-comparison always evaluates to true [-Werror=tautological-compare]
if (current_user_ns()==&init_user_ns)This is a legitimate warning in principle, but here it isn't really helpful, so I'm reprasing the definition in a way that shuts up the warning. Apparently gcc only warns when comparing identical literals, but it can figure out that the result of an inline function can be identical to a constant expression in order to optimize a condition yet not warn about the fact that the condition is known at compile time. This is exactly what we want here, and it looks reasonable because we generally prefer inline functions over macros anyway.
Quoted 1 line
Signed-off-by Arnd Bergmann <[email protected]>
Was a bit worried about the first hunk since capability.h doesn't include cred.h explicitly, but I guess if that was a problem it would've not compiled long ago due to current_cred_xxx().
Quoted 36 lines
--- include/linux/capability.h | 2 -- include/linux/cred.h | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-)include/linux/capability.h +0
-2@@ -40,8 +40,6 @@ struct inode;struct dentry ;struct user_namespace ; -struct user_namespace *current_user_ns (void ); -extern const kernel_cap_t __cap_empty_set;extern const kernel_cap_t __cap_init_eff_set;include/linux/cred.h +4
-1@@ -377,7 +377,10 @@ extern struct user_namespace init_user_ns;#ifdef CONFIG_USER_NS #define current_user_ns () (current_cred_xxx(user_ns))#else -#define current_user_ns () (&init_user_ns) +static inline struct user_namespace *current_user_ns (void ) +{ +return &init_user_ns; +}#endif Signature · 1 line
2.7.0