diff mbox series

[v1,1/5] seq_file: Introduce DEFINE_STORE_ATTRIBUTE() helper macro

Message ID 1603355997-32350-2-git-send-email-luojiaxing@huawei.com (mailing list archive)
State Not Applicable
Headers show
Series Introduce a new helper marco DEFINE_STORE_ATTRIBUTE at seq_file.c | expand

Commit Message

luojiaxing Oct. 22, 2020, 8:39 a.m. UTC
We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
for read-only file, but we found many of drivers want a helper marco for
read-write file too.

So we try to make one to decrease code duplication.

Signed-off-by: Luo Jiaxing <luojiaxing@huawei.com>
---
 include/linux/seq_file.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

Comments

Andy Shevchenko Oct. 22, 2020, 2:22 p.m. UTC | #1
On Thu, Oct 22, 2020 at 04:39:53PM +0800, Luo Jiaxing wrote:
> We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
> for read-only file, but we found many of drivers want a helper marco for
> read-write file too.

I would expect that DEFINE_STORE maps to WO attribute...
For RW SHOW_STORE would be more appropriate.

Otherwise I think it makes sense.
luojiaxing Oct. 23, 2020, 8:53 a.m. UTC | #2
Hi

On 2020/10/22 22:22, Andy Shevchenko wrote:
> On Thu, Oct 22, 2020 at 04:39:53PM +0800, Luo Jiaxing wrote:
>> We already own DEFINE_SHOW_ATTRIBUTE() helper macro for defining attribute
>> for read-only file, but we found many of drivers want a helper marco for
>> read-write file too.
> I would expect that DEFINE_STORE maps to WO attribute...
> For RW SHOW_STORE would be more appropriate.
>
> Otherwise I think it makes sense.


Thanks for the review, it's true that the name is a bit inappropriate.

I'll change the name if I get a v2 patch.

But AI doesn't seem to like this macro  : )


Thanks

Jiaxing


>
diff mbox series

Patch

diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index 813614d..3b3b797 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -191,6 +191,21 @@  static const struct proc_ops __name ## _proc_ops = {			\
 	.proc_release	= single_release,				\
 }
 
+#define DEFINE_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,				\
+}
+
 static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
 {
 #ifdef CONFIG_USER_NS