UPSTREAM: seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Mon, 22 Jan 2018 16:05:43 +0000 (18:05 +0200)
committerChristian Hoffmann <chrmhoffmann@gmail.com>
Sun, 12 Feb 2023 08:13:15 +0000 (09:13 +0100)
The DEFINE_SHOW_ATTRIBUTE() helper macro would be useful for current
users, which are many of them, and for new comers to decrease code
duplication.

Acked-by: Lee Jones <lee.jones@linaro.org>
Acked-by: Darren Hart (VMware) <dvhart@infradead.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Bug: 136497735
(cherry picked from commit a08f06bb7a0743a7fc8d571899c93d882468096e)
Change-Id: Ib60cf57dc5e979915a83848919644150d82e7058
Signed-off-by: Hridya Valsaraju <hridya@google.com>
include/linux/seq_file.h

index e305b66a9fb994904cdd87b046cca7822e62cef1..d75248d81499093b2c5f62dfb05c637c2dffd786 100644 (file)
@@ -139,6 +139,20 @@ 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_SHOW_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,                                     \
+       .llseek         = seq_lseek,                                    \
+       .release        = single_release,                               \
+}
+
 static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
 {
 #ifdef CONFIG_USER_NS