mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH 1/3] seq_file: Introduce DEFINE_SEQ_ATTRIBUTE() helper macro
@ 2020-05-09 11:35 Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2020-05-09 11:35 UTC (permalink / raw)
  To: Kefeng Wang, kernel-janitors
  Cc: linux-kernel, Andrew Morton, Greg Kroah-Hartman, Ingo Molnar

…
> +++ 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)	\
…

Can such a macro work also with an identifier which does not contain
double underscores?

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/3] seq_file: Introduce DEFINE_SEQ_ATTRIBUTE() helper macro
  2020-05-09  6:40 [PATCH 0/3] " Kefeng Wang
@ 2020-05-09  6:40 ` Kefeng Wang
  0 siblings, 0 replies; 2+ messages in thread
From: Kefeng Wang @ 2020-05-09  6:40 UTC (permalink / raw)
  To: Greg KH, linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Kefeng Wang

Introduce DEFINE_SEQ_ATTRIBUTE() helper macro to decrease code duplication.

Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-05-09 11:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09 11:35 [PATCH 1/3] seq_file: Introduce DEFINE_SEQ_ATTRIBUTE() helper macro Markus Elfring
  -- strict thread matches above, loose matches on Subject: below --
2020-05-09  6:40 [PATCH 0/3] " Kefeng Wang
2020-05-09  6:40 ` [PATCH 1/3] " Kefeng Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®