From: xiubli@redhat.com
To: linux-kernel@vger.kernel.org
Cc: Xiubo Li <xiubli@redhat.com>
Subject: [RFC PATCH] seq_file: Introduce DEFINE_RW_ATTRIBUTE() helper macro
Date: Fri, 31 Jan 2020 08:40:09 -0500 [thread overview]
Message-ID: <20200131134009.14581-1-xiubli@redhat.com> (raw)
From: Xiubo Li <xiubli@redhat.com>
It's time to introduce the DEFINE_RW_ATTRIBUTE() helper macro, this
would be useful for current users, there are many places are doing
the duplicated works. This could decrease code duplication.
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
include/linux/seq_file.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 5998e1f4ff06..9e0c10a5aa4a 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -160,6 +160,21 @@ static const struct file_operations __name ## _fops = { \
.release = single_release, \
}
+#define DEFINE_RW_ATTRIBUTE(__name) \
+static int __name ## _open(struct inode *inode, struct file *file) \
+{ \
+ return single_open(file, __name ## _show, inode->i_private); \
+} \
+ \
+static const struct file_operations __name ## _fops = { \
+ .owner = THIS_MODULE, \
+ .open = __name ## _open, \
+ .read = seq_read, \
+ .write = __name ## _store, \
+ .llseek = seq_lseek, \
+ .release = single_release, \
+}
+
static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
{
#ifdef CONFIG_USER_NS
--
2.21.0
reply other threads:[~2020-01-31 13:40 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20200131134009.14581-1-xiubli@redhat.com \
--to=xiubli@redhat.com \
--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;
as well as URLs for NNTP newsgroup(s).