From patchwork Sat Sep 17 19:43:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 9337345 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 78DEC60839 for ; Sat, 17 Sep 2016 19:43:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5E929291CE for ; Sat, 17 Sep 2016 19:43:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5195D291E5; Sat, 17 Sep 2016 19:43:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1F06291CE for ; Sat, 17 Sep 2016 19:43:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752356AbcIQTnL (ORCPT ); Sat, 17 Sep 2016 15:43:11 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34789 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751959AbcIQTnJ (ORCPT ); Sat, 17 Sep 2016 15:43:09 -0400 Received: by mail-wm0-f68.google.com with SMTP id l132so7490316wmf.1; Sat, 17 Sep 2016 12:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=bZP6VWC8zLDfaV8UqOaMrmNN8KPYzwXFNz4IoweOKlY=; b=PipD+B1XV/4Yc7cDY6KS5skrttP7/ev2hE8FmFMs3PZG5tAXpcHurCv+ZCHxNDbasd CWym68bxHauN/AFkitR+PxHgt1mBLtJF8uTa+9+S4wMmXXSFnuNBATe822VccIYrtUSW s/xqewuLw/RFrwf74L8lAiixhEqzG8gNxwks0zGrnvZ5XB3wnVe8Dj4liHXIzPMGgP5y lM2NUH013dJPj+XY3LYQj7QZGzHMWS012y+KPFcTxApRsrDAPQ2rM/LDHyEa0Ic7Enrm /Jh9/QVZod7ssaRrPqysqNxQbcqVQBUHeXFZBmjOwFwyEU7qCAUc8KUi1BJK8IJ7I+Iz lrzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bZP6VWC8zLDfaV8UqOaMrmNN8KPYzwXFNz4IoweOKlY=; b=Yp1Fv9UeYhqaGvDdjLvdrPzpK9kzgR50KVtL6qHl8Bx78/0qBMMxQGrCuRYsrqt80A 4jv6F/FabrPUcHfiXAIiGqbxfa5XwmJPQaV4mwaqtGZZRzlpMBnO8gru0goiNy9nsiYp rCKpUGz3scV6+sD/Mx0aSKwv/YzimjtAcLYK5ODHE4Nh3P/HKHw5vTl5CPhkwfzi1Qvn 0vLlVjJf0AvYrP38tdpfAsNTYvquQc7tLeklrIQC7yjq1LIX6Klky8ibFAaVyLfjyzgr Fah0YoYH4MtRIpZOeIRMKoD4K78IH0HPhMxP7qu7ASbLQEmf/6Y5EoPkBpTvGHe2Y05e ZmXQ== X-Gm-Message-State: AE9vXwP67tqnpysQlk/PrlQ9mMdDM8WF1u03Fnvc8fvZ8xIxInKjtYES08d0OGzIrUmfxw== X-Received: by 10.28.62.20 with SMTP id l20mr2741513wma.45.1474141387258; Sat, 17 Sep 2016 12:43:07 -0700 (PDT) Received: from debian64.daheim (pD9F8BE97.dip0.t-ipconnect.de. [217.248.190.151]) by smtp.gmail.com with ESMTPSA id uv6sm14519178wjc.31.2016.09.17.12.43.06 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 17 Sep 2016 12:43:06 -0700 (PDT) From: Christian Lamparter X-Google-Original-From: Christian Lamparter Received: from chuck by debian64.daheim with local (Exim 4.87) (envelope-from ) id 1blLVy-0006si-0h; Sat, 17 Sep 2016 21:43:06 +0200 To: gregkh@linuxfoundation.org, Kalle Valo Cc: Christian Lamparter , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, b43-dev@lists.infradead.org, Nicolai Stange , Ben Greear , Larry Finger Subject: [PATCH 1/4] debugfs: introduce a public file_operations accessor Date: Sat, 17 Sep 2016 21:43:01 +0200 Message-Id: <48411543620969bebb37a1a9ea7b8f451cdfdd31.1474140477.git.chunkeey@gmail.com> X-Mailer: git-send-email 2.9.3 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces an accessor which can be used by the users of debugfs (drivers, fs, ...) to get the original file_operations struct. It also removes the REAL_FOPS_DEREF macro in file.c and converts the code to use the public version. Previously, REAL_FOPS_DEREF was only available within the file.c of debugfs. But having a public getter available for debugfs users is important as some drivers (carl9170 and b43) use the pointer of the original file_operations in conjunction with container_of() within their debugfs implementations. Reviewed-by: Nicolai Stange Signed-off-by: Christian Lamparter --- fs/debugfs/file.c | 13 +++++-------- include/linux/debugfs.h | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index 592059f..309f4e9 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c @@ -97,9 +97,6 @@ EXPORT_SYMBOL_GPL(debugfs_use_file_finish); #define F_DENTRY(filp) ((filp)->f_path.dentry) -#define REAL_FOPS_DEREF(dentry) \ - ((const struct file_operations *)(dentry)->d_fsdata) - static int open_proxy_open(struct inode *inode, struct file *filp) { const struct dentry *dentry = F_DENTRY(filp); @@ -112,7 +109,7 @@ static int open_proxy_open(struct inode *inode, struct file *filp) goto out; } - real_fops = REAL_FOPS_DEREF(dentry); + real_fops = debugfs_real_fops(filp); real_fops = fops_get(real_fops); if (!real_fops) { /* Huh? Module did not clean up after itself at exit? */ @@ -143,7 +140,7 @@ static ret_type full_proxy_ ## name(proto) \ { \ const struct dentry *dentry = F_DENTRY(filp); \ const struct file_operations *real_fops = \ - REAL_FOPS_DEREF(dentry); \ + debugfs_real_fops(filp); \ int srcu_idx; \ ret_type r; \ \ @@ -176,7 +173,7 @@ static unsigned int full_proxy_poll(struct file *filp, struct poll_table_struct *wait) { const struct dentry *dentry = F_DENTRY(filp); - const struct file_operations *real_fops = REAL_FOPS_DEREF(dentry); + const struct file_operations *real_fops = debugfs_real_fops(filp); int srcu_idx; unsigned int r = 0; @@ -193,7 +190,7 @@ static unsigned int full_proxy_poll(struct file *filp, static int full_proxy_release(struct inode *inode, struct file *filp) { const struct dentry *dentry = F_DENTRY(filp); - const struct file_operations *real_fops = REAL_FOPS_DEREF(dentry); + const struct file_operations *real_fops = debugfs_real_fops(filp); const struct file_operations *proxy_fops = filp->f_op; int r = 0; @@ -241,7 +238,7 @@ static int full_proxy_open(struct inode *inode, struct file *filp) goto out; } - real_fops = REAL_FOPS_DEREF(dentry); + real_fops = debugfs_real_fops(filp); real_fops = fops_get(real_fops); if (!real_fops) { /* Huh? Module did not cleanup after itself at exit? */ diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index 1438e23..4d3f0d1 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h @@ -45,6 +45,23 @@ extern struct dentry *arch_debugfs_dir; extern struct srcu_struct debugfs_srcu; +/** + * debugfs_real_fops - getter for the real file operation + * @filp: a pointer to a struct file + * + * Must only be called under the protection established by + * debugfs_use_file_start(). + */ +static inline const struct file_operations *debugfs_real_fops(struct file *filp) + __must_hold(&debugfs_srcu) +{ + /* + * Neither the pointer to the struct file_operations, nor its + * contents ever change -- srcu_dereference() is not needed here. + */ + return filp->f_path.dentry->d_fsdata; +} + #if defined(CONFIG_DEBUG_FS) struct dentry *debugfs_create_file(const char *name, umode_t mode,