Patch series "seq_file: Introduce DEFINE_SEQ_ATTRIBUTE() helper macro". As discussed in https://lore.kernel.org/lkml/20191129222310.GA3712618@kroah.com/, we could introduce a new helper macro to reduce losts of boilerplate code, vmstat and kprobes is the example which covert to use it, if this is accepted, I will send out more cleanups. This patch (of 3): Introduce DEFINE_SEQ_ATTRIBUTE() helper macro to decrease code duplication. [akpm@linux-foundation.org: coding style fixes] Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Kefeng Wang <wangkefeng.wang@huawei.com> Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> Cc: "David S. Miller" <davem@davemloft.net> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Link: http://lkml.kernel.org/r/20200509064031.181091-1-wangkefeng.wang@huawei.com Link: http://lkml.kernel.org/r/20200509064031.181091-2-wangkefeng.wang@huawei.com Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing the changes to include/linux (1 of 1 file). Show all
Unified · Split
| @@ -145,6 +145,25 @@ void *__seq_open_private(struct file *, const struct seq_operations *, int); · 144 unmodified lines | |||
| 145 | int seq_open_private(struct file *, const struct seq_operations *, int); | 145 | int seq_open_private(struct file *, const struct seq_operations *, int); |
| 146 | int seq_release_private(struct inode *, struct file *); | 146 | int seq_release_private(struct inode *, struct file *); |
| 147 | 147 | ||
| 148 | #define DEFINE_SEQ_ATTRIBUTE(__name) \ | ||
| 149 | static int __name ## _open(struct inode *inode, struct file *file) \ | ||
| 150 | { \ | ||
| 151 | int ret = seq_open(file, &__name ## _sops); \ | ||
| 152 | if (!ret && inode->i_private) { \ | ||
| 153 | struct seq_file *seq_f = file->private_data; \ | ||
| 154 | seq_f->private = inode->i_private; \ | ||
| 155 | } \ | ||
| 156 | return ret; \ | ||
| 157 | } \ | ||
| 158 | \ | ||
| 159 | static const struct file_operations __name ## _fops = { \ | ||
| 160 | .owner = THIS_MODULE, \ | ||
| 161 | .open = __name ## _open, \ | ||
| 162 | .read = seq_read, \ | ||
| 163 | .llseek = seq_lseek, \ | ||
| 164 | .release = seq_release, \ | ||
| 165 | } | ||
| 166 | |||
| 148 | #define DEFINE_SHOW_ATTRIBUTE(__name) \ | 167 | #define DEFINE_SHOW_ATTRIBUTE(__name) \ |
| 149 | static int __name ## _open(struct inode *inode, struct file *file) \ | 168 | static int __name ## _open(struct inode *inode, struct file *file) \ |
| 150 | { \ | 169 | { \ |