diff mbox series

[v1,6/9] pktcdvd: Use DEFINE_SHOW_ATTRIBUTE() to simplify code

Message ID 20230119220809.5518-6-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/9] pktcdvd: Get rid of custom printing macros | expand

Commit Message

Andy Shevchenko Jan. 19, 2023, 10:08 p.m. UTC
Use DEFINE_SHOW_ATTRIBUTE() helper macro to simplify the code.
No functional change.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/block/pktcdvd.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

Comments

Greg KH Jan. 20, 2023, 7:26 a.m. UTC | #1
On Fri, Jan 20, 2023 at 12:08:06AM +0200, Andy Shevchenko wrote:
> Use DEFINE_SHOW_ATTRIBUTE() helper macro to simplify the code.
> No functional change.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/block/pktcdvd.c | 23 +++--------------------
>  1 file changed, 3 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
> index a53d21dbf2ab..2c5441303e55 100644
> --- a/drivers/block/pktcdvd.c
> +++ b/drivers/block/pktcdvd.c
> @@ -504,24 +504,7 @@ static int pkt_seq_show(struct seq_file *m, void *p)
>  			pd->write_congestion_on);
>  	return 0;
>  }
> -
> -static int pkt_debugfs_seq_show(struct seq_file *m, void *p)
> -{
> -	return pkt_seq_show(m, p);
> -}
> -
> -static int pkt_debugfs_fops_open(struct inode *inode, struct file *file)
> -{
> -	return single_open(file, pkt_debugfs_seq_show, inode->i_private);
> -}
> -
> -static const struct file_operations debug_fops = {
> -	.open		= pkt_debugfs_fops_open,
> -	.read		= seq_read,
> -	.llseek		= seq_lseek,
> -	.release	= single_release,
> -	.owner		= THIS_MODULE,
> -};
> +DEFINE_SHOW_ATTRIBUTE(pkt_seq);
>  
>  static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)
>  {
> @@ -531,8 +514,8 @@ static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)
>  	if (!pd->dfs_d_root)
>  		return;

This check shouldn't be here either.

> -	pd->dfs_f_info = debugfs_create_file("info", 0444,
> -					     pd->dfs_d_root, pd, &debug_fops);
> +	pd->dfs_f_info = debugfs_create_file("info", 0444, pd->dfs_d_root,
> +					     pd, &pkt_seq_fops);

For further cleanup, there's no need to keep this dentry at all as the
whole directory is later removed.

But that's future cleanups, for this, nice work:

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff mbox series

Patch

diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index a53d21dbf2ab..2c5441303e55 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -504,24 +504,7 @@  static int pkt_seq_show(struct seq_file *m, void *p)
 			pd->write_congestion_on);
 	return 0;
 }
-
-static int pkt_debugfs_seq_show(struct seq_file *m, void *p)
-{
-	return pkt_seq_show(m, p);
-}
-
-static int pkt_debugfs_fops_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, pkt_debugfs_seq_show, inode->i_private);
-}
-
-static const struct file_operations debug_fops = {
-	.open		= pkt_debugfs_fops_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-	.owner		= THIS_MODULE,
-};
+DEFINE_SHOW_ATTRIBUTE(pkt_seq);
 
 static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)
 {
@@ -531,8 +514,8 @@  static void pkt_debugfs_dev_new(struct pktcdvd_device *pd)
 	if (!pd->dfs_d_root)
 		return;
 
-	pd->dfs_f_info = debugfs_create_file("info", 0444,
-					     pd->dfs_d_root, pd, &debug_fops);
+	pd->dfs_f_info = debugfs_create_file("info", 0444, pd->dfs_d_root,
+					     pd, &pkt_seq_fops);
 }
 
 static void pkt_debugfs_dev_remove(struct pktcdvd_device *pd)