Skip to contentSkip to conversation

block: aoe: no need to check return value of debugfs_create functions

PATCH In review Greg Kroah-Hartman 5 participants 8 messages Jan 22, 2019 – Jun 4, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: aoe: no need to check return value of debugfs_create functions

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

---
 drivers/block/aoe/aoeblk.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/block/aoe/aoeblk.c +1 -12
index e2c6aae2d636..b602646bfa04 100644
@@ -207,14 +207,7 @@ aoedisk_add_debugfs(struct aoedev *d)
 	else
 		p++;
 	BUG_ON(*p == '\0');
-	entry = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
-				    &aoe_debugfs_fops);
-	if (IS_ERR_OR_NULL(entry)) {
-		pr_info("aoe: cannot create debugfs file for %s\n",
-			d->gd->disk_name);
-		return;
-	}
-	BUG_ON(d->debugfs);
+	debugfs_create_file(p, 0444, aoe_debugfs_dir, d, &aoe_debugfs_fops);
 	d->debugfs = entry;
 }
 void
@@ -472,10 +465,6 @@ aoeblk_init(void)
 	if (buf_pool_cache == NULL)
 		return -ENOMEM;
 	aoe_debugfs_dir = debugfs_create_dir("aoe", NULL);
-	if (IS_ERR_OR_NULL(aoe_debugfs_dir)) {
-		pr_info("aoe: cannot create debugfs directory\n");
-		aoe_debugfs_dir = NULL;
-	}
 	return 0;
 }
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 20 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

---
 drivers/block/aoe/aoeblk.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/block/aoe/aoeblk.c +0 -0
index e2c6aae2d636..b602646bfa04 100644
@@ -207,14 +207,7 @@ aoedisk_add_debugfs(struct aoedev *d)
 	else
 		p++;
 	BUG_ON(*p == '\0');

drivers/block/aoe/aoeblk.c aoedisk_add_debugfs(struct aoedev *d) · line 211

Quoted 10 lines
drivers/block/aoe/aoeblk.c +1 -8
-	entry = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
-				    &aoe_debugfs_fops);
-	if (IS_ERR_OR_NULL(entry)) {
-		pr_info("aoe: cannot create debugfs file for %s\n",
-			d->gd->disk_name);
-		return;
-	}
-	BUG_ON(d->debugfs);
+	debugfs_create_file(p, 0444, aoe_debugfs_dir, d, &aoe_debugfs_fops);
 	d->debugfs = entry;

Now entry is uninitialized here when we assign it to d->debugfs.

Quoted 16 lines
drivers/block/aoe/aoeblk.c +0 -4
 }
 void
@@ -472,10 +465,6 @@ aoeblk_init(void)
 	if (buf_pool_cache == NULL)
 		return -ENOMEM;
 	aoe_debugfs_dir = debugfs_create_dir("aoe", NULL);
-	if (IS_ERR_OR_NULL(aoe_debugfs_dir)) {
-		pr_info("aoe: cannot create debugfs directory\n");
-		aoe_debugfs_dir = NULL;
-	}
 	return 0;
 }
 
Signature · 1 line
2.20.1
#2 lore raw

On Tue, Jan 22, 2019 at 6:29 PM Omar Sandoval <[email protected]> wrote:
...

Quoted 1 line

Now entry is uninitialized here when we assign it to d->debugfs.

Thanks for noticing that.

#3 lore raw
In reply to Omar Sandoval
Quoted 25 lines · Omar Sandoval
Quoted 24 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

---
 drivers/block/aoe/aoeblk.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/block/aoe/aoeblk.c +0 -4
index e2c6aae2d636..b602646bfa04 100644
@@ -207,14 +207,7 @@ aoedisk_add_debugfs(struct aoedev *d)
 	else
 		p++;
 	BUG_ON(*p == '\0');
-	entry = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
-				    &aoe_debugfs_fops);
-	if (IS_ERR_OR_NULL(entry)) {
-		pr_info("aoe: cannot create debugfs file for %s\n",
Quoted 8 lines

drivers/block/aoe/aoeblk.c aoedisk_add_debugfs(struct aoedev *d) · line 211

Quoted 6 lines
drivers/block/aoe/aoeblk.c +1 -4
-			d->gd->disk_name);
-		return;
-	}
-	BUG_ON(d->debugfs);
+	debugfs_create_file(p, 0444, aoe_debugfs_dir, d, &aoe_debugfs_fops);
 	d->debugfs = entry;

Now entry is uninitialized here when we assign it to d->debugfs.

Ah, good catch, I'll go fix this up and post a v2, sorry about that.

greg k-h

#4 lore raw

PATCH v2 1/1 block: aoe: no need to check return value of debugfs_create functions

In reply to Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

---
v2: fix uninitialized entry issue found by Omar Sandoval

 drivers/block/aoe/aoeblk.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/block/aoe/aoeblk.c +2 -14
index e2c6aae2d636..bd19f8af950b 100644
@@ -196,7 +196,6 @@ static const struct file_operations aoe_debugfs_fops = {
 static void
 aoedisk_add_debugfs(struct aoedev *d)
 {
-	struct dentry *entry;
 	char *p;
 
 	if (aoe_debugfs_dir == NULL)
@@ -207,15 +206,8 @@ aoedisk_add_debugfs(struct aoedev *d)
 	else
 		p++;
 	BUG_ON(*p == '\0');
-	entry = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
-				    &aoe_debugfs_fops);
-	if (IS_ERR_OR_NULL(entry)) {
-		pr_info("aoe: cannot create debugfs file for %s\n",
-			d->gd->disk_name);
-		return;
-	}
-	BUG_ON(d->debugfs);
-	d->debugfs = entry;
+	d->debugfs = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
+					 &aoe_debugfs_fops);
 }
 void
 aoedisk_rm_debugfs(struct aoedev *d)
@@ -472,10 +464,6 @@ aoeblk_init(void)
 	if (buf_pool_cache == NULL)
 		return -ENOMEM;
 	aoe_debugfs_dir = debugfs_create_dir("aoe", NULL);
-	if (IS_ERR_OR_NULL(aoe_debugfs_dir)) {
-		pr_info("aoe: cannot create debugfs directory\n");
-		aoe_debugfs_dir = NULL;
-	}
 	return 0;
 }
 
Signature · 1 line
2.21.0
#5 lore raw

PATCH v3 1/1 block: aoe: no need to check return value of debugfs_create functions

In reply to Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

Cc "Ed L. Cashin" <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Justin Sanders <[email protected]>

---
v3: Justin is now the maintainer of this driver, properly send it to
him.
v2: fix uninitialized entry issue found by Omar Sandoval

 drivers/block/aoe/aoeblk.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
drivers/block/aoe/aoeblk.c +2 -14
index e2c6aae2d636..bd19f8af950b 100644
@@ -196,7 +196,6 @@ static const struct file_operations aoe_debugfs_fops = {
 static void
 aoedisk_add_debugfs(struct aoedev *d)
 {
-	struct dentry *entry;
 	char *p;
 
 	if (aoe_debugfs_dir == NULL)
@@ -207,15 +206,8 @@ aoedisk_add_debugfs(struct aoedev *d)
 	else
 		p++;
 	BUG_ON(*p == '\0');
-	entry = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
-				    &aoe_debugfs_fops);
-	if (IS_ERR_OR_NULL(entry)) {
-		pr_info("aoe: cannot create debugfs file for %s\n",
-			d->gd->disk_name);
-		return;
-	}
-	BUG_ON(d->debugfs);
-	d->debugfs = entry;
+	d->debugfs = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
+					 &aoe_debugfs_fops);
 }
 void
 aoedisk_rm_debugfs(struct aoedev *d)
@@ -472,10 +464,6 @@ aoeblk_init(void)
 	if (buf_pool_cache == NULL)
 		return -ENOMEM;
 	aoe_debugfs_dir = debugfs_create_dir("aoe", NULL);
-	if (IS_ERR_OR_NULL(aoe_debugfs_dir)) {
-		pr_info("aoe: cannot create debugfs directory\n");
-		aoe_debugfs_dir = NULL;
-	}
 	return 0;
 }
 
Signature · 1 line
2.21.0
maintainer Acked-by on v3 1/1
#6 lore raw

Hi,

Quoted 65 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

Cc "Ed L. Cashin" <[email protected]>
Cc Jens Axboe <[email protected]>
Cc Omar Sandoval <[email protected]>
Cc Justin Sanders <[email protected]>

---
v3: Justin is now the maintainer of this driver, properly send it to
him.
v2: fix uninitialized entry issue found by Omar Sandoval

drivers/block/aoe/aoeblk.c | 16 ++--------------

1 file changed, 2 insertions(+), 14 deletions(-)
drivers/block/aoe/aoeblk.c +0 -0
index e2c6aae2d636..bd19f8af950b 100644
@@ -196,7 +196,6 @@ static const struct file_operations aoe_debugfs_fops = {

static void
aoedisk_add_debugfs(struct aoedev *d)
{

drivers/block/aoe/aoeblk.c +0 -1
-	struct dentry *entry;
	char *p;

	if (aoe_debugfs_dir == NULL)
drivers/block/aoe/aoeblk.c +2 -9
@@ -207,15 +206,8 @@ aoedisk_add_debugfs(struct aoedev *d)
 	else
 		p++;
 	BUG_ON(*p == '\0');
-	entry = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
-				    &aoe_debugfs_fops);
-	if (IS_ERR_OR_NULL(entry)) {
-		pr_info("aoe: cannot create debugfs file for %s\n",
-			d->gd->disk_name);
-		return;
-	}
-	BUG_ON(d->debugfs);
-	d->debugfs = entry;
+	d->debugfs = debugfs_create_file(p, 0444, aoe_debugfs_dir, d,
+					 &aoe_debugfs_fops);
 }

void
aoedisk_rm_debugfs(struct aoedev *d)

drivers/block/aoe/aoeblk.c +0 -4
@@ -472,10 +464,6 @@ aoeblk_init(void)
 	if (buf_pool_cache == NULL)
 		return -ENOMEM;
 	aoe_debugfs_dir = debugfs_create_dir("aoe", NULL);
-	if (IS_ERR_OR_NULL(aoe_debugfs_dir)) {
-		pr_info("aoe: cannot create debugfs directory\n");
-		aoe_debugfs_dir = NULL;
-	}
 	return 0;
 }
 
Signature · 1 line
2.21.0

This looks good to me, thanks.

Cheers,
Justin

maintainer Applied
#7 lore raw
In reply to Greg Kroah-Hartman
Quoted 3 lines · Greg Kroah-Hartman

When calling debugfs functions, there is no need to ever check the return value. The function can work or not, but the code logic should never do something different based on this.

Applied, thanks.

Signature · 1 line
Jens Axboe