Skip to contentSkip to conversation

x86/platform/atom: Re-use DEFINE_SHOW_ATTRIBUTE() macro

PATCH In review Andy Shevchenko 3 participants 6 messages Feb 14, 2018 – Feb 16, 2018 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 x86/platform/atom: Re-use DEFINE_SHOW_ATTRIBUTE() macro

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

While here, replace permissions by explicit octal value.

---
 arch/x86/platform/atom/punit_atom_debug.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
arch/x86/platform/atom/punit_atom_debug.c +1 -12
index d49d3be81953..156b445bcf4d 100644
@@ -109,18 +109,7 @@ static int punit_dev_state_show(struct seq_file *seq_file, void *unused)
 
 	return 0;
 }
-
-static int punit_dev_state_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, punit_dev_state_show, inode->i_private);
-}
-
-static const struct file_operations punit_dev_state_ops = {
-	.open		= punit_dev_state_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(punit_dev_state);
 
 static struct dentry *punit_dbg_file;
 
Signature · 1 line
2.15.1
#1 lore raw

PATCH 2/2 x86/platform/quark: Re-use DEFINE_SHOW_ATTRIBUTE() macro

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

While here, replace permissions by explicit octal value.

---
 arch/x86/platform/intel-quark/imr.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)
arch/x86/platform/intel-quark/imr.c +3 -21
index 17d6d2296e4d..49828c2707ac 100644
@@ -224,25 +224,7 @@ static int imr_dbgfs_state_show(struct seq_file *s, void *unused)
 	mutex_unlock(&idev->lock);
 	return ret;
 }
-
-/**
- * imr_state_open - debugfs open callback.
- *
- * @inode:	pointer to struct inode.
- * @file:	pointer to struct file.
- * @return:	result of single open.
- */
-static int imr_state_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, imr_dbgfs_state_show, inode->i_private);
-}
-
-static const struct file_operations imr_state_ops = {
-	.open		= imr_state_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(imr_dbgfs_state);
 
 /**
  * imr_debugfs_register - register debugfs hooks.
@@ -252,8 +234,8 @@ static const struct file_operations imr_state_ops = {
  */
 static int imr_debugfs_register(struct imr_device *idev)
 {
-	idev->file = debugfs_create_file("imr_state", S_IFREG | S_IRUGO, NULL,
-					 idev, &imr_state_ops);
+	idev->file = debugfs_create_file("imr_state", 0444, NULL, idev,
+					 &imr_dbgfs_state_fops);
 	return PTR_ERR_OR_ZERO(idev->file);
 }
 
Signature · 1 line
2.15.1
#2 lore raw

[tip:x86/platform] x86/platform/quark: Re-use DEFINE_SHOW_ATTRIBUTE() macro

x86/platform/quark: Re-use DEFINE_SHOW_ATTRIBUTE() macro
Commit-ID:  a66b86f0026b07b0ea7340e3690ac9fd5ac1499a
Gitweb:     https://git.kernel.org/tip/a66b86f0026b07b0ea7340e3690ac9fd5ac1499a
Author:     Andy Shevchenko <[email protected]>
AuthorDate: Wed, 14 Feb 2018 17:43:17 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 16 Feb 2018 10:10:14 +0100

x86/platform/quark: Re-use DEFINE_SHOW_ATTRIBUTE() macro

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

While here, replace permissions by explicit octal value.

---
 arch/x86/platform/intel-quark/imr.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)
arch/x86/platform/intel-quark/imr.c +3 -21
index 17d6d22..49828c2 100644
@@ -224,25 +224,7 @@ static int imr_dbgfs_state_show(struct seq_file *s, void *unused)
 	mutex_unlock(&idev->lock);
 	return ret;
 }
-
-/**
- * imr_state_open - debugfs open callback.
- *
- * @inode:	pointer to struct inode.
- * @file:	pointer to struct file.
- * @return:	result of single open.
- */
-static int imr_state_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, imr_dbgfs_state_show, inode->i_private);
-}
-
-static const struct file_operations imr_state_ops = {
-	.open		= imr_state_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(imr_dbgfs_state);
 
 /**
  * imr_debugfs_register - register debugfs hooks.
@@ -252,8 +234,8 @@ static const struct file_operations imr_state_ops = {
  */
 static int imr_debugfs_register(struct imr_device *idev)
 {
-	idev->file = debugfs_create_file("imr_state", S_IFREG | S_IRUGO, NULL,
-					 idev, &imr_state_ops);
+	idev->file = debugfs_create_file("imr_state", 0444, NULL, idev,
+					 &imr_dbgfs_state_fops);
 	return PTR_ERR_OR_ZERO(idev->file);
 }
 
#3 lore raw
In reply to Andy Shevchenko
Quoted 23 lines · Andy Shevchenko

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

While here, replace permissions by explicit octal value.

---
 arch/x86/platform/atom/punit_atom_debug.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
arch/x86/platform/atom/punit_atom_debug.c +0 -5
index d49d3be81953..156b445bcf4d 100644
@@ -109,18 +109,7 @@ static int punit_dev_state_show(struct seq_file *seq_file, void *unused)
 
 	return 0;
 }
-
-static int punit_dev_state_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, punit_dev_state_show, inode->i_private);
-}

