2023-05-13 14:47:08

by Immad Mir

[permalink] [raw]
Subject: [PATCH] loongarch: fix debugfs_create_dir error checking

From: Immad Mir <[email protected]>

The debugfs_create_dir returns ERR_PTR incase of an error and the
correct way of checking it by using the IS_ERR inline function, and
not the simple null comparision. This patch fixes this.

Suggested-By: Ivan Orlov <[email protected]>
Signed-off-by: Immad Mir <[email protected]>
---
arch/loongarch/kernel/unaligned.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/kernel/unaligned.c b/arch/loongarch/kernel/unaligned.c
index bdff825d2..be2a5bdc5 100644
--- a/arch/loongarch/kernel/unaligned.c
+++ b/arch/loongarch/kernel/unaligned.c
@@ -485,7 +485,7 @@ static int __init debugfs_unaligned(void)
struct dentry *d;

d = debugfs_create_dir("loongarch", NULL);
- if (!d)
+ if (IS_ERR(d))
return -ENOMEM;

debugfs_create_u32("unaligned_instructions_user",
--
2.40.0



2023-05-14 03:45:29

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH] loongarch: fix debugfs_create_dir error checking

Hi, Immad,

On Sat, May 13, 2023 at 10:46 PM <[email protected]> wrote:
>
> From: Immad Mir <[email protected]>
>
> The debugfs_create_dir returns ERR_PTR incase of an error and the
> correct way of checking it by using the IS_ERR inline function, and
> not the simple null comparision. This patch fixes this.
>
> Suggested-By: Ivan Orlov <[email protected]>
> Signed-off-by: Immad Mir <[email protected]>
> ---
> arch/loongarch/kernel/unaligned.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kernel/unaligned.c b/arch/loongarch/kernel/unaligned.c
> index bdff825d2..be2a5bdc5 100644
> --- a/arch/loongarch/kernel/unaligned.c
> +++ b/arch/loongarch/kernel/unaligned.c
> @@ -485,7 +485,7 @@ static int __init debugfs_unaligned(void)
> struct dentry *d;
>
> d = debugfs_create_dir("loongarch", NULL);
> - if (!d)
> + if (IS_ERR(d))
Maybe we need IS_ERR_OR_NULL() here?

Huacai
> return -ENOMEM;
>
> debugfs_create_u32("unaligned_instructions_user",
> --
> 2.40.0
>

2023-05-14 07:24:19

by Immad Mir

[permalink] [raw]
Subject: [PATCH v2] loongarch: fix debugfs_create_dir error checking

From: Immad Mir <[email protected]>

The debugfs_create_dir returns ERR_PTR incase of an error and the
correct way of checking it by using the IS_ERR_OR_NULL inline function, and
not the simple null comparision. This patch fixes this.

Suggested-By: Ivan Orlov <[email protected]>
Signed-off-by: Immad Mir <[email protected]>
---
arch/loongarch/kernel/unaligned.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/loongarch/kernel/unaligned.c b/arch/loongarch/kernel/unaligned.c
index bdff825d2..85fae3d2d 100644
--- a/arch/loongarch/kernel/unaligned.c
+++ b/arch/loongarch/kernel/unaligned.c
@@ -485,7 +485,7 @@ static int __init debugfs_unaligned(void)
struct dentry *d;

d = debugfs_create_dir("loongarch", NULL);
- if (!d)
+ if (IS_ERR_OR_NULL(d))
return -ENOMEM;

debugfs_create_u32("unaligned_instructions_user",
--
2.40.0


2023-05-16 02:32:06

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH v2] loongarch: fix debugfs_create_dir error checking

Queued, thanks.

Huacai

On Sun, May 14, 2023 at 2:44 PM <[email protected]> wrote:
>
> From: Immad Mir <[email protected]>
>
> The debugfs_create_dir returns ERR_PTR incase of an error and the
> correct way of checking it by using the IS_ERR_OR_NULL inline function, and
> not the simple null comparision. This patch fixes this.
>
> Suggested-By: Ivan Orlov <[email protected]>
> Signed-off-by: Immad Mir <[email protected]>
> ---
> arch/loongarch/kernel/unaligned.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kernel/unaligned.c b/arch/loongarch/kernel/unaligned.c
> index bdff825d2..85fae3d2d 100644
> --- a/arch/loongarch/kernel/unaligned.c
> +++ b/arch/loongarch/kernel/unaligned.c
> @@ -485,7 +485,7 @@ static int __init debugfs_unaligned(void)
> struct dentry *d;
>
> d = debugfs_create_dir("loongarch", NULL);
> - if (!d)
> + if (IS_ERR_OR_NULL(d))
> return -ENOMEM;
>
> debugfs_create_u32("unaligned_instructions_user",
> --
> 2.40.0
>