Skip to content

Commit 0335695

Browse files
arndbtorvalds
authored andcommitted
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. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Serge Hallyn <serge.hallyn@canonical.com> Cc: David Howells <dhowells@redhat.com> Cc: Yaowei Bai <baiyaowei@cmss.chinamobile.com> Cc: James Morris <james.l.morris@oracle.com> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e8de370 commit 0335695

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

‎include/linux/capability.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ struct inode;
4040
struct dentry;
4141
struct user_namespace;
4242

43-
struct user_namespace *current_user_ns(void);
44-
4543
extern const kernel_cap_t __cap_empty_set;
4644
extern const kernel_cap_t __cap_init_eff_set;
4745

‎include/linux/cred.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ extern struct user_namespace init_user_ns;
377377
#ifdef CONFIG_USER_NS
378378
#define current_user_ns() (current_cred_xxx(user_ns))
379379
#else
380-
#define current_user_ns() (&init_user_ns)
380+
static inline struct user_namespace *current_user_ns(void)
381+
{
382+
return &init_user_ns;
383+
}
381384
#endif
382385

383386

0 commit comments

Comments
 (0)