[PATCH] lib: error-inject: fix error check for debugfs_create_file()

Yi Yang posted 1 patch 2 years, 3 months ago
lib/error-inject.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] lib: error-inject: fix error check for debugfs_create_file()
Posted by Yi Yang 2 years, 3 months ago
The debugfs_create_file() function returns error pointers, it never
returns NULL, we need to check the return value correctly to avoid
debugfs_remove() is not called.

Fixes: 540adea3809f ("error-injection: Separate error-injection from kprobe")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
---
 lib/error-inject.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/error-inject.c b/lib/error-inject.c
index 887acd9a6ea6..8bcdea5229eb 100644
--- a/lib/error-inject.c
+++ b/lib/error-inject.c
@@ -219,7 +219,7 @@ static int __init ei_debugfs_init(void)
 	dir = debugfs_create_dir("error_injection", NULL);
 
 	file = debugfs_create_file("list", 0444, dir, NULL, &ei_fops);
-	if (!file) {
+	if (IS_ERR(file)) {
 		debugfs_remove(dir);
 		return -ENOMEM;
 	}
-- 
2.17.1
Re: [PATCH] lib: error-inject: fix error check for debugfs_create_file()
Posted by Greg KH 2 years, 3 months ago
On Thu, Aug 31, 2023 at 03:56:53PM +0800, Yi Yang wrote:
> The debugfs_create_file() function returns error pointers, it never
> returns NULL, we need to check the return value correctly to avoid
> debugfs_remove() is not called.
> 
> Fixes: 540adea3809f ("error-injection: Separate error-injection from kprobe")
> Signed-off-by: Yi Yang <yiyang13@huawei.com>
> ---
>  lib/error-inject.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/lib/error-inject.c b/lib/error-inject.c
> index 887acd9a6ea6..8bcdea5229eb 100644
> --- a/lib/error-inject.c
> +++ b/lib/error-inject.c
> @@ -219,7 +219,7 @@ static int __init ei_debugfs_init(void)
>  	dir = debugfs_create_dir("error_injection", NULL);
>  
>  	file = debugfs_create_file("list", 0444, dir, NULL, &ei_fops);
> -	if (!file) {
> +	if (IS_ERR(file)) {

As it is obvious this check has never failed, please just don't check
this at all, it's fine to never check the return value of this function.

thanks,

greg k-h