* [PATCH v2 0/2] seq_file, Bluetooth: introduce DEFINE_SHOW_ATTRIBUTE()
@ 2017-11-23 20:36 Andy Shevchenko
2017-11-23 20:36 ` [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro Andy Shevchenko
2017-11-23 20:36 ` [PATCH v2 2/2] Bluetooth: Re-use DEFINE_SHOW_ATTRIBUTE() macro Andy Shevchenko
0 siblings, 2 replies; 6+ messages in thread
From: Andy Shevchenko @ 2017-11-23 20:36 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, linux-bluetooth, David S . Miller,
netdev, Randy Dunlap
Cc: Andy Shevchenko
Introduce a helper macro for attributes that have only ->show() defined.
P.S. I have few more clean ups locally, thus it would be nice to have an
immutable branch for the rest patches which would like to utilize the new
macro.
In v2:
- introduce for all users followed by an example clean up of hci_debugfs.c
Andy Shevchenko (2):
seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro
Bluetooth: Re-use DEFINE_SHOW_ATTRIBUTE() macro
include/linux/seq_file.h | 13 +++
net/bluetooth/hci_debugfs.c | 193 ++++----------------------------------------
2 files changed, 29 insertions(+), 177 deletions(-)
--
2.15.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro
2017-11-23 20:36 [PATCH v2 0/2] seq_file, Bluetooth: introduce DEFINE_SHOW_ATTRIBUTE() Andy Shevchenko
@ 2017-11-23 20:36 ` Andy Shevchenko
2017-11-28 8:43 ` Marcel Holtmann
2017-11-23 20:36 ` [PATCH v2 2/2] Bluetooth: Re-use DEFINE_SHOW_ATTRIBUTE() macro Andy Shevchenko
1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2017-11-23 20:36 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, linux-bluetooth, David S . Miller,
netdev, Randy Dunlap
Cc: Andy Shevchenko
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, \
+} \
+
static inline struct user_namespace *seq_user_ns(struct seq_file *seq)
{
#ifdef CONFIG_USER_NS
--
2.15.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] Bluetooth: Re-use DEFINE_SHOW_ATTRIBUTE() macro
2017-11-23 20:36 [PATCH v2 0/2] seq_file, Bluetooth: introduce DEFINE_SHOW_ATTRIBUTE() Andy Shevchenko
2017-11-23 20:36 ` [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro Andy Shevchenko
@ 2017-11-23 20:36 ` Andy Shevchenko
1 sibling, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2017-11-23 20:36 UTC (permalink / raw)
To: Marcel Holtmann, Johan Hedberg, linux-bluetooth, David S . Miller,
netdev, Randy Dunlap
Cc: Andy Shevchenko
...instead of open coding file operations followed by custom ->open()
callbacks per each attribute.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
net/bluetooth/hci_debugfs.c | 193 ++++----------------------------------------
1 file changed, 16 insertions(+), 177 deletions(-)
diff --git a/net/bluetooth/hci_debugfs.c b/net/bluetooth/hci_debugfs.c
index 63df63ebfb24..2fffc5a05243 100644
--- a/net/bluetooth/hci_debugfs.c
+++ b/net/bluetooth/hci_debugfs.c
@@ -88,17 +88,7 @@ static int __name ## _show(struct seq_file *f, void *ptr) \
return 0; \
} \
\
-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, \
-} \
+DEFINE_SHOW_ATTRIBUTE(__name)
static int features_show(struct seq_file *f, void *ptr)
{
@@ -126,17 +116,7 @@ static int features_show(struct seq_file *f, void *ptr)
return 0;
}
-static int features_open(struct inode *inode, struct file *file)
-{
- return single_open(file, features_show, inode->i_private);
-}
-
-static const struct file_operations features_fops = {
- .open = features_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(features);
static int device_id_show(struct seq_file *f, void *ptr)
{
@@ -150,17 +130,7 @@ static int device_id_show(struct seq_file *f, void *ptr)
return 0;
}
-static int device_id_open(struct inode *inode, struct file *file)
-{
- return single_open(file, device_id_show, inode->i_private);
-}
-
-static const struct file_operations device_id_fops = {
- .open = device_id_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(device_id);
static int device_list_show(struct seq_file *f, void *ptr)
{
@@ -180,17 +150,7 @@ static int device_list_show(struct seq_file *f, void *ptr)
return 0;
}
-static int device_list_open(struct inode *inode, struct file *file)
-{
- return single_open(file, device_list_show, inode->i_private);
-}
-
-static const struct file_operations device_list_fops = {
- .open = device_list_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(device_list);
static int blacklist_show(struct seq_file *f, void *p)
{
@@ -205,17 +165,7 @@ static int blacklist_show(struct seq_file *f, void *p)
return 0;
}
-static int blacklist_open(struct inode *inode, struct file *file)
-{
- return single_open(file, blacklist_show, inode->i_private);
-}
-
-static const struct file_operations blacklist_fops = {
- .open = blacklist_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(blacklist);
static int uuids_show(struct seq_file *f, void *p)
{
@@ -240,17 +190,7 @@ static int uuids_show(struct seq_file *f, void *p)
return 0;
}
-static int uuids_open(struct inode *inode, struct file *file)
-{
- return single_open(file, uuids_show, inode->i_private);
-}
-
-static const struct file_operations uuids_fops = {
- .open = uuids_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(uuids);
static int remote_oob_show(struct seq_file *f, void *ptr)
{
@@ -269,17 +209,7 @@ static int remote_oob_show(struct seq_file *f, void *ptr)
return 0;
}
-static int remote_oob_open(struct inode *inode, struct file *file)
-{
- return single_open(file, remote_oob_show, inode->i_private);
-}
-
-static const struct file_operations remote_oob_fops = {
- .open = remote_oob_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(remote_oob);
static int conn_info_min_age_set(void *data, u64 val)
{
@@ -443,17 +373,7 @@ static int inquiry_cache_show(struct seq_file *f, void *p)
return 0;
}
-static int inquiry_cache_open(struct inode *inode, struct file *file)
-{
- return single_open(file, inquiry_cache_show, inode->i_private);
-}
-
-static const struct file_operations inquiry_cache_fops = {
- .open = inquiry_cache_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(inquiry_cache);
static int link_keys_show(struct seq_file *f, void *ptr)
{
@@ -469,17 +389,7 @@ static int link_keys_show(struct seq_file *f, void *ptr)
return 0;
}
-static int link_keys_open(struct inode *inode, struct file *file)
-{
- return single_open(file, link_keys_show, inode->i_private);
-}
-
-static const struct file_operations link_keys_fops = {
- .open = link_keys_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(link_keys);
static int dev_class_show(struct seq_file *f, void *ptr)
{
@@ -493,17 +403,7 @@ static int dev_class_show(struct seq_file *f, void *ptr)
return 0;
}
-static int dev_class_open(struct inode *inode, struct file *file)
-{
- return single_open(file, dev_class_show, inode->i_private);
-}
-
-static const struct file_operations dev_class_fops = {
- .open = dev_class_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(dev_class);
static int voice_setting_get(void *data, u64 *val)
{
@@ -692,17 +592,7 @@ static int identity_show(struct seq_file *f, void *p)
return 0;
}
-static int identity_open(struct inode *inode, struct file *file)
-{
- return single_open(file, identity_show, inode->i_private);
-}
-
-static const struct file_operations identity_fops = {
- .open = identity_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(identity);
static int rpa_timeout_set(void *data, u64 val)
{
@@ -746,17 +636,7 @@ static int random_address_show(struct seq_file *f, void *p)
return 0;
}
-static int random_address_open(struct inode *inode, struct file *file)
-{
- return single_open(file, random_address_show, inode->i_private);
-}
-
-static const struct file_operations random_address_fops = {
- .open = random_address_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(random_address);
static int static_address_show(struct seq_file *f, void *p)
{
@@ -769,17 +649,7 @@ static int static_address_show(struct seq_file *f, void *p)
return 0;
}
-static int static_address_open(struct inode *inode, struct file *file)
-{
- return single_open(file, static_address_show, inode->i_private);
-}
-
-static const struct file_operations static_address_fops = {
- .open = static_address_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(static_address);
static ssize_t force_static_address_read(struct file *file,
char __user *user_buf,
@@ -841,17 +711,7 @@ static int white_list_show(struct seq_file *f, void *ptr)
return 0;
}
-static int white_list_open(struct inode *inode, struct file *file)
-{
- return single_open(file, white_list_show, inode->i_private);
-}
-
-static const struct file_operations white_list_fops = {
- .open = white_list_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(white_list);
static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
{
@@ -869,18 +729,7 @@ static int identity_resolving_keys_show(struct seq_file *f, void *ptr)
return 0;
}
-static int identity_resolving_keys_open(struct inode *inode, struct file *file)
-{
- return single_open(file, identity_resolving_keys_show,
- inode->i_private);
-}
-
-static const struct file_operations identity_resolving_keys_fops = {
- .open = identity_resolving_keys_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(identity_resolving_keys);
static int long_term_keys_show(struct seq_file *f, void *ptr)
{
@@ -898,17 +747,7 @@ static int long_term_keys_show(struct seq_file *f, void *ptr)
return 0;
}
-static int long_term_keys_open(struct inode *inode, struct file *file)
-{
- return single_open(file, long_term_keys_show, inode->i_private);
-}
-
-static const struct file_operations long_term_keys_fops = {
- .open = long_term_keys_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(long_term_keys);
static int conn_min_interval_set(void *data, u64 val)
{
--
2.15.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro
2017-11-23 20:36 ` [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro Andy Shevchenko
@ 2017-11-28 8:43 ` Marcel Holtmann
[not found] ` <F129B4E0-91B1-4B7B-AF5D-A5EA29486A6E-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
0 siblings, 1 reply; 6+ messages in thread
From: Marcel Holtmann @ 2017-11-28 8:43 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Johan Hedberg, open list:BLUETOOTH DRIVERS, David S. Miller,
Network Development, Randy Dunlap
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro
[not found] ` <F129B4E0-91B1-4B7B-AF5D-A5EA29486A6E-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
@ 2017-11-28 12:19 ` Andy Shevchenko
2017-12-13 15:38 ` Andy Shevchenko
0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2017-11-28 12:19 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Johan Hedberg, open list:BLUETOOTH DRIVERS, David S. Miller,
Network Development, Randy Dunlap
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 <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Intel Finland Oy
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro
2017-11-28 12:19 ` Andy Shevchenko
@ 2017-12-13 15:38 ` Andy Shevchenko
0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2017-12-13 15:38 UTC (permalink / raw)
To: Marcel Holtmann
Cc: Johan Hedberg, open list:BLUETOOTH DRIVERS, David S. Miller,
Network Development, Randy Dunlap
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?
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-12-13 15:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-23 20:36 [PATCH v2 0/2] seq_file, Bluetooth: introduce DEFINE_SHOW_ATTRIBUTE() Andy Shevchenko
2017-11-23 20:36 ` [PATCH v2 1/2] seq_file: Introduce DEFINE_SHOW_ATTRIBUTE() helper macro Andy Shevchenko
2017-11-28 8:43 ` Marcel Holtmann
[not found] ` <F129B4E0-91B1-4B7B-AF5D-A5EA29486A6E-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
2017-11-28 12:19 ` Andy Shevchenko
2017-12-13 15:38 ` Andy Shevchenko
2017-11-23 20:36 ` [PATCH v2 2/2] Bluetooth: Re-use DEFINE_SHOW_ATTRIBUTE() macro Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).