[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200509064031.181091-2-wangkefeng.wang@huawei.com>
Date: Sat, 9 May 2020 14:40:29 +0800
From: Kefeng Wang <wangkefeng.wang@...wei.com>
To: Greg KH <gregkh@...uxfoundation.org>,
<linux-kernel@...r.kernel.org>
CC: Ingo Molnar <mingo@...nel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Kefeng Wang <wangkefeng.wang@...wei.com>
Subject: [PATCH 1/3] seq_file: Introduce DEFINE_SEQ_ATTRIBUTE() helper macro
Introduce DEFINE_SEQ_ATTRIBUTE() helper macro to decrease code duplication.
Signed-off-by: Kefeng Wang <wangkefeng.wang@...wei.com>
---
include/linux/seq_file.h | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 1672cf6f7614..c77869cf7d10 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -145,6 +145,25 @@ void *__seq_open_private(struct file *, const struct seq_operations *, int);
int seq_open_private(struct file *, const struct seq_operations *, int);
int seq_release_private(struct inode *, struct file *);
+#define DEFINE_SEQ_ATTRIBUTE(__name) \
+static int __name ## _open(struct inode *inode, struct file *file) \
+{ \
+ int ret = seq_open(file, &__name ## _sops); \
+ if (!ret && inode->i_private) { \
+ struct seq_file *seq_f = file->private_data; \
+ seq_f->private = inode->i_private; \
+ } \
+ return ret; \
+} \
+ \
+static const struct file_operations __name ## _fops = { \
+ .owner = THIS_MODULE, \
+ .open = __name ## _open, \
+ .read = seq_read, \
+ .llseek = seq_lseek, \
+ .release = seq_release, \
+}
+
#define DEFINE_SHOW_ATTRIBUTE(__name) \
static int __name ## _open(struct inode *inode, struct file *file) \
{ \
--
2.26.2
Powered by blists - more mailing lists