Skip to contentSkip to conversation

malidp: no need to check return value of debugfs_create functions

PATCH In review Greg Kroah-Hartman 2 participants 6 messages Jun 13, 2019 – Jun 14, 2019

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

PATCH 1/1 malidp: 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 Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/arm/malidp_drv.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +2 -9
index 21725c9b9f5e..7d732423d70d 100644
@@ -542,19 +542,12 @@ static const struct file_operations malidp_debugfs_fops = {
 static int malidp_debugfs_init(struct drm_minor *minor)
 {
 	struct malidp_drm *malidp = minor->dev->dev_private;
-	struct dentry *dentry = NULL;
 
 	malidp_error_stats_init(&malidp->de_errors);
 	malidp_error_stats_init(&malidp->se_errors);
 	spin_lock_init(&malidp->errors_lock);
-	dentry = debugfs_create_file("debug",
-				     S_IRUGO | S_IWUSR,
-				     minor->debugfs_root, minor->dev,
-				     &malidp_debugfs_fops);
-	if (!dentry) {
-		DRM_ERROR("Cannot create debug file\n");
-		return -ENOMEM;
-	}
+	debugfs_create_file("debug", S_IRUGO | S_IWUSR, minor->debugfs_root,
+			    minor->dev, &malidp_debugfs_fops);
 	return 0;
 }
 
Signature · 6 lines
2.22.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer Acked-by on v1 1/1
#1 lore raw
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.

I remember when writing this code and testing not fully complete code that left nodes around on removing the module that there were errors being returned by debugfs_create_file(). Has that changed since 2 years ago? :)

Quoted 7 lines
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>

I'll pull it into the malidp tree.

Best regards,
Liviu

Quoted 33 lines
---
 drivers/gpu/drm/arm/malidp_drv.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +2 -9
index 21725c9b9f5e..7d732423d70d 100644
@@ -542,19 +542,12 @@ static const struct file_operations malidp_debugfs_fops = {
 static int malidp_debugfs_init(struct drm_minor *minor)
 {
 	struct malidp_drm *malidp = minor->dev->dev_private;
-	struct dentry *dentry = NULL;
 
 	malidp_error_stats_init(&malidp->de_errors);
 	malidp_error_stats_init(&malidp->se_errors);
 	spin_lock_init(&malidp->errors_lock);
-	dentry = debugfs_create_file("debug",
-				     S_IRUGO | S_IWUSR,
-				     minor->debugfs_root, minor->dev,
-				     &malidp_debugfs_fops);
-	if (!dentry) {
-		DRM_ERROR("Cannot create debug file\n");
-		return -ENOMEM;
-	}
+	debugfs_create_file("debug", S_IRUGO | S_IWUSR, minor->debugfs_root,
+			    minor->dev, &malidp_debugfs_fops);
 	return 0;
 }
 
Signature · 1 line
2.22.0
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw
Quoted 8 lines · Liviu Dudau
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.

I remember when writing this code and testing not fully complete code that left nodes around on removing the module that there were errors being returned by debugfs_create_file(). Has that changed since 2 years ago? :)

Errors can be returned if you do something foolish:
- pass an error as a parent pointer
- pass a name that is already present
or if the system is out of resources
- can not increment superblock reference
- out of memory to create an inode

If those last two things are happening, then your system is crashing already, debugfs is the least of your worries :)

Quoted 10 lines
Quoted 6 lines
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>

I'll pull it into the malidp tree.

Wonderful, thanks!

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#3 lore raw
Quoted 6 lines · Greg Kroah-Hartman
Quoted 5 lines · Liviu Dudau
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.

Quoted 7 lines
Quoted 3 lines

I remember when writing this code and testing not fully complete code that left nodes around on removing the module that there were errors being returned by debugfs_create_file(). Has that changed since 2 years ago? :)

Errors can be returned if you do something foolish:
- pass an error as a parent pointer
- pass a name that is already present

That is what I was hitting previously. If we follow the new advice of not checking for errors does this mean I can now start to hide debugfs entries by touching some debugfs files before modules get loaded?

Best regards,
Liviu

Quoted 21 lines

or if the system is out of resources
- can not increment superblock reference
- out of memory to create an inode

If those last two things are happening, then your system is crashing already, debugfs is the least of your worries :)

Quoted 10 lines
Quoted 6 lines
Cc Liviu Dudau <[email protected]>
Cc Brian Starkey <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>

I'll pull it into the malidp tree.

Wonderful, thanks!

greg k-h

Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
Quoted 11 lines · Liviu Dudau
Quoted 10 lines · Greg Kroah-Hartman
Quoted 8 lines · Liviu Dudau
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.

I remember when writing this code and testing not fully complete code that left nodes around on removing the module that there were errors being returned by debugfs_create_file(). Has that changed since 2 years ago? :)

Quoted 7 lines
Quoted 3 lines

Errors can be returned if you do something foolish:
- pass an error as a parent pointer
- pass a name that is already present

That is what I was hitting previously. If we follow the new advice of not checking for errors does this mean I can now start to hide debugfs entries by touching some debugfs files before modules get loaded?

How can you "touch" a debugfs file today?

And even if there is a duplicate debugfs file, you shouldn't care as your driver should keep going even if creation of it fails as no functionality of the code should ever rely on debugfs.

thanks,

greg k-h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#5 lore raw
Quoted 16 lines · Greg Kroah-Hartman
Quoted 15 lines · Liviu Dudau
Quoted 13 lines · Greg Kroah-Hartman
Quoted 8 lines · Liviu Dudau
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.

I remember when writing this code and testing not fully complete code that left nodes around on removing the module that there were errors being returned by debugfs_create_file(). Has that changed since 2 years ago? :)

Errors can be returned if you do something foolish:
- pass an error as a parent pointer
- pass a name that is already present

Quoted 5 lines
Quoted 3 lines

That is what I was hitting previously. If we follow the new advice of not checking for errors does this mean I can now start to hide debugfs entries by touching some debugfs files before modules get loaded?

How can you "touch" a debugfs file today?

Touché! Yes, last time it was through my sloppy coding :)

Quoted 4 lines

And even if there is a duplicate debugfs file, you shouldn't care as your driver should keep going even if creation of it fails as no functionality of the code should ever rely on debugfs.

Agree and understood. Thanks for taking the time to explain it to me!

Best regards,
Liviu

Quoted 4 lines

thanks,

greg k-h

Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel