From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] [v4, 5/6] syscalls/sysfs: Convert sysfs05 to the new API
Date: Fri, 13 Aug 2021 14:45:54 +0200 [thread overview]
Message-ID: <YRZpgsgh2N2csZ9s@yuki> (raw)
In-Reply-To: <20210813033507.18781-1-sujiaxun@uniontech.com>
Hi!
Pushed with a few changes, thanks.
The main change is that we do pass a valid buffer for the cases where
option != 1. That is because the order of checks in kernel is not
guaranteed. So if we pass bad_address as well as invalid index the
kernel can return either one of EINVAL or EFAULT. If we want to get
specific error we have to make sure that all parameters but one are
correct.
Also while strictly not an error LKML coding style prefers curly braces
around multiline blocks even if they are a single function.
Full diff:
diff --git a/testcases/kernel/syscalls/sysfs/sysfs05.c b/testcases/kernel/syscalls/sysfs/sysfs05.c
index 3586453cf..bfcead7db 100644
--- a/testcases/kernel/syscalls/sysfs/sysfs05.c
+++ b/testcases/kernel/syscalls/sysfs/sysfs05.c
@@ -5,6 +5,7 @@
/*\
* [Description]
+ *
* This test case checks whether sysfs(2) system call returns appropriate
* error number for invalid option and for invalid filesystem name and fs index out of bounds.
*/
@@ -12,8 +13,6 @@
#include "tst_test.h"
#include "lapi/syscalls.h"
-static char *bad_addr;
-
static struct test_case {
int option;
char *fsname;
@@ -22,27 +21,29 @@ static struct test_case {
int exp_errno;
} tcases[] = {
{1, "ext0", 0, "Invalid filesystem name", EINVAL},
- {4, "ext4", 0, "Invalid option", EINVAL},
- {1, (char *)-1, 0, "Address is out of your address space", EFAULT},
+ {4, NULL, 0, "Invalid option", EINVAL},
+ {1, NULL, 0, "Address is out of your address space", EFAULT},
{2, NULL, 1000, "fs_index is out of bounds", EINVAL}
};
static void verify_sysfs05(unsigned int nr)
{
struct test_case *tc = &tcases[nr];
+ char buf[1024];
- if (tc->option == 1)
+ if (tc->option == 1) {
TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsname),
tc->exp_errno, "%s", tc->err_desc);
- else
- TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsindex, bad_addr),
+ } else {
+ TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsindex, buf),
tc->exp_errno, "%s", tc->err_desc);
-
+ }
}
static void setup(void)
{
unsigned int i;
+ char *bad_addr;
bad_addr = tst_get_bad_addr(NULL);
--
Cyril Hrubis
chrubis@suse.cz
prev parent reply other threads:[~2021-08-13 12:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-13 3:35 [LTP] [PATCH] [v4, 5/6] syscalls/sysfs: Convert sysfs05 to the new API sujiaxun
2021-08-13 12:45 ` Cyril Hrubis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YRZpgsgh2N2csZ9s@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox