diff mbox series

[v5,1/3] seq_file: Add helper macro to define attribute for rw file

Message ID 20230904084804.39564-2-yangxingui@huawei.com
State Superseded
Headers show
Series Add helper macro DEFINE_SHOW_STORE_ATTRIBUTE at seq_file.c | expand

Commit Message

yangxingui Sept. 4, 2023, 8:48 a.m. UTC
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@huawei.com>
Signed-off-by: Xingui Yang <yangxingui@huawei.com>
---
 include/linux/seq_file.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Andy Shevchenko Sept. 4, 2023, 10:53 a.m. UTC | #1
On Mon, Sep 04, 2023 at 08:48:02AM +0000, Xingui Yang wrote:
> 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@huawei.com>

I believe you need to preserve Luo's authorship.

Perhaps,
Co-developed-by: Xingui ...
(depending if you really do some job in the certain patch(es) or not).

> Signed-off-by: Xingui Yang <yangxingui@huawei.com>

Code wise LGTM, FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
diff mbox series

Patch

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)	\
 {									\