[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <6916d710-9cfb-bea5-9464-4c2d8aa140f2@roeck-us.net>
Date: Thu, 23 Jul 2020 19:12:09 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: Tiezhu Yang <yangtiezhu@...ngson.cn>,
Andrew Morton <akpm@...ux-foundation.org>,
Konstantin Khlebnikov <khlebnikov@...dex-team.ru>,
Kees Cook <keescook@...omium.org>
Cc: linux-kernel@...r.kernel.org, Xuefeng Li <lixuefeng@...ngson.cn>
Subject: Re: [PATCH 2/2] lib/test_lockup.c: Fix return value of
test_lockup_init()
On 7/23/20 6:50 PM, Tiezhu Yang wrote:
> Since filp_open() returns an error pointer, we should use IS_ERR() to
> check the return value and then return PTR_ERR() if failed to get the
> actual return value instead of always -EINVAL.
>
> E.g. without this patch:
>
> [root@...alhost loongson]# ls no_such_file
> ls: cannot access no_such_file: No such file or directory
> [root@...alhost loongson]# modprobe test_lockup file_path=no_such_file lock_sb_umount time_secs=60 state=S
> modprobe: ERROR: could not insert 'test_lockup': Invalid argument
> [root@...alhost loongson]# dmesg | tail -1
> [ 126.100596] test_lockup: cannot find file_path
>
> With this patch:
>
> [root@...alhost loongson]# ls no_such_file
> ls: cannot access no_such_file: No such file or directory
> [root@...alhost loongson]# modprobe test_lockup file_path=no_such_file lock_sb_umount time_secs=60 state=S
> modprobe: ERROR: could not insert 'test_lockup': Unknown symbol in module, or unknown parameter (see dmesg)
> [root@...alhost loongson]# dmesg | tail -1
> [ 95.134362] test_lockup: failed to open no_such_file: -2
>
> Fixes: aecd42df6d39 ("lib/test_lockup.c: add parameters for locking generic vfs locks")
> Signed-off-by: Tiezhu Yang <yangtiezhu@...ngson.cn>
Reviewed-by: Guenter Roeck <linux@...ck-us.net>
> ---
> lib/test_lockup.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/test_lockup.c b/lib/test_lockup.c
> index bd7c7ff..e720276 100644
> --- a/lib/test_lockup.c
> +++ b/lib/test_lockup.c
> @@ -512,8 +512,8 @@ static int __init test_lockup_init(void)
> if (test_file_path[0]) {
> test_file = filp_open(test_file_path, O_RDONLY, 0);
> if (IS_ERR(test_file)) {
> - pr_err("cannot find file_path\n");
> - return -EINVAL;
> + pr_err("failed to open %s: %ld\n", test_file_path, PTR_ERR(test_file));
> + return PTR_ERR(test_file);
> }
> test_inode = file_inode(test_file);
> } else if (test_lock_inode ||
>
Powered by blists - more mailing lists