* usb: dwc3: debugfs: Re-use DEFINE_SHOW_ATTRIBUTE() macro
@ 2018-02-15 13:12 Felipe Balbi
0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2018-02-15 13:12 UTC (permalink / raw)
To: Andy Shevchenko, Linux USB
Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
> On Thu, 2018-02-15 at 13:16 +0200, Felipe Balbi wrote:
>> ...instead of open coding file operations followed by custom ->open()
>> callbacks per each attribute.
>>
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Though one comment below.
>
>> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
>
>> static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep,
>> + struct dentry *parent, const char *const name,
>> + const struct file_operations *const fops)
>> {
>> + (void) debugfs_create_file(name, S_IRUGO, parent, dep, fops);
>> }
>
> At this point why do you need one line function anymore?
fair enough, here you go:
8<------------------------------------------------------------------------------
From 32ea5fda7654e7c081fff161544da73d53bf8fac Mon Sep 17 00:00:00 2001
From: Felipe Balbi <felipe.balbi@linux.intel.com>
Date: Thu, 15 Feb 2018 13:03:38 +0200
Subject: [PATCH] usb: dwc3: debugfs: Re-use DEFINE_SHOW_ATTRIBUTE() macro
...instead of open coding file operations followed by custom ->open()
callbacks per each attribute.
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
---
drivers/usb/dwc3/debugfs.c | 79 ++++++++++++++++++----------------------------
1 file changed, 30 insertions(+), 49 deletions(-)
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 00e65530c81e..c4c0dcb3f589 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -487,8 +487,8 @@ static const struct file_operations dwc3_link_state_fops = {
};
struct dwc3_ep_file_map {
- char name[25];
- int (*show)(struct seq_file *s, void *unused);
+ const char name[25];
+ const struct file_operations *const fops;
};
static int dwc3_tx_fifo_queue_show(struct seq_file *s, void *unused)
@@ -596,7 +596,7 @@ static int dwc3_event_queue_show(struct seq_file *s, void *unused)
return 0;
}
-static int dwc3_ep_transfer_type_show(struct seq_file *s, void *unused)
+static int dwc3_transfer_type_show(struct seq_file *s, void *unused)
{
struct dwc3_ep *dep = s->private;
struct dwc3 *dwc = dep->dwc;
@@ -632,7 +632,7 @@ static int dwc3_ep_transfer_type_show(struct seq_file *s, void *unused)
return 0;
}
-static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
+static int dwc3_trb_ring_show(struct seq_file *s, void *unused)
{
struct dwc3_ep *dep = s->private;
struct dwc3 *dwc = dep->dwc;
@@ -670,58 +670,39 @@ static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
return 0;
}
-static struct dwc3_ep_file_map map[] = {
- { "tx_fifo_queue", dwc3_tx_fifo_queue_show, },
- { "rx_fifo_queue", dwc3_rx_fifo_queue_show, },
- { "tx_request_queue", dwc3_tx_request_queue_show, },
- { "rx_request_queue", dwc3_rx_request_queue_show, },
- { "rx_info_queue", dwc3_rx_info_queue_show, },
- { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show, },
- { "event_queue", dwc3_event_queue_show, },
- { "transfer_type", dwc3_ep_transfer_type_show, },
- { "trb_ring", dwc3_ep_trb_ring_show, },
+DEFINE_SHOW_ATTRIBUTE(dwc3_tx_fifo_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_rx_fifo_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_tx_request_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_rx_request_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_rx_info_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_descriptor_fetch_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_event_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_transfer_type);
+DEFINE_SHOW_ATTRIBUTE(dwc3_trb_ring);
+
+static const struct dwc3_ep_file_map dwc3_ep_file_map[] = {
+ { "tx_fifo_queue", &dwc3_tx_fifo_queue_fops, },
+ { "rx_fifo_queue", &dwc3_rx_fifo_queue_fops, },
+ { "tx_request_queue", &dwc3_tx_request_queue_fops, },
+ { "rx_request_queue", &dwc3_rx_request_queue_fops, },
+ { "rx_info_queue", &dwc3_rx_info_queue_fops, },
+ { "descriptor_fetch_queue", &dwc3_descriptor_fetch_queue_fops, },
+ { "event_queue", &dwc3_event_queue_fops, },
+ { "transfer_type", &dwc3_transfer_type_fops, },
+ { "trb_ring", &dwc3_trb_ring_fops, },
};
-static int dwc3_endpoint_open(struct inode *inode, struct file *file)
-{
- const char *file_name = file_dentry(file)->d_iname;
- struct dwc3_ep_file_map *f_map;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(map); i++) {
- f_map = &map[i];
-
- if (strcmp(f_map->name, file_name) == 0)
- break;
- }
-
- return single_open(file, f_map->show, inode->i_private);
-}
-
-static const struct file_operations dwc3_endpoint_fops = {
- .open = dwc3_endpoint_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
-static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep,
- struct dentry *parent, int type)
-{
- struct dentry *file;
- struct dwc3_ep_file_map *ep_file = &map[type];
-
- file = debugfs_create_file(ep_file->name, S_IRUGO, parent, dep,
- &dwc3_endpoint_fops);
-}
-
static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
struct dentry *parent)
{
int i;
- for (i = 0; i < ARRAY_SIZE(map); i++)
- dwc3_debugfs_create_endpoint_file(dep, parent, i);
+ for (i = 0; i < ARRAY_SIZE(dwc3_ep_file_map); i++) {
+ const struct file_operations *fops = dwc3_ep_file_map[i].fops;
+ const char *name = dwc3_ep_file_map[i].name;
+
+ debugfs_create_file(name, S_IRUGO, parent, dep, fops);
+ }
}
static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
^ permalink raw reply related [flat|nested] 4+ messages in thread
* usb: dwc3: debugfs: Re-use DEFINE_SHOW_ATTRIBUTE() macro
@ 2018-02-20 18:12 Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2018-02-20 18:12 UTC (permalink / raw)
To: Felipe Balbi, Linux USB
On Thu, 2018-02-15 at 15:12 +0200, Felipe Balbi wrote:
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
>
> > On Thu, 2018-02-15 at 13:16 +0200, Felipe Balbi wrote:
> > > ...instead of open coding file operations followed by custom
> > > ->open()
> > > callbacks per each attribute.
> > >
> >
> > Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > Though one comment below.
> >
> > > Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
> > > static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep
> > > *dep,
> > > + struct dentry *parent, const char *const name,
> > > + const struct file_operations *const fops)
> > > {
> > > + (void) debugfs_create_file(name, S_IRUGO, parent, dep,
> > > fops);
> > > }
> >
> > At this point why do you need one line function anymore?
>
> fair enough, here you go:
Feel free to add
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 8<------------------------------------------------------------------
> ------------
> From 32ea5fda7654e7c081fff161544da73d53bf8fac Mon Sep 17 00:00:00 2001
> From: Felipe Balbi <felipe.balbi@linux.intel.com>
> Date: Thu, 15 Feb 2018 13:03:38 +0200
> Subject: [PATCH] usb: dwc3: debugfs: Re-use DEFINE_SHOW_ATTRIBUTE()
> macro
>
> ...instead of open coding file operations followed by custom ->open()
> callbacks per each attribute.
>
> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
> ---
> drivers/usb/dwc3/debugfs.c | 79 ++++++++++++++++++-------------------
> ---------
> 1 file changed, 30 insertions(+), 49 deletions(-)
>
> diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
> index 00e65530c81e..c4c0dcb3f589 100644
> --- a/drivers/usb/dwc3/debugfs.c
> +++ b/drivers/usb/dwc3/debugfs.c
> @@ -487,8 +487,8 @@ static const struct file_operations
> dwc3_link_state_fops = {
> };
>
> struct dwc3_ep_file_map {
> - char name[25];
> - int (*show)(struct seq_file *s, void *unused);
> + const char name[25];
> + const struct file_operations *const fops;
> };
>
> static int dwc3_tx_fifo_queue_show(struct seq_file *s, void *unused)
> @@ -596,7 +596,7 @@ static int dwc3_event_queue_show(struct seq_file
> *s, void *unused)
> return 0;
> }
>
> -static int dwc3_ep_transfer_type_show(struct seq_file *s, void
> *unused)
> +static int dwc3_transfer_type_show(struct seq_file *s, void *unused)
> {
> struct dwc3_ep *dep = s->private;
> struct dwc3 *dwc = dep->dwc;
> @@ -632,7 +632,7 @@ static int dwc3_ep_transfer_type_show(struct
> seq_file *s, void *unused)
> return 0;
> }
>
> -static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
> +static int dwc3_trb_ring_show(struct seq_file *s, void *unused)
> {
> struct dwc3_ep *dep = s->private;
> struct dwc3 *dwc = dep->dwc;
> @@ -670,58 +670,39 @@ static int dwc3_ep_trb_ring_show(struct seq_file
> *s, void *unused)
> return 0;
> }
>
> -static struct dwc3_ep_file_map map[] = {
> - { "tx_fifo_queue", dwc3_tx_fifo_queue_show, },
> - { "rx_fifo_queue", dwc3_rx_fifo_queue_show, },
> - { "tx_request_queue", dwc3_tx_request_queue_show, },
> - { "rx_request_queue", dwc3_rx_request_queue_show, },
> - { "rx_info_queue", dwc3_rx_info_queue_show, },
> - { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show,
> },
> - { "event_queue", dwc3_event_queue_show, },
> - { "transfer_type", dwc3_ep_transfer_type_show, },
> - { "trb_ring", dwc3_ep_trb_ring_show, },
> +DEFINE_SHOW_ATTRIBUTE(dwc3_tx_fifo_queue);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_rx_fifo_queue);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_tx_request_queue);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_rx_request_queue);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_rx_info_queue);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_descriptor_fetch_queue);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_event_queue);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_transfer_type);
> +DEFINE_SHOW_ATTRIBUTE(dwc3_trb_ring);
> +
> +static const struct dwc3_ep_file_map dwc3_ep_file_map[] = {
> + { "tx_fifo_queue", &dwc3_tx_fifo_queue_fops, },
> + { "rx_fifo_queue", &dwc3_rx_fifo_queue_fops, },
> + { "tx_request_queue", &dwc3_tx_request_queue_fops, },
> + { "rx_request_queue", &dwc3_rx_request_queue_fops, },
> + { "rx_info_queue", &dwc3_rx_info_queue_fops, },
> + { "descriptor_fetch_queue",
> &dwc3_descriptor_fetch_queue_fops, },
> + { "event_queue", &dwc3_event_queue_fops, },
> + { "transfer_type", &dwc3_transfer_type_fops, },
> + { "trb_ring", &dwc3_trb_ring_fops, },
> };
>
> -static int dwc3_endpoint_open(struct inode *inode, struct file *file)
> -{
> - const char *file_name = file_dentry(file)-
> >d_iname;
> - struct dwc3_ep_file_map *f_map;
> - int i;
> -
> - for (i = 0; i < ARRAY_SIZE(map); i++) {
> - f_map = &map[i];
> -
> - if (strcmp(f_map->name, file_name) == 0)
> - break;
> - }
> -
> - return single_open(file, f_map->show, inode->i_private);
> -}
> -
> -static const struct file_operations dwc3_endpoint_fops = {
> - .open = dwc3_endpoint_open,
> - .read = seq_read,
> - .llseek = seq_lseek,
> - .release = single_release,
> -};
> -
> -static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep,
> - struct dentry *parent, int type)
> -{
> - struct dentry *file;
> - struct dwc3_ep_file_map *ep_file = &map[type];
> -
> - file = debugfs_create_file(ep_file->name, S_IRUGO, parent,
> dep,
> - &dwc3_endpoint_fops);
> -}
> -
> static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
> struct dentry *parent)
> {
> int i;
>
> - for (i = 0; i < ARRAY_SIZE(map); i++)
> - dwc3_debugfs_create_endpoint_file(dep, parent, i);
> + for (i = 0; i < ARRAY_SIZE(dwc3_ep_file_map); i++) {
> + const struct file_operations *fops =
> dwc3_ep_file_map[i].fops;
> + const char *name = dwc3_ep_file_map[i].name;
> +
> + debugfs_create_file(name, S_IRUGO, parent, dep,
> fops);
> + }
> }
>
> static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
> --
> 2.16.1
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* usb: dwc3: debugfs: Re-use DEFINE_SHOW_ATTRIBUTE() macro
@ 2018-02-15 13:00 Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2018-02-15 13:00 UTC (permalink / raw)
To: Felipe Balbi, Linux USB
On Thu, 2018-02-15 at 13:16 +0200, Felipe Balbi wrote:
> ...instead of open coding file operations followed by custom ->open()
> callbacks per each attribute.
>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Though one comment below.
> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
> static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep,
> + struct dentry *parent, const char *const name,
> + const struct file_operations *const fops)
> {
> + (void) debugfs_create_file(name, S_IRUGO, parent, dep, fops);
> }
At this point why do you need one line function anymore?
> + dwc3_debugfs_create_endpoint_file(dep, parent,
> + name, fops);
^ permalink raw reply [flat|nested] 4+ messages in thread
* usb: dwc3: debugfs: Re-use DEFINE_SHOW_ATTRIBUTE() macro
@ 2018-02-15 11:16 Felipe Balbi
0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2018-02-15 11:16 UTC (permalink / raw)
To: Linux USB; +Cc: Andy Shevchenko, Felipe Balbi
...instead of open coding file operations followed by custom ->open()
callbacks per each attribute.
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
---
drivers/usb/dwc3/debugfs.c | 79 ++++++++++++++++++++--------------------------
1 file changed, 34 insertions(+), 45 deletions(-)
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 00e65530c81e..160dc90a4a41 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -487,8 +487,8 @@ static const struct file_operations dwc3_link_state_fops = {
};
struct dwc3_ep_file_map {
- char name[25];
- int (*show)(struct seq_file *s, void *unused);
+ const char name[25];
+ const struct file_operations *const fops;
};
static int dwc3_tx_fifo_queue_show(struct seq_file *s, void *unused)
@@ -596,7 +596,7 @@ static int dwc3_event_queue_show(struct seq_file *s, void *unused)
return 0;
}
-static int dwc3_ep_transfer_type_show(struct seq_file *s, void *unused)
+static int dwc3_transfer_type_show(struct seq_file *s, void *unused)
{
struct dwc3_ep *dep = s->private;
struct dwc3 *dwc = dep->dwc;
@@ -632,7 +632,7 @@ static int dwc3_ep_transfer_type_show(struct seq_file *s, void *unused)
return 0;
}
-static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
+static int dwc3_trb_ring_show(struct seq_file *s, void *unused)
{
struct dwc3_ep *dep = s->private;
struct dwc3 *dwc = dep->dwc;
@@ -670,49 +670,33 @@ static int dwc3_ep_trb_ring_show(struct seq_file *s, void *unused)
return 0;
}
-static struct dwc3_ep_file_map map[] = {
- { "tx_fifo_queue", dwc3_tx_fifo_queue_show, },
- { "rx_fifo_queue", dwc3_rx_fifo_queue_show, },
- { "tx_request_queue", dwc3_tx_request_queue_show, },
- { "rx_request_queue", dwc3_rx_request_queue_show, },
- { "rx_info_queue", dwc3_rx_info_queue_show, },
- { "descriptor_fetch_queue", dwc3_descriptor_fetch_queue_show, },
- { "event_queue", dwc3_event_queue_show, },
- { "transfer_type", dwc3_ep_transfer_type_show, },
- { "trb_ring", dwc3_ep_trb_ring_show, },
-};
-
-static int dwc3_endpoint_open(struct inode *inode, struct file *file)
-{
- const char *file_name = file_dentry(file)->d_iname;
- struct dwc3_ep_file_map *f_map;
- int i;
-
- for (i = 0; i < ARRAY_SIZE(map); i++) {
- f_map = &map[i];
-
- if (strcmp(f_map->name, file_name) == 0)
- break;
- }
-
- return single_open(file, f_map->show, inode->i_private);
-}
-
-static const struct file_operations dwc3_endpoint_fops = {
- .open = dwc3_endpoint_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = single_release,
+DEFINE_SHOW_ATTRIBUTE(dwc3_tx_fifo_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_rx_fifo_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_tx_request_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_rx_request_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_rx_info_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_descriptor_fetch_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_event_queue);
+DEFINE_SHOW_ATTRIBUTE(dwc3_transfer_type);
+DEFINE_SHOW_ATTRIBUTE(dwc3_trb_ring);
+
+static const struct dwc3_ep_file_map dwc3_ep_file_map[] = {
+ { "tx_fifo_queue", &dwc3_tx_fifo_queue_fops, },
+ { "rx_fifo_queue", &dwc3_rx_fifo_queue_fops, },
+ { "tx_request_queue", &dwc3_tx_request_queue_fops, },
+ { "rx_request_queue", &dwc3_rx_request_queue_fops, },
+ { "rx_info_queue", &dwc3_rx_info_queue_fops, },
+ { "descriptor_fetch_queue", &dwc3_descriptor_fetch_queue_fops, },
+ { "event_queue", &dwc3_event_queue_fops, },
+ { "transfer_type", &dwc3_transfer_type_fops, },
+ { "trb_ring", &dwc3_trb_ring_fops, },
};
static void dwc3_debugfs_create_endpoint_file(struct dwc3_ep *dep,
- struct dentry *parent, int type)
+ struct dentry *parent, const char *const name,
+ const struct file_operations *const fops)
{
- struct dentry *file;
- struct dwc3_ep_file_map *ep_file = &map[type];
-
- file = debugfs_create_file(ep_file->name, S_IRUGO, parent, dep,
- &dwc3_endpoint_fops);
+ (void) debugfs_create_file(name, S_IRUGO, parent, dep, fops);
}
static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
@@ -720,8 +704,13 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
{
int i;
- for (i = 0; i < ARRAY_SIZE(map); i++)
- dwc3_debugfs_create_endpoint_file(dep, parent, i);
+ for (i = 0; i < ARRAY_SIZE(dwc3_ep_file_map); i++) {
+ const struct file_operations *fops = dwc3_ep_file_map[i].fops;
+ const char *name = dwc3_ep_file_map[i].name;
+
+ dwc3_debugfs_create_endpoint_file(dep, parent,
+ name, fops);
+ }
}
static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-02-20 18:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-15 13:12 usb: dwc3: debugfs: Re-use DEFINE_SHOW_ATTRIBUTE() macro Felipe Balbi
-- strict thread matches above, loose matches on Subject: below --
2018-02-20 18:12 Andy Shevchenko
2018-02-15 13:00 Andy Shevchenko
2018-02-15 11:16 Felipe Balbi
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.