From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: <gregkh@linuxfoundation.org>, <linux-kernel@vger.kernel.org>
Cc: Kefeng Wang <wangkefeng.wang@huawei.com>
Subject: [PATCH next 1/3] debugfs: Provide debugfs_[set|clear|test]_lowest_bit()
Date: Fri, 29 Nov 2019 17:27:50 +0800 [thread overview]
Message-ID: <20191129092752.169902-2-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <20191129092752.169902-1-wangkefeng.wang@huawei.com>
Provide debugfs_[set|clear|test]_lowest_bit() helper, which
could test, set and clear the lowest bit of a pointer, and
will be used in the subsequent patches.
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
fs/debugfs/file.c | 7 +++----
fs/debugfs/inode.c | 7 +++----
fs/debugfs/internal.h | 5 ++++-
3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index dede25247b81..38c17a99eb17 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -50,7 +50,7 @@ const struct file_operations *debugfs_real_fops(const struct file *filp)
{
struct debugfs_fsdata *fsd = F_DENTRY(filp)->d_fsdata;
- if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT) {
+ if (debugfs_test_lowest_bit(fsd)) {
/*
* Urgh, we've been called w/o a protecting
* debugfs_file_get().
@@ -84,15 +84,14 @@ int debugfs_file_get(struct dentry *dentry)
void *d_fsd;
d_fsd = READ_ONCE(dentry->d_fsdata);
- if (!((unsigned long)d_fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT)) {
+ if (!debugfs_test_lowest_bit(d_fsd)) {
fsd = d_fsd;
} else {
fsd = kmalloc(sizeof(*fsd), GFP_KERNEL);
if (!fsd)
return -ENOMEM;
- fsd->real_fops = (void *)((unsigned long)d_fsd &
- ~DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
+ fsd->real_fops = debugfs_clear_lowest_bit(d_fsd);
refcount_set(&fsd->active_users, 1);
init_completion(&fsd->active_users_drained);
if (cmpxchg(&dentry->d_fsdata, d_fsd, fsd) != d_fsd) {
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 7b975dbb2bb4..cc24e97686d0 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -211,7 +211,7 @@ static void debugfs_release_dentry(struct dentry *dentry)
{
void *fsd = dentry->d_fsdata;
- if (!((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT))
+ if (!debugfs_test_lowest_bit(fsd))
kfree(dentry->d_fsdata);
}
@@ -398,8 +398,7 @@ static struct dentry *__debugfs_create_file(const char *name, umode_t mode,
inode->i_op = &debugfs_file_inode_operations;
inode->i_fop = proxy_fops;
- dentry->d_fsdata = (void *)((unsigned long)real_fops |
- DEBUGFS_FSDATA_IS_REAL_FOPS_BIT);
+ dentry->d_fsdata = debugfs_set_lowest_bit(real_fops);
d_instantiate(dentry, inode);
fsnotify_create(d_inode(dentry->d_parent), dentry);
@@ -679,7 +678,7 @@ static void __debugfs_file_removed(struct dentry *dentry)
*/
smp_mb();
fsd = READ_ONCE(dentry->d_fsdata);
- if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT)
+ if (debugfs_test_lowest_bit(fsd))
return;
if (!refcount_dec_and_test(&fsd->active_users))
wait_for_completion(&fsd->active_users_drained);
diff --git a/fs/debugfs/internal.h b/fs/debugfs/internal.h
index f0d73d86cc1a..4dd6df4bc172 100644
--- a/fs/debugfs/internal.h
+++ b/fs/debugfs/internal.h
@@ -27,6 +27,9 @@ struct debugfs_fsdata {
* In order to distinguish between these two cases, a real fops
* pointer gets its lowest bit set.
*/
-#define DEBUGFS_FSDATA_IS_REAL_FOPS_BIT BIT(0)
+
+#define debugfs_set_lowest_bit(ptr) ((void *)((unsigned long)(ptr) | BIT(0)))
+#define debugfs_clear_lowest_bit(ptr) ((void *)((unsigned long)(ptr) & ~BIT(0)))
+#define debugfs_test_lowest_bit(ptr) ((unsigned long)(ptr) & BIT(0))
#endif /* _DEBUGFS_INTERNAL_H_ */
--
2.20.1
next prev parent reply other threads:[~2019-11-29 9:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-29 9:27 [PATCH next 0/3] debugfs: introduce debugfs_create_single/seq[,_data] Kefeng Wang
2019-11-29 9:27 ` Kefeng Wang [this message]
2019-11-29 9:27 ` [PATCH next 2/3] debugfs: introduce debugfs_create_single[,_data] Kefeng Wang
2019-12-03 8:38 ` Dan Carpenter
2019-12-03 9:02 ` [kbuild-all] " Rong Chen
2019-12-03 9:32 ` Dan Carpenter
2019-11-29 9:27 ` [PATCH next 3/3] debugfs: introduce debugfs_create_seq[,_data] Kefeng Wang
2019-11-29 14:22 ` Greg KH
2019-11-29 15:03 ` Kefeng Wang
2019-11-29 22:16 ` Greg KH
2019-11-29 14:21 ` [PATCH next 0/3] debugfs: introduce debugfs_create_single/seq[,_data] Greg KH
2019-11-29 15:16 ` Kefeng Wang
2019-11-29 22:19 ` Greg KH
2019-11-29 22:23 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191129092752.169902-2-wangkefeng.wang@huawei.com \
--to=wangkefeng.wang@huawei.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®