From patchwork Mon Oct 10 11:12:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101714 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1149582qge; Mon, 10 Oct 2016 04:13:52 -0700 (PDT) X-Received: by 10.66.160.72 with SMTP id xi8mr52912791pab.78.1476098032383; Mon, 10 Oct 2016 04:13:52 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id hr2si30549557pad.44.2016.10.10.04.13.52; Mon, 10 Oct 2016 04:13:52 -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 S1751297AbcJJLNl (ORCPT + 27 others); Mon, 10 Oct 2016 07:13:41 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:52555 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750770AbcJJLNj (ORCPT ); Mon, 10 Oct 2016 07:13:39 -0400 Received: from wuerfel.lan. ([78.43.20.153]) by mrelayeu.kundenserver.de (mreue001) with ESMTPA (Nemesis) id 0MIUYB-1brdEw0qkR-0047vo; Mon, 10 Oct 2016 13:13:17 +0200 From: Arnd Bergmann To: Greg Kroah-Hartman Cc: Andy Shevchenko , Rajneesh Bhardwaj , Darren Hart , Nicolai Stange , Arnd Bergmann , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] debugfs: improve DEFINE_DEBUGFS_ATTRIBUTE for !CONFIG_DEBUGFS_FS Date: Mon, 10 Oct 2016 13:12:57 +0200 Message-Id: <20161010111313.119658-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 X-Provags-ID: V03:K0:OZqN0/RCi+E2Q46wEi7EUeSuyI6ydRfWcAM11a+OtXuPP2JtzSa ssF1p2DLRxIy9OQzN0968cPz8/PK0hEeeaRHFee3GLr5dM9zIDLrtRUMH09jLjbBMKm2BEB /qtL5Ws1gA0BqnSxPC9aLSYnJKDaq4Pr/thgq+w+AVZowD+oEBrqsXNHaFiPjF0Sx+NDnRq kZK4uFvzA74htWihkYrxg== X-UI-Out-Filterresults: notjunk:1; V01:K0:cMuhRzoz1UY=:H2J+RpltJPoVq3pcf3aogF RGtixxkZ04fpgYifSo7U1qUUyfoGuQcHZM7u453RmM5PeSkziz/CIArHEtSwTb42QZp/hFTSG P/G/IUXrxBx0GIyF76FbXp3Ve3L6EPbMxbhC1bYPUtvZFMYGkHCEUyn7mf1ebuER3C4pfJFIo Kqec+xJD2VWpgOMqIoCV+eMy5zWI3XKAUT6hHQZNvxhS25T2Odvb88VWVRGsrnG+jmZZ/s9ED CHBATXc9Lk1l+oIAq8xoCUaWLsyJAG7Mtmj1SYiZDiu8RLwSkJ22rzlQFmMV3hAXCtvJUdc7Z g1RQfvwhQPZjIedLOWvM8wvlPySbCpwX8sal/Pl3FvKej8kTfNrtOoX2tMlxdocg+gKDz609F V0ZkFh07KaAjHW9KkH/O7iJobcxbLLgAU4UN1nkLJ6ldGCQ+k9jPCBJ4doFH5nHUEPdoL3Iei 7Awtvk2HBKYmwrUPZ0L6Wq/RVvevApFvM93xsSWzp7T7by9PhENmTwcm6w11PtFeI0QobFCik 8jL/hOQgR2Y20sbdhppIor3iVau+Zop7VKNUo5nUCrn+8udmfa13h22Fc14ilQmLXPb0gV8DX 80HpgNS6eTwNXl3vMgOeYCmfU5llUYvcrvcjyDo+J91cbF5LI9+oSJo1efYicrm1MT8/iGkVp +BDzIW6yUaXJo1s6g7aDj2aJCOgfxOaiyG25iMZ0CpBmlklyga+cLQXd/fyLmXJcScSTj/zOw BIQsZaQMUAE6AiSP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The slp_s0_residency_usec debugfs file currently uses DEFINE_DEBUGFS_ATTRIBUTE(), but that macro cannot really be used to define files outside of the debugfs code, as it has no reference to the get/set functions if CONFIG_DEBUGFS_FS is not defined: drivers/platform/x86/intel_pmc_core.c:80:12: error: ‘pmc_core_dev_state_get’ defined but not used [-Werror=unused-function] This fixes the macro to always contain the reference, and instead rely on the stubbed-out debugfs_create_file to not actually refer to its arguments so the compiler can still drop the reference. This works because the attribute definition is always 'static', and the dead-code removal silently drops all static symbols that are not used. Fixes: c64688081490 ("debugfs: add support for self-protecting attribute file fops") Fixes: df2294fb6428 ("intel_pmc_core: Convert to DEFINE_DEBUGFS_ATTRIBUTE") Signed-off-by: Arnd Bergmann --- include/linux/debugfs.h | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) -- 2.9.0 diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index 4d3f0d1aec73..e94f5f8dced3 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -62,6 +62,26 @@ static inline const struct file_operations *debugfs_real_fops(struct file *filp) return filp->f_path.dentry->d_fsdata; } +ssize_t debugfs_attr_read(struct file *file, char __user *buf, + size_t len, loff_t *ppos); +ssize_t debugfs_attr_write(struct file *file, const char __user *buf, + size_t len, loff_t *ppos); + +#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ +static int __fops ## _open(struct inode *inode, struct file *file) \ +{ \ + __simple_attr_check_format(__fmt, 0ull); \ + return simple_attr_open(inode, file, __get, __set, __fmt); \ +} \ +static const struct file_operations __fops = { \ + .owner = THIS_MODULE, \ + .open = __fops ## _open, \ + .release = simple_attr_release, \ + .read = debugfs_attr_read, \ + .write = debugfs_attr_write, \ + .llseek = generic_file_llseek, \ +} + #if defined(CONFIG_DEBUG_FS) struct dentry *debugfs_create_file(const char *name, umode_t mode, @@ -94,26 +114,6 @@ int debugfs_use_file_start(const struct dentry *dentry, int *srcu_idx) void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu); -ssize_t debugfs_attr_read(struct file *file, char __user *buf, - size_t len, loff_t *ppos); -ssize_t debugfs_attr_write(struct file *file, const char __user *buf, - size_t len, loff_t *ppos); - -#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ -static int __fops ## _open(struct inode *inode, struct file *file) \ -{ \ - __simple_attr_check_format(__fmt, 0ull); \ - return simple_attr_open(inode, file, __get, __set, __fmt); \ -} \ -static const struct file_operations __fops = { \ - .owner = THIS_MODULE, \ - .open = __fops ## _open, \ - .release = simple_attr_release, \ - .read = debugfs_attr_read, \ - .write = debugfs_attr_write, \ - .llseek = generic_file_llseek, \ -} - struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, struct dentry *new_dir, const char *new_name); @@ -233,9 +233,6 @@ static inline void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu) { } -#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ - static const struct file_operations __fops = { 0 } - static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, struct dentry *new_dir, char *new_name) {