Skip to contentSkip to conversation

hid-wiimote-debug.c: Fix error checking for debugfs_create_file

PATCH Superseded Osama Muhammad 2 participants 3 messages May 23, 2023 – May 30, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hid-wiimote-debug.c: Fix error checking for debugfs_create_file

This patch fixes the error checking in hid-wiimote-debug.c in debugfs_create_file. The correct way to check if an error occurred is 'IS_ERR' inline function.

---
 drivers/hid/hid-wiimote-debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-wiimote-debug.c +2 -2
index a99dcca2e099..eddd981fee1a 100644
@@ -183,12 +183,12 @@ int wiidebug_init(struct wiimote_data *wdata)
 
 	dbg->eeprom = debugfs_create_file("eeprom", S_IRUSR,
 		dbg->wdata->hdev->debug_dir, dbg, &wiidebug_eeprom_fops);
-	if (!dbg->eeprom)
+	if (IS_ERR(dbg->eeprom))
 		goto err;
 
 	dbg->drm = debugfs_create_file("drm", S_IRUSR,
 			dbg->wdata->hdev->debug_dir, dbg, &wiidebug_drm_fops);
-	if (!dbg->drm)
+	if (IS_ERR(dbg->drm))
 		goto err_drm;
 
 	spin_lock_irqsave(&wdata->state.lock, flags);
Signature · 1 line
2.34.1
#1 lore raw

Hi

Quoted 4 lines · Osama Muhammad

This patch fixes the error checking in hid-wiimote-debug.c in debugfs_create_file. The correct way to check if an error occurred is 'IS_ERR' inline function.

Please have a look at fs/debugfs/inode.c, especiall the docs of debugfs_create_file():

477 * NOTE: it's expected that most callers should _ignore_ the errors returned 478 * by this function. Other debugfs functions handle the fact that the "dentry"
479 * passed to them could be an error and they don't crash in that case. 480 * Drivers should generally work fine even if debugfs fails to init anyway.

I think the current code is fine. If you feel like adjusting it, I would rather just remove the NULL-check.

Thanks
David

Quoted 27 lines
---
 drivers/hid/hid-wiimote-debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-wiimote-debug.c +2 -3
index a99dcca2e099..eddd981fee1a 100644
@@ -183,12 +183,12 @@ int wiidebug_init(struct wiimote_data *wdata)
 
        dbg->eeprom = debugfs_create_file("eeprom", S_IRUSR,
                dbg->wdata->hdev->debug_dir, dbg, &wiidebug_eeprom_fops);
-       if (!dbg->eeprom)
+       if (IS_ERR(dbg->eeprom))
                goto err;
 
        dbg->drm = debugfs_create_file("drm", S_IRUSR,
                        dbg->wdata->hdev->debug_dir, dbg, &wiidebug_drm_fops);
-       if (!dbg->drm)
+       if (IS_ERR(dbg->drm))
                goto err_drm;
 
        spin_lock_irqsave(&wdata->state.lock, flags);
--

2.34.1

#2 lore raw

Hi,

I will adjust it by sending the revision of the patch by removing NULL-check.

Thanks,
Osmten

Quoted 51 lines · David Rheinsberg

Hi

Quoted 4 lines · Osama Muhammad

This patch fixes the error checking in hid-wiimote-debug.c in debugfs_create_file. The correct way to check if an error occurred is 'IS_ERR' inline function.

Please have a look at fs/debugfs/inode.c, especiall the docs of debugfs_create_file():

477 * NOTE: it's expected that most callers should _ignore_ the errors returned 478 * by this function. Other debugfs functions handle the fact that the "dentry"
479 * passed to them could be an error and they don't crash in that case. 480 * Drivers should generally work fine even if debugfs fails to init anyway.

I think the current code is fine. If you feel like adjusting it, I would rather just remove the NULL-check.

Thanks
David

Quoted 27 lines
---
 drivers/hid/hid-wiimote-debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hid/hid-wiimote-debug.c +2 -3
index a99dcca2e099..eddd981fee1a 100644
@@ -183,12 +183,12 @@ int wiidebug_init(struct wiimote_data *wdata)
 
        dbg->eeprom = debugfs_create_file("eeprom", S_IRUSR,
                dbg->wdata->hdev->debug_dir, dbg, &wiidebug_eeprom_fops);
-       if (!dbg->eeprom)
+       if (IS_ERR(dbg->eeprom))
                goto err;
 
        dbg->drm = debugfs_create_file("drm", S_IRUSR,
                        dbg->wdata->hdev->debug_dir, dbg, &wiidebug_drm_fops);
-       if (!dbg->drm)
+       if (IS_ERR(dbg->drm))
                goto err_drm;
 
        spin_lock_irqsave(&wdata->state.lock, flags);
--

2.34.1