From patchwork Mon Mar 14 21:47:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102584 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp291195lbc; Mon, 14 Mar 2016 14:48:39 -0700 (PDT) X-Received: by 10.98.93.205 with SMTP id n74mr33216880pfj.99.1457992119255; Mon, 14 Mar 2016 14:48:39 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r72si7147792pfb.235.2016.03.14.14.48.38; Mon, 14 Mar 2016 14:48:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751909AbcCNVsh (ORCPT + 31 others); Mon, 14 Mar 2016 17:48:37 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:63552 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750958AbcCNVsd (ORCPT ); Mon, 14 Mar 2016 17:48:33 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue002) with ESMTPA (Nemesis) id 0MZKwe-1aPAUD1896-00KzhY; Mon, 14 Mar 2016 22:48:13 +0100 From: Arnd Bergmann To: Serge Hallyn Cc: David Howells , Arnd Bergmann , Yaowei Bai , James Morris , Andrew Morton , "Paul E. McKenney" , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] cred/userns: define current_user_ns() as a function Date: Mon, 14 Mar 2016 22:47:33 +0100 Message-Id: <1457992081-150281-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:h+X9IHP7SeytudbS8Wr7wtb3/xq8ck8gOuenth8uLwGErx5cWnK Po0Lon3XP+4GsyGmKBa9lwDm4Z8AJSHZ8lFIzKJsDEdVACMayDAfGmamOym58+yOx82brFC gzDl/9zsYCBd9pFy31SnnKy3yoLZDvIFn5ctnHAmFHLBHWM2Wq1QwbFV3+2s2Y9ET4a/CQc 3DJNBO6yP/l2zlKR5QPtA== X-UI-Out-Filterresults: notjunk:1; V01:K0:bpKPB+3xxKM=:qLu1B74Tjm/GVeVixAN36c 6ZJkNpss9zQc4NvyObAjALJ5PwJnQbUtrI/UQibv7VRGR2QQuVQdhLYFlrubue8XpDdRgc135 l//kmhzV4nJtwI5KIMZCKH5E9OAH8YtgwgobVqV+QFExPjEy68KMgvkgTUmRXEAgvEukdPOox KjFGDfe1HgzbyWHrYMWGlKdS7E+dkWQmaZ/eT7UmyUIFTuOV+yXWgI+6il/vUEAq3Ng9azc44 yL52sVVT5hpBulCA+GrMASMOFjozwqJeMhPgXErQ99F7V/x7uKSVr+0/D9r3yK5fGwYDBWejY sU6wkWRGtBtFme0yguQSJkDpP/CZ3Zm9veQKOVUlj8f4MtX5A90EzTc1Cgzk8C2mu4pgqNl8R iOeil6pkyOx5/vEmrdXt69YByiwUykDkeUF58Q8AG8xLEs1/1CziQU/eAdFdX02505s3QpdJo kjnUwJPUMVUOQfDsKkB4s7QoN6Sa4z2ye+gqu7CTqQC/iw3SltmOZXBCfo3tWE/16V9aI27eI tMQyKdz4byB6xkmRbUQb3hfUflaLNvxObeCCRFm3XE5Eocnf8MJSQB/Chab3UBtWQBIwXWhdM 4qfd6kzCWpRVEIB87gCbMERo3lP6es5SZFDQKP/Yg0RIn5aoQt6/uoiTFziQw2sc+wUyBaCwf BEz/QKcoO6rwwEHxb0WPiWAAIk4QAPDhADnk9dhEWqcW0/RKW+X01XLrlI0Xp2vsz9/U= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- include/linux/capability.h | 2 -- include/linux/cred.h | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) -- 2.7.0 diff --git a/include/linux/capability.h b/include/linux/capability.h index f314275d4e3f..00690ff92edf 100644 --- a/include/linux/capability.h +++ b/include/linux/capability.h @@ -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; diff --git a/include/linux/cred.h b/include/linux/cred.h index 8d70e1361ecd..257db64562e5 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h @@ -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