arch/x86/platform/atom/punit_atom_debug.c static int punit_dev_state_show(struct seq_file *seq_file, void *unused) · line 114

Quoted 10 lines
arch/x86/platform/atom/punit_atom_debug.c +1 -7
-
-static const struct file_operations punit_dev_state_ops = {
-	.open		= punit_dev_state_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(punit_dev_state);
 
 static struct dentry *punit_dbg_file;

Hm, that octal value replacement does not seem to be part of this patch, only the next patch.

Also, the debugfs_create_file() call still uses the old &punit_dev_state_ops callback array.

Did a patch hunk go missing?

I've added the fixes below to the patch.

Thanks,

Ingo

arch/x86/platform/atom/punit_atom_debug.c +2 -2
@@ -132,9 +121,9 @@ static int punit_dbgfs_register(struct p
 	if (!punit_dbg_file)
 		return -ENXIO;
 
-	dev_state = debugfs_create_file("dev_power_state", S_IFREG | S_IRUGO,
+	dev_state = debugfs_create_file("dev_power_state", 0444,
 					punit_dbg_file, punit_device,
-					&punit_dev_state_ops);
+					&punit_dev_state_fops);
 	if (!dev_state) {
 		pr_err("punit_dev_state register failed\n");
 		debugfs_remove(punit_dbg_file);
#4 lore raw
Quoted 45 lines · Ingo Molnar
Quoted 37 lines · Andy Shevchenko

...instead of open coding file operations followed by custom ->open()
callbacks per each attribute.

While here, replace permissions by explicit octal value.

---
 arch/x86/platform/atom/punit_atom_debug.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
arch/x86/platform/atom/punit_atom_debug.c +1 -12
index d49d3be81953..156b445bcf4d 100644
@@ -109,18 +109,7 @@ static int punit_dev_state_show(struct seq_file
 *seq_file, void *unused)
 
 	return 0;
 }
-
-static int punit_dev_state_open(struct inode *inode, struct file
 *file)
-{
-	return single_open(file, punit_dev_state_show, inode-
 >i_private);
-}
-
-static const struct file_operations punit_dev_state_ops = {
-	.open		= punit_dev_state_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(punit_dev_state);
Quoted 1 line

static struct dentry *punit_dbg_file;

Hm, that octal value replacement does not seem to be part of this patch, only the
next patch.

Quoted 5 lines

Also, the debugfs_create_file() call still uses the old &punit_dev_state_ops
callback array.

Did a patch hunk go missing?

Ooops, sorry.
Indeed, it happened to be half baked.

Quoted 2 lines

I've added the fixes below to the patch.

Thanks!

Quoted 20 lines

Thanks,

Ingo

arch/x86/platform/atom/punit_atom_debug.c +2 -2
@@ -132,9 +121,9 @@ static int punit_dbgfs_register(struct p
 	if (!punit_dbg_file)
 		return -ENXIO;
 
-	dev_state = debugfs_create_file("dev_power_state", S_IFREG |
 S_IRUGO,
+	dev_state = debugfs_create_file("dev_power_state", 0444,
 					punit_dbg_file, punit_device,
-					&punit_dev_state_ops);
+					&punit_dev_state_fops);
 	if (!dev_state) {
 		pr_err("punit_dev_state register failed\n");

debugfs_remove(punit_dbg_file);

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
#5 lore raw
In reply to Andy Shevchenko
x86/platform/atom: Re-use DEFINE_SHOW_ATTRIBUTE() macro
Commit-ID:  3130451e270960065e8de684c60b898e970c940c
Gitweb:     https://git.kernel.org/tip/3130451e270960065e8de684c60b898e970c940c
Author:     Andy Shevchenko <[email protected]>
AuthorDate: Wed, 14 Feb 2018 17:43:16 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 16 Feb 2018 10:10:14 +0100

x86/platform/atom: Re-use DEFINE_SHOW_ATTRIBUTE() macro

...instead of open coding file operations followed by custom ->open() callbacks per each attribute.

While here, replace permissions by explicit octal value.

---
 arch/x86/platform/atom/punit_atom_debug.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
arch/x86/platform/atom/punit_atom_debug.c +3 -14
index d49d3be..034813d 100644
@@ -109,18 +109,7 @@ static int punit_dev_state_show(struct seq_file *seq_file, void *unused)
 
 	return 0;
 }
-
-static int punit_dev_state_open(struct inode *inode, struct file *file)
-{
-	return single_open(file, punit_dev_state_show, inode->i_private);
-}
-
-static const struct file_operations punit_dev_state_ops = {
-	.open		= punit_dev_state_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= single_release,
-};
+DEFINE_SHOW_ATTRIBUTE(punit_dev_state);
 
 static struct dentry *punit_dbg_file;
 
@@ -132,9 +121,9 @@ static int punit_dbgfs_register(struct punit_device *punit_device)
 	if (!punit_dbg_file)
 		return -ENXIO;
 
-	dev_state = debugfs_create_file("dev_power_state", S_IFREG | S_IRUGO,
+	dev_state = debugfs_create_file("dev_power_state", 0444,
 					punit_dbg_file, punit_device,
-					&punit_dev_state_ops);
+					&punit_dev_state_fops);
 	if (!dev_state) {
 		pr_err("punit_dev_state register failed\n");
 		debugfs_remove(punit_dbg_file);