All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 03/36] tree: keyctl: Use SAFE_ADD_KEY()
Date: Wed, 16 Sep 2026 16:03:29 +0200	[thread overview]
Message-ID: <20260916140402.1797325-4-pvorel@suse.cz> (raw)
In-Reply-To: <20260916140402.1797325-1-pvorel@suse.cz>

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 testcases/cve/cve-2016-7042.c                      |  4 +---
 testcases/kernel/syscalls/add_key/add_key03.c      |  9 ++-------
 testcases/kernel/syscalls/add_key/add_key04.c      | 14 ++++----------
 testcases/kernel/syscalls/keyctl/keyctl02.c        |  8 ++------
 testcases/kernel/syscalls/keyctl/keyctl03.c        |  4 +---
 testcases/kernel/syscalls/keyctl/keyctl06.c        |  6 ++----
 .../kernel/syscalls/request_key/request_key01.c    |  4 +---
 .../kernel/syscalls/request_key/request_key02.c    |  4 +---
 testcases/kernel/watchqueue/common.h               |  4 +---
 9 files changed, 15 insertions(+), 42 deletions(-)

diff --git a/testcases/cve/cve-2016-7042.c b/testcases/cve/cve-2016-7042.c
index 24915ad441..0556789d61 100644
--- a/testcases/cve/cve-2016-7042.c
+++ b/testcases/cve/cve-2016-7042.c
@@ -25,9 +25,7 @@ static void do_test(void)
 {
 	char buf[BUFSIZ];
 
-	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
-	if (key == -1)
-		tst_brk(TBROK, "Failed to add key");
+	key = SAFE_ADD_KEY("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
 
 	if (keyctl(KEYCTL_UPDATE, key, "b", 1))
 		tst_brk(TBROK, "Failed to update key");
diff --git a/testcases/kernel/syscalls/add_key/add_key03.c b/testcases/kernel/syscalls/add_key/add_key03.c
index fe2406fcc2..4b0e49127e 100644
--- a/testcases/kernel/syscalls/add_key/add_key03.c
+++ b/testcases/kernel/syscalls/add_key/add_key03.c
@@ -24,13 +24,8 @@
 
 static key_serial_t create_keyring(const char *description)
 {
-	TEST(add_key("keyring", description, NULL, 0,
-		     KEY_SPEC_PROCESS_KEYRING));
-	if (TST_RET < 0) {
-		tst_brk(TBROK | TTERRNO,
-			"unable to create keyring '%s'", description);
-	}
-	return TST_RET;
+	return SAFE_ADD_KEY("keyring", description, NULL, 0,
+		     KEY_SPEC_PROCESS_KEYRING);
 }
 
 static key_serial_t get_keyring_id(key_serial_t special_id)
diff --git a/testcases/kernel/syscalls/add_key/add_key04.c b/testcases/kernel/syscalls/add_key/add_key04.c
index 3fbb52479b..ff0895efd1 100644
--- a/testcases/kernel/syscalls/add_key/add_key04.c
+++ b/testcases/kernel/syscalls/add_key/add_key04.c
@@ -50,18 +50,12 @@ static void do_test(void)
 
 		for (i = 0; i < ASSOC_ARRAY_FAN_OUT; i++) {
 			sprintf(description, "keyring%d", i);
-			TEST(add_key("keyring", description, NULL, 0,
-				     KEY_SPEC_SESSION_KEYRING));
-			if (TST_RET < 0) {
-				tst_brk(TBROK | TTERRNO,
-					"unable to create keyring %d", i);
-			}
+			SAFE_ADD_KEY("keyring", description, NULL, 0,
+				     KEY_SPEC_SESSION_KEYRING);
 		}
 
-		TEST(add_key("user", "userkey", payload, sizeof(PAYLOAD),
-			     KEY_SPEC_SESSION_KEYRING));
-		if (TST_RET < 0)
-			tst_brk(TBROK | TTERRNO, "unable to create user key");
+		SAFE_ADD_KEY("user", "userkey", payload, sizeof(PAYLOAD),
+			     KEY_SPEC_SESSION_KEYRING);
 
 		exit(0);
 	}
diff --git a/testcases/kernel/syscalls/keyctl/keyctl02.c b/testcases/kernel/syscalls/keyctl/keyctl02.c
index 306181c44a..964dfad316 100644
--- a/testcases/kernel/syscalls/keyctl/keyctl02.c
+++ b/testcases/kernel/syscalls/keyctl/keyctl02.c
@@ -61,10 +61,8 @@ static void do_test(void)
 	pthread_t pth[4];
 
 	for (i = 0; i < LOOPS; i++) {
-		key = add_key("user", "ltptestkey", "foo", 3,
+		key = SAFE_ADD_KEY("user", "ltptestkey", "foo", 3,
 			KEY_SPEC_PROCESS_KEYRING);
-		if (key == -1)
-			tst_brk(TBROK | TERRNO, "Failed to add key");
 
 		SAFE_PTHREAD_CREATE(&pth[0], NULL, do_read,
 			(void *)(unsigned long)key);
@@ -103,10 +101,8 @@ static void do_test(void)
 	 *
 	 * We create extra key here, to remove reference to last revoked key.
 	 */
-	key_inv = add_key("user", "ltptestkey", "foo", 3,
+	key_inv = SAFE_ADD_KEY("user", "ltptestkey", "foo", 3,
 		KEY_SPEC_PROCESS_KEYRING);
-	if (key_inv == -1)
-		tst_brk(TBROK | TERRNO, "Failed to add key");
 
 	/*
 	 * If we have invalidate, we can drop extra key immediately as well,
diff --git a/testcases/kernel/syscalls/keyctl/keyctl03.c b/testcases/kernel/syscalls/keyctl/keyctl03.c
index 676dddcd0b..d5339cb43d 100644
--- a/testcases/kernel/syscalls/keyctl/keyctl03.c
+++ b/testcases/kernel/syscalls/keyctl/keyctl03.c
@@ -20,9 +20,7 @@ static void do_test(void)
 {
 	key_serial_t key;
 
-	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
-	if (key == -1)
-		tst_brk(TBROK, "Failed to add key");
+	key = SAFE_ADD_KEY("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
 
 	request_key("keyring", "foo", "bar", KEY_SPEC_THREAD_KEYRING);
 
diff --git a/testcases/kernel/syscalls/keyctl/keyctl06.c b/testcases/kernel/syscalls/keyctl/keyctl06.c
index b3c61b9d15..e3fdbcb841 100644
--- a/testcases/kernel/syscalls/keyctl/keyctl06.c
+++ b/testcases/kernel/syscalls/keyctl/keyctl06.c
@@ -21,10 +21,8 @@
 
 static void add_test_key(const char *description)
 {
-	TEST(add_key("user", description, "payload", 7,
-		     KEY_SPEC_PROCESS_KEYRING));
-	if (TST_RET < 0)
-		tst_brk(TBROK | TTERRNO, "Failed to add test key");
+	SAFE_ADD_KEY("user", description, "payload", 7,
+		     KEY_SPEC_PROCESS_KEYRING);
 }
 
 static void do_test(void)
diff --git a/testcases/kernel/syscalls/request_key/request_key01.c b/testcases/kernel/syscalls/request_key/request_key01.c
index 97121533da..0aa5fd85f7 100644
--- a/testcases/kernel/syscalls/request_key/request_key01.c
+++ b/testcases/kernel/syscalls/request_key/request_key01.c
@@ -35,9 +35,7 @@ static void verify_request_key(void)
 
 static void setup(void)
 {
-	key = add_key("keyring", "ltp", NULL, 0, KEY_SPEC_THREAD_KEYRING);
-	if (key == -1)
-		tst_brk(TBROK | TERRNO, "add_key() failed");
+	key = SAFE_ADD_KEY("keyring", "ltp", NULL, 0, KEY_SPEC_THREAD_KEYRING);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/request_key/request_key02.c b/testcases/kernel/syscalls/request_key/request_key02.c
index 2d35aceeee..d7e0664e68 100644
--- a/testcases/kernel/syscalls/request_key/request_key02.c
+++ b/testcases/kernel/syscalls/request_key/request_key02.c
@@ -48,9 +48,7 @@ static int init_key(char *name, int cmd)
 	int n;
 	int sec = 1;
 
-	n = add_key("keyring", name, NULL, 0, KEY_SPEC_THREAD_KEYRING);
-	if (n == -1)
-		tst_brk(TBROK | TERRNO, "add_key() failed");
+	n = SAFE_ADD_KEY("keyring", name, NULL, 0, KEY_SPEC_THREAD_KEYRING);
 
 	if (cmd == KEYCTL_REVOKE) {
 		if (keyctl(cmd, n) == -1)
diff --git a/testcases/kernel/watchqueue/common.h b/testcases/kernel/watchqueue/common.h
index 0921dce9a6..639dd4a7cd 100644
--- a/testcases/kernel/watchqueue/common.h
+++ b/testcases/kernel/watchqueue/common.h
@@ -81,9 +81,7 @@ static inline key_serial_t wqueue_add_key(int fd)
 {
 	key_serial_t key;
 
-	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
-	if (key == -1)
-		tst_brk(TBROK, "add_key error: %s", tst_strerrno(errno));
+	key = SAFE_ADD_KEY("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
 
 	SAFE_KEYCTL(KEYCTL_WATCH_KEY, key, fd, 0x01, 0);
 	SAFE_KEYCTL(KEYCTL_WATCH_KEY, KEY_SPEC_SESSION_KEYRING, fd, 0x02, 0);
-- 
2.55.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-09-16 14:05 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-16 14:03 [LTP] [PATCH v3 00/36] Improve coverage for keyctl() syscall Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 01/36] lapi/keyctl.h: Add fallback definitions for extended ops Petr Vorel
2026-09-17  9:35   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 02/36] lapi/keyctl.h: Add SAFE_ADD_KEY() Petr Vorel
2026-09-17  9:38   ` Cyril Hrubis
2026-09-16 14:03 ` Petr Vorel [this message]
2026-09-17  9:43   ` [LTP] [PATCH v3 03/36] tree: keyctl: Use SAFE_ADD_KEY() Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 04/36] keyctl10: Test KEYCTL_DESCRIBE format parsing Petr Vorel
2026-09-17  9:54   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 05/36] keyctl11: Test KEYCTL_DESCRIBE with exact buffer size Petr Vorel
2026-09-16 18:19   ` [LTP] lapi/keyctl.h: Add fallback definitions for extended ops linuxtestproject.agent
2026-09-17 11:07   ` [LTP] [PATCH v3 05/36] keyctl11: Test KEYCTL_DESCRIBE with exact buffer size Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 06/36] keyctl12: Test KEYCTL_DESCRIBE with too small buffer Petr Vorel
2026-09-17 11:14   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 07/36] keyctl13: Test KEYCTL_DESCRIBE size query Petr Vorel
2026-09-17 11:32   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 08/36] keyctl14: Negative tests for KEYCTL_DESCRIBE Petr Vorel
2026-09-18 15:42   ` Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 09/36] keyctl15: Test KEYCTL_GET_SECURITY label retrieval Petr Vorel
2026-09-17  8:54   ` Li Wang
2026-09-17 11:50     ` Cyril Hrubis
2026-09-18  5:01       ` Li Wang
2026-09-18  9:50         ` Cyril Hrubis
2026-09-18 10:59           ` Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 10/36] keyctl16: Test KEYCTL_GET_SECURITY truncated copy Petr Vorel
2026-09-17 14:01   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 11/36] keyctl17: Negative tests for KEYCTL_GET_SECURITY Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 12/36] keyctl18: Test basic KEYCTL_MOVE Petr Vorel
2026-09-17  9:51   ` Li Wang
2026-09-17 14:37   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 13/36] keyctl19: Test KEYCTL_MOVE with same source and destination Petr Vorel
2026-09-17  9:37   ` Li Wang
2026-09-16 14:03 ` [LTP] [PATCH v3 14/36] keyctl20: Test KEYCTL_MOVE displacement Petr Vorel
2026-09-17  9:38   ` Li Wang
2026-09-16 14:03 ` [LTP] [PATCH v3 15/36] keyctl21: Negative and boundary tests for KEYCTL_MOVE Petr Vorel
2026-09-18 11:24   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 16/36] keyctl22: Test KEYCTL_RESTRICT_KEYRING reject-all Petr Vorel
2026-09-18 11:29   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 17/36] lib: tst_test: Move the iterations to struct tst_test Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 18/36] keyctl23: Test KEYCTL_RESTRICT_KEYRING builtin_trusted Petr Vorel
2026-09-18 11:51   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 19/36] keyctl24: Negative tests for KEYCTL_RESTRICT_KEYRING Petr Vorel
2026-09-18 12:08   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 20/36] keyctl25: Test KEYCTL_DH_COMPUTE shared secret computation Petr Vorel
2026-09-18 12:14   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 21/36] keyctl26: Test KEYCTL_DH_COMPUTE size query Petr Vorel
2026-09-18 12:16   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 22/36] keyctl27: Test KEYCTL_DH_COMPUTE KDF key derivation Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 23/36] keyctl28: Negative and boundary tests for KEYCTL_DH_COMPUTE Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 24/36] lapi/keyctl.h: Add fallback definitions for public key ops Petr Vorel
2026-09-18 12:31   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 25/36] keyctl29: Test KEYCTL_PKEY_QUERY on public key Petr Vorel
2026-09-18 14:42   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 26/36] keyctl30: Test KEYCTL_PKEY_QUERY on private key Petr Vorel
2026-09-18 14:50   ` Cyril Hrubis
2026-09-18 16:55     ` Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 27/36] keyctl31: Test KEYCTL_PKEY_ENCRYPT and KEYCTL_PKEY_DECRYPT Petr Vorel
2026-09-18 15:17   ` Cyril Hrubis
2026-09-18 15:53     ` Petr Vorel
2026-09-18 17:01     ` Petr Vorel
2026-09-16 14:03 ` [LTP] [PATCH v3 28/36] keyctl32: Test KEYCTL_PKEY_SIGN and VERIFY Petr Vorel
2026-09-18 15:25   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 29/36] keyctl33: Negative tests for KEYCTL_PKEY_* Petr Vorel
2026-09-18 15:31   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 30/36] lapi/keyctl.h: Add capability fallback defines Petr Vorel
2026-09-18 15:32   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 31/36] keyctl34: Test KEYCTL_CAPABILITIES flag retrieval Petr Vorel
2026-09-18 15:36   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 32/36] keyctl35: Test KEYCTL_CAPABILITIES size query Petr Vorel
2026-09-18 15:37   ` Cyril Hrubis
2026-09-16 14:03 ` [LTP] [PATCH v3 33/36] keyctl36: Test KEYCTL_CAPABILITIES buffer sizing Petr Vorel
2026-09-18 15:44   ` Cyril Hrubis
2026-09-16 14:04 ` [LTP] [PATCH v3 34/36] keyctl37: Negative tests for KEYCTL_CAPABILITIES Petr Vorel
2026-09-16 14:04 ` [LTP] [PATCH v3 35/36] keyctl38: Test KEYCTL_WATCH_KEY add and remove Petr Vorel
2026-09-18 15:53   ` Cyril Hrubis
2026-09-16 14:04 ` [LTP] [PATCH v3 36/36] keyctl39: Negative tests for KEYCTL_WATCH_KEY Petr Vorel
2026-09-17 10:11 ` [LTP] [PATCH v3 00/36] Improve coverage for keyctl() syscall Li Wang
2026-09-18 14:39   ` Petr Vorel
2026-09-19  0:18     ` Li Wang

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=20260916140402.1797325-4-pvorel@suse.cz \
    --to=pvorel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.