diff mbox series

[v2,1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro

Message ID 20171123203605.44954-2-andriy.shevchenko@linux.intel.com
State Awaiting Upstream, archived
Delegated to: David Miller
Headers show
Series seq_file, Bluetooth: introduce DEFINE_SHOW_ATTRIBUTE() | expand

Commit Message

Andy Shevchenko Nov. 23, 2017, 8:36 p.m. UTC
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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 include/linux/seq_file.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Marcel Holtmann Nov. 28, 2017, 8:43 a.m. UTC | #1
Hi Andy,

> 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.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> include/linux/seq_file.h | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
> 
> diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
> index c32929802c25..73adc12ab773 100644
> --- a/include/linux/seq_file.h
> +++ b/include/linux/seq_file.h
> @@ -144,6 +144,19 @@ 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 = {			      \
> +	.open		= __name ## _open,				      \
> +	.read		= seq_read,					      \
> +	.llseek		= seq_lseek,					      \
> +	.release	= single_release,				      \
> +}									      \
> +

can we define this in hci_debugfs.c first and get that patch merged into bluetooth-next. And only as a follow up patch try to generalize this in seq_file.h. I really don’t like to carry a patch for seq_file.h in the bluetooth-next tree.

Regards

Marcel
Andy Shevchenko Nov. 28, 2017, 12:19 p.m. UTC | #2
On Tue, 2017-11-28 at 09:43 +0100, Marcel Holtmann wrote:
> Hi Andy,
> 
> > 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.

> can we define this in hci_debugfs.c first and get that patch merged
> into bluetooth-next. And only as a follow up patch try to generalize
> this in seq_file.h. I really don’t like to carry a patch for
> seq_file.h in the bluetooth-next tree.
> 

This was in v1 [1].

Feel free to apply it instead. Frankly I don't understand what's wrong
with carrying patch against seq_file.h? Is it "person non grata"?

[1]: https://marc.info/?l=linux-bluetooth&m=151138535801354&w=2
Andy Shevchenko Dec. 13, 2017, 3:38 p.m. UTC | #3
On Tue, 2017-11-28 at 14:19 +0200, Andy Shevchenko wrote:
> On Tue, 2017-11-28 at 09:43 +0100, Marcel Holtmann wrote:
> > Hi Andy,
> > 
> > > 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.
> > can we define this in hci_debugfs.c first and get that patch merged
> > into bluetooth-next. And only as a follow up patch try to generalize
> > this in seq_file.h. I really don’t like to carry a patch for
> > seq_file.h in the bluetooth-next tree.
> > 
> 
> This was in v1 [1].
> 
> Feel free to apply it instead. Frankly I don't understand what's wrong
> with carrying patch against seq_file.h? Is it "person non grata"?
> 
> [1]: https://marc.info/?l=linux-bluetooth&m=151138535801354&w=2

Marcel, can you apply v1? Or should I resend it as v3?
diff mbox series

Patch

diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index c32929802c25..73adc12ab773 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -144,6 +144,19 @@  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 = {			      \
+	.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