[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230904084804.39564-2-yangxingui@huawei.com>
Date: Mon, 4 Sep 2023 08:48:02 +0000
From: Xingui Yang <yangxingui@...wei.com>
To: <jejb@...ux.ibm.com>, <martin.petersen@...cle.com>,
<john.g.garry@...cle.com>, <damien.lemoal@...nsource.wdc.com>
CC: <andriy.shevchenko@...ux.intel.com>, <akpm@...ux-foundation.org>,
<viro@...iv.linux.org.uk>, <himanshu.madhani@...ium.com>,
<felipe.balbi@...ux.intel.com>, <gregkh@...uxfoundation.org>,
<uma.shankar@...el.com>, <anshuman.gupta@...el.com>,
<animesh.manna@...el.com>, <linux-usb@...r.kernel.org>,
<linux-scsi@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linuxarm@...wei.com>, <yangxingui@...wei.com>,
<prime.zeng@...ilicon.com>, <kangfenglong@...wei.com>,
<chenxiang66@...ilicon.com>
Subject: [PATCH v5 1/3] seq_file: Add helper macro to define attribute for rw file
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but many of drivers want a helper macro for read-write
file too.
So we add DEFINE_SHOW_STORE_ATTRIBUTE helper to reduce duplicated code.
Signed-off-by: Luo Jiaxing <luojiaxing@...wei.com>
Signed-off-by: Xingui Yang <yangxingui@...wei.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 bd023dd38ae6..e400007e410c 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -207,6 +207,21 @@ static const struct file_operations __name ## _fops = { \
.release = single_release, \
}
+#define DEFINE_SHOW_STORE_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 ## _write, \
+ .llseek = seq_lseek, \
+ .release = single_release, \
+}
+
#define DEFINE_PROC_SHOW_ATTRIBUTE(__name) \
static int __name ## _open(struct inode *inode, struct file *file) \
{ \
--
2.17.1
Powered by blists - more mailing lists