2023-05-30 15:51:36

by Osama Muhammad

[permalink] [raw]
Subject: [PATCH v2] hid-wiimote-debug.c: Drop error checking for debugfs_create_file

This patch removes the error checking for debugfs_create_file
in hid-wiimote-debug.c.c. This is because the debugfs_create_file()
does not return NULL but an ERR_PTR after an error.
The DebugFS kernel API is developed in a way that the
caller can safely ignore the errors that occur during
the creation of DebugFS nodes.The debugfs Api handles
it gracefully. The check is unnecessary.

Link to the comment above debugfs_create_file:
https://elixir.bootlin.com/linux/latest/source/fs/debugfs/inode.c#L451

Signed-off-by: Osama Muhammad <[email protected]>

---
changes since v1
-In v1 the IS_ERR was used for error checking which is dropped now.
---
drivers/hid/hid-wiimote-debug.c | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
index a99dcca2e099..00f9be55f148 100644
--- a/drivers/hid/hid-wiimote-debug.c
+++ b/drivers/hid/hid-wiimote-debug.c
@@ -173,7 +173,6 @@ int wiidebug_init(struct wiimote_data *wdata)
{
struct wiimote_debug *dbg;
unsigned long flags;
- int ret = -ENOMEM;

dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
if (!dbg)
@@ -183,13 +182,9 @@ 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)
- goto err;

dbg->drm = debugfs_create_file("drm", S_IRUSR,
dbg->wdata->hdev->debug_dir, dbg, &wiidebug_drm_fops);
- if (!dbg->drm)
- goto err_drm;

spin_lock_irqsave(&wdata->state.lock, flags);
wdata->debug = dbg;
@@ -197,11 +192,6 @@ int wiidebug_init(struct wiimote_data *wdata)

return 0;

-err_drm:
- debugfs_remove(dbg->eeprom);
-err:
- kfree(dbg);
- return ret;
}

void wiidebug_deinit(struct wiimote_data *wdata)
--
2.34.1



2023-05-31 06:51:00

by David Rheinsberg

[permalink] [raw]
Subject: Re: [PATCH v2] hid-wiimote-debug.c: Drop error checking for debugfs_create_file

Hi

On Tue, 30 May 2023 at 17:43, Osama Muhammad <[email protected]> wrote:
>
> This patch removes the error checking for debugfs_create_file
> in hid-wiimote-debug.c.c. This is because the debugfs_create_file()
> does not return NULL but an ERR_PTR after an error.
> The DebugFS kernel API is developed in a way that the
> caller can safely ignore the errors that occur during
> the creation of DebugFS nodes.The debugfs Api handles
> it gracefully. The check is unnecessary.
>
> Link to the comment above debugfs_create_file:
> https://elixir.bootlin.com/linux/latest/source/fs/debugfs/inode.c#L451
>
> Signed-off-by: Osama Muhammad <[email protected]>

Looks good, thanks!

Reviewed-by: David Rheinsberg <[email protected]>

Thanks
David

> ---
> changes since v1
> -In v1 the IS_ERR was used for error checking which is dropped now.
> ---
> drivers/hid/hid-wiimote-debug.c | 10 ----------
> 1 file changed, 10 deletions(-)
>
> diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
> index a99dcca2e099..00f9be55f148 100644
> --- a/drivers/hid/hid-wiimote-debug.c
> +++ b/drivers/hid/hid-wiimote-debug.c
> @@ -173,7 +173,6 @@ int wiidebug_init(struct wiimote_data *wdata)
> {
> struct wiimote_debug *dbg;
> unsigned long flags;
> - int ret = -ENOMEM;
>
> dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
> if (!dbg)
> @@ -183,13 +182,9 @@ 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)
> - goto err;
>
> dbg->drm = debugfs_create_file("drm", S_IRUSR,
> dbg->wdata->hdev->debug_dir, dbg, &wiidebug_drm_fops);
> - if (!dbg->drm)
> - goto err_drm;
>
> spin_lock_irqsave(&wdata->state.lock, flags);
> wdata->debug = dbg;
> @@ -197,11 +192,6 @@ int wiidebug_init(struct wiimote_data *wdata)
>
> return 0;
>
> -err_drm:
> - debugfs_remove(dbg->eeprom);
> -err:
> - kfree(dbg);
> - return ret;
> }
>
> void wiidebug_deinit(struct wiimote_data *wdata)
> --
> 2.34.1
>

2023-08-14 09:43:44

by Jiri Kosina

[permalink] [raw]
Subject: Re: [PATCH v2] hid-wiimote-debug.c: Drop error checking for debugfs_create_file

On Tue, 30 May 2023, Osama Muhammad wrote:

> This patch removes the error checking for debugfs_create_file
> in hid-wiimote-debug.c.c. This is because the debugfs_create_file()
> does not return NULL but an ERR_PTR after an error.
> The DebugFS kernel API is developed in a way that the
> caller can safely ignore the errors that occur during
> the creation of DebugFS nodes.The debugfs Api handles
> it gracefully. The check is unnecessary.
>
> Link to the comment above debugfs_create_file:
> https://elixir.bootlin.com/linux/latest/source/fs/debugfs/inode.c#L451
>
> Signed-off-by: Osama Muhammad <[email protected]>
>
> ---
> changes since v1
> -In v1 the IS_ERR was used for error checking which is dropped now.

Now applied, sorry for the delay.

--
Jiri Kosina
SUSE Labs