Skip to contentSkip to conversation

coresight: cpu-debug: no need to check return value of debugfs_create functions

PATCH In review Greg Kroah-Hartman 2 participants 6 messages Jun 18, 2019 – Jun 19, 2019

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

PATCH 1/1 coresight: cpu-debug: 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.

Cc Mathieu Poirier <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Alexander Shishkin <[email protected]>
---
 drivers/hwtracing/coresight/coresight-cpu-debug.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -13
index e8819d750938..6446ed69ab2f 100644
@@ -525,23 +525,12 @@ static const struct file_operations debug_func_knob_fops = {
 
 static int debug_func_init(void)
 {
-	struct dentry *file;
 	int ret;
 
 	/* Create debugfs node */
 	debug_debugfs_dir = debugfs_create_dir("coresight_cpu_debug", NULL);
-	if (!debug_debugfs_dir) {
-		pr_err("%s: unable to create debugfs directory\n", __func__);
-		return -ENOMEM;
-	}
-
-	file = debugfs_create_file("enable", 0644, debug_debugfs_dir, NULL,
-				   &debug_func_knob_fops);
-	if (!file) {
-		pr_err("%s: unable to create enable knob file\n", __func__);
-		ret = -ENOMEM;
-		goto err;
-	}
+	debugfs_create_file("enable", 0644, debug_debugfs_dir, NULL,
+			    &debug_func_knob_fops);
 
 	/* Register function to be called for panic */
 	ret = atomic_notifier_chain_register(&panic_notifier_list,
Signature · 7 lines
2.22.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#1 lore raw

Hi Greg,

Quoted 4 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.

Looking around in the kernel there is no shortage of instances where the return value of debugfs functions are checked and the logic altered based on these values. But there are also just as many that don't... It also seems counter intuitive to ignore the return value of any function, something that in most case is guaranteed to raise admonition.

That being said I am sure there is a good reason to support your position - would you mind expanding a little so that I can follow?

Thanks,
Mathieu

Quoted 41 lines
Cc Mathieu Poirier <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Alexander Shishkin <[email protected]>
---
 drivers/hwtracing/coresight/coresight-cpu-debug.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/hwtracing/coresight/coresight-cpu-debug.c +2 -14
index e8819d750938..6446ed69ab2f 100644
@@ -525,23 +525,12 @@ static const struct file_operations debug_func_knob_fops = {
 
 static int debug_func_init(void)
 {
-       struct dentry *file;
        int ret;
 
        /* Create debugfs node */
        debug_debugfs_dir = debugfs_create_dir("coresight_cpu_debug", NULL);
-       if (!debug_debugfs_dir) {
-               pr_err("%s: unable to create debugfs directory\n", __func__);
-               return -ENOMEM;
-       }
-
-       file = debugfs_create_file("enable", 0644, debug_debugfs_dir, NULL,
-                                  &debug_func_knob_fops);
-       if (!file) {
-               pr_err("%s: unable to create enable knob file\n", __func__);
-               ret = -ENOMEM;
-               goto err;
-       }
+       debugfs_create_file("enable", 0644, debug_debugfs_dir, NULL,
+                           &debug_func_knob_fops);
 
        /* Register function to be called for panic */
        ret = atomic_notifier_chain_register(&panic_notifier_list,
--
Quoted 2 lines

2.22.0

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#2 lore raw
Quoted 9 lines · Mathieu Poirier

Hi Greg,

Quoted 4 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.

Quoted 6 lines

Looking around in the kernel there is no shortage of instances where the return value of debugfs functions are checked and the logic altered based on these values. But there are also just as many that don't... It also seems counter intuitive to ignore the return value of any function, something that in most case is guaranteed to raise admonition.

In my tree, those instances are almost all gone. I've also posted over 100+ patches in the past few weeks to clean this up.

Quoted 2 lines

That being said I am sure there is a good reason to support your position - would you mind expanding a little so that I can follow?

No kernel code should ever care if debugfs works or not. No user code should ever require it for normal operation either. debugfs was written to be simple and easy to use, no need to check any return values at all.

Any return value of a debugfs call can be fed back into another call with no issues at all.

Also, due to some debugfs core changes a few kernel releases ago, the checks:

	if (!debug_debugfs_dir) {
...
	if (!file) {

can never trigger as debugfs_create_dir() or debugfs_create_file() can never return NULL (and in the past, it almost never would either). So as it is, that code isn't correct anyway (my fault, I know, hey, I'm trying to fix it!)

I'm trying to make things simple, and easy, and impossible to get wrong. I know it goes against the normal "robust" kernel development mentality, but there is no need to ever care about debugfs at all.

The reason I started all of this is that we have found places where userspace, and the kernel, was depending on the proper operation of debugfs. In one horrid example, a device would not display the batter level if debugfs was disabled. In another case, the kernel was actually relying on a debugfs call to fail in order to handle some logic the subsystem should have been doing on its own. All of that has now been cleaned up, and I am working on making debugfs just not return any values at all to prevent this type of mess happening again.

And hey, I am removing code, here's my current tree as a diff from what is not already merged into linux-next:

	 301 files changed, 1394 insertions(+), 4637 deletions(-)

that's always a good thing :)

Hopefully this helps explain things better.

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw
Quoted 53 lines · Greg Kroah-Hartman
Quoted 9 lines · Mathieu Poirier

Hi Greg,

Quoted 4 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.

Quoted 6 lines

Looking around in the kernel there is no shortage of instances where the return value of debugfs functions are checked and the logic altered based on these values. But there are also just as many that don't... It also seems counter intuitive to ignore the return value of any function, something that in most case is guaranteed to raise admonition.

In my tree, those instances are almost all gone. I've also posted over 100+ patches in the past few weeks to clean this up.

Quoted 2 lines

That being said I am sure there is a good reason to support your position - would you mind expanding a little so that I can follow?

No kernel code should ever care if debugfs works or not. No user code should ever require it for normal operation either. debugfs was written to be simple and easy to use, no need to check any return values at all.

Any return value of a debugfs call can be fed back into another call with no issues at all.

Also, due to some debugfs core changes a few kernel releases ago, the checks:

	if (!debug_debugfs_dir) {
...
	if (!file) {

can never trigger as debugfs_create_dir() or debugfs_create_file() can never return NULL (and in the past, it almost never would either). So as it is, that code isn't correct anyway (my fault, I know, hey, I'm trying to fix it!)

I'm trying to make things simple, and easy, and impossible to get wrong. I know it goes against the normal "robust" kernel development mentality, but there is no need to ever care about debugfs at all.

The reason I started all of this is that we have found places where userspace, and the kernel, was depending on the proper operation of debugfs. In one horrid example, a device would not display the batter level if debugfs was disabled. In another case, the kernel was actually relying on a debugfs call to fail in order to handle some logic the subsystem should have been doing on its own. All of that has now been cleaned up, and I am working on making debugfs just not return any values at all to prevent this type of mess happening again.

Quoted 4 lines

And hey, I am removing code, here's my current tree as a diff from what is not already merged into linux-next:

	 301 files changed, 1394 insertions(+), 4637 deletions(-)

that's always a good thing :)

Oh, forgot the pointer to the tree:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git/log/?h=debugfs_cleanup
this is all public, just not in linux-next as it's being fed through 50+ different subsystem trees.

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by Tested-by
#4 lore raw
In reply to Greg Kroah-Hartman
Quoted 31 lines · Greg Kroah-Hartman
Quoted 9 lines · Mathieu Poirier

Hi Greg,

Quoted 4 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.

Quoted 6 lines

Looking around in the kernel there is no shortage of instances where the return value of debugfs functions are checked and the logic altered based on these values. But there are also just as many that don't... It also seems counter intuitive to ignore the return value of any function, something that in most case is guaranteed to raise admonition.

In my tree, those instances are almost all gone. I've also posted over 100+ patches in the past few weeks to clean this up.

Quoted 2 lines

That being said I am sure there is a good reason to support your position - would you mind expanding a little so that I can follow?

No kernel code should ever care if debugfs works or not. No user code should ever require it for normal operation either. debugfs was written to be simple and easy to use, no need to check any return values at all.

Any return value of a debugfs call can be fed back into another call with no issues at all.

Quoted 7 lines

Also, due to some debugfs core changes a few kernel releases ago, the checks:

        if (!debug_debugfs_dir) {
...
        if (!file) {

can never trigger as debugfs_create_dir() or debugfs_create_file() can never return NULL (and in the past, it almost never would either). So

That is the rational I was looking for.

Quoted 16 lines

as it is, that code isn't correct anyway (my fault, I know, hey, I'm trying to fix it!)

I'm trying to make things simple, and easy, and impossible to get wrong. I know it goes against the normal "robust" kernel development mentality, but there is no need to ever care about debugfs at all.

The reason I started all of this is that we have found places where userspace, and the kernel, was depending on the proper operation of debugfs. In one horrid example, a device would not display the batter level if debugfs was disabled. In another case, the kernel was actually relying on a debugfs call to fail in order to handle some logic the subsystem should have been doing on its own. All of that has now been cleaned up, and I am working on making debugfs just not return any values at all to prevent this type of mess happening again.

Quoted 6 lines

And hey, I am removing code, here's my current tree as a diff from what is not already merged into linux-next:

         301 files changed, 1394 insertions(+), 4637 deletions(-)

that's always a good thing :)

Hopefully this helps explain things better.

It does - thanks for taking the time to write all this.

Do you want me to take the patch through my tree (only to see it coming back to you later this week) or you'll add it directly to yours? In the latter case:

Regards,
Mathieu

Quoted 4 lines

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw
Quoted 66 lines · Mathieu Poirier
Quoted 31 lines · Greg Kroah-Hartman
Quoted 9 lines · Mathieu Poirier

Hi Greg,

Quoted 4 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.

Quoted 6 lines

Looking around in the kernel there is no shortage of instances where the return value of debugfs functions are checked and the logic altered based on these values. But there are also just as many that don't... It also seems counter intuitive to ignore the return value of any function, something that in most case is guaranteed to raise admonition.

In my tree, those instances are almost all gone. I've also posted over 100+ patches in the past few weeks to clean this up.

Quoted 2 lines

That being said I am sure there is a good reason to support your position - would you mind expanding a little so that I can follow?

No kernel code should ever care if debugfs works or not. No user code should ever require it for normal operation either. debugfs was written to be simple and easy to use, no need to check any return values at all.

Any return value of a debugfs call can be fed back into another call with no issues at all.

Quoted 7 lines

Also, due to some debugfs core changes a few kernel releases ago, the checks:

        if (!debug_debugfs_dir) {
...
        if (!file) {

can never trigger as debugfs_create_dir() or debugfs_create_file() can never return NULL (and in the past, it almost never would either). So

That is the rational I was looking for.

Quoted 16 lines

as it is, that code isn't correct anyway (my fault, I know, hey, I'm trying to fix it!)

I'm trying to make things simple, and easy, and impossible to get wrong. I know it goes against the normal "robust" kernel development mentality, but there is no need to ever care about debugfs at all.

The reason I started all of this is that we have found places where userspace, and the kernel, was depending on the proper operation of debugfs. In one horrid example, a device would not display the batter level if debugfs was disabled. In another case, the kernel was actually relying on a debugfs call to fail in order to handle some logic the subsystem should have been doing on its own. All of that has now been cleaned up, and I am working on making debugfs just not return any values at all to prevent this type of mess happening again.

Quoted 6 lines

And hey, I am removing code, here's my current tree as a diff from what is not already merged into linux-next:

         301 files changed, 1394 insertions(+), 4637 deletions(-)

that's always a good thing :)

Hopefully this helps explain things better.

Quoted 8 lines

It does - thanks for taking the time to write all this.

Do you want me to take the patch through my tree (only to see it coming back to you later this week) or you'll add it directly to yours? In the latter case:

I can just take it directly, thanks!

greg k-h

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel