All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v3] mem/hugetlb: use SAFE_SHMGET() and fix checkpatch warnings in hugeshmget
@ 2026-08-18 13:18 Samir Mulani
  2026-08-18 19:29 ` [LTP] " linuxtestproject.agent
  0 siblings, 1 reply; 2+ messages in thread
From: Samir Mulani @ 2026-08-18 13:18 UTC (permalink / raw)
  To: ltp; +Cc: Samir Mulani

Replace the manual shmget()/error-check/tst_brk() pattern in the
setup() functions of hugeshmget02 and hugeshmget05 with SAFE_SHMGET()
to align with LTP conventions and reduce boilerplate error handling.
Include "tst_safe_sysv_ipc.h" explicitly in both files to make the
SAFE_SHMGET() declaration directly visible.

In hugeshmget03, simplify the tst_brk() error message by removing
the "shmget #setup" string and replacing it with "shmget()" to avoid
embedding the function name as a plain string literal.

Also fix the following pre-existing checkpatch warnings across all
three files:
- hugeshmget02: remove unnecessary parentheses around pointer
  dereferences of tcases[i].skey
- hugeshmget02: fix continuation line alignment in TEST() call
- hugeshmget03: merge split string literals in tst_res() and
  tst_brk() calls into single strings
- hugeshmget05: merge split string literal in tst_res() call into
  a single string


Signed-off-by: Samir Mulani <samir@linux.ibm.com>
Reviewed-by: Li Wang <wangli.ahau@gmail.com>
---
Patch v2: https://lore.kernel.org/ltp/20260412141039.1075095-1-samir@linux.ibm.com/
Patch v1: https://lore.kernel.org/ltp/20260407054943.125260-1-samir@linux.ibm.com/

 .../kernel/mem/hugetlb/hugeshmget/hugeshmget02.c  | 15 +++++++--------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget03.c  | 12 +++++-------
 .../kernel/mem/hugetlb/hugeshmget/hugeshmget05.c  | 11 +++++------
 3 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
index bbd968c06..c1fd41509 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
@@ -12,6 +12,7 @@
  *	04/2004 - Updated by Robbie Williamson
  */
 #include <limits.h>
+#include "tst_safe_sysv_ipc.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -41,19 +42,19 @@ static void test_hugeshmget(unsigned int i)
 	int shm_id_2 = -1;
 
 	if (*tcases[i].skey == -1) {
-		shm_id_2 = shmget(*(tcases[i].skey), 0, 0);
+		shm_id_2 = shmget(*tcases[i].skey, 0, 0);
 		if (shm_id_2 != -1)
 			shmctl(shm_id_2, IPC_RMID, NULL);
 	}
 
-	TEST(shmget(*(tcases[i].skey), tcases[i].size_coe * shm_size,
-					tcases[i].flags));
+	TEST(shmget(*tcases[i].skey, tcases[i].size_coe * shm_size,
+		    tcases[i].flags));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "shmget succeeded unexpectedly");
 		return;
 	}
 
-	if (TST_ERR != tcases[i].error) {
+	if (tcases[i].error != TST_ERR) {
 		tst_res(TFAIL | TTERRNO,
 			"shmget failed unexpectedly, expected %s",
 			tst_strerrno(tcases[i].error));
@@ -77,10 +78,8 @@ void setup(void)
 
 	shmkey = getipckey();
 	shmkey2 = shmkey + 1;
-	shm_id_1 = shmget(shmkey, shm_size,
-			  SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
-	if (shm_id_1 == -1)
-		tst_brk(TBROK | TERRNO, "shmget #setup");
+	shm_id_1 = SAFE_SHMGET(shmkey, shm_size,
+			      SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
index 0e9c7d5f0..8a5e2708d 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
@@ -37,8 +37,8 @@ static void test_hugeshmget(void)
 	if (TST_ERR == ENOSPC)
 		tst_res(TPASS | TTERRNO, "shmget failed as expected");
 	else
-		tst_res(TFAIL | TTERRNO, "shmget failed unexpectedly "
-				"- expect errno=ENOSPC, got");
+		tst_res(TFAIL | TTERRNO,
+			"shmget failed unexpectedly - expect errno=ENOSPC, got");
 }
 
 static void setup(void)
@@ -64,15 +64,13 @@ static void setup(void)
 	while (shm_id_1 != -1) {
 		shm_id_arr[num_shms++] = shm_id_1;
 		if (num_shms == MAXIDS)
-			tst_brk(TBROK, "The maximum number of "
-				 "shared memory ID's has been reached. "
-				 "Please increase the MAXIDS value in "
-				 "the test.");
+			tst_brk(TBROK,
+				"The maximum number of shared memory ID's has been reached. Please increase the MAXIDS value in the test.");
 		shm_id_1 = shmget(IPC_PRIVATE, shm_size,
 				  SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
 	}
 	if (errno != ENOSPC)
-		tst_brk(TBROK | TERRNO, "shmget #setup");
+		tst_brk(TBROK | TERRNO, "shmget()");
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
index 336319603..de96d9824 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
@@ -14,6 +14,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <limits.h>
+#include "tst_safe_sysv_ipc.h"
 #include "hugetlb.h"
 
 static size_t shm_size;
@@ -53,8 +54,8 @@ static void do_child(void)
 	if (TST_ERR == EACCES)
 		tst_res(TPASS | TTERRNO, "shmget failed as expected");
 	else
-		tst_res(TFAIL | TTERRNO, "shmget failed unexpectedly "
-				"- expect errno=EACCES, got");
+		tst_res(TFAIL | TTERRNO,
+			"shmget failed unexpectedly - expect errno=EACCES, got");
 }
 
 void setup(void)
@@ -69,10 +70,8 @@ void setup(void)
 	shm_size = hpage_size * tst_hugepages / 2;
 	update_shm_size(&shm_size);
 	shmkey = getipckey();
-	shm_id_1 = shmget(shmkey, shm_size,
-			  SHM_HUGETLB | SHM_RW | IPC_CREAT | IPC_EXCL);
-	if (shm_id_1 == -1)
-		tst_brk(TBROK | TERRNO, "shmget #setup");
+	shm_id_1 = SAFE_SHMGET(shmkey, shm_size,
+			      SHM_HUGETLB | SHM_RW | IPC_CREAT | IPC_EXCL);
 
 	/* get the userid for a non-root user */
 	ltp_uid = getuserid(ltp_user);
-- 
2.52.0


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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-18 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-18 13:18 [LTP] [PATCH v3] mem/hugetlb: use SAFE_SHMGET() and fix checkpatch warnings in hugeshmget Samir Mulani
2026-08-18 19:29 ` [LTP] " linuxtestproject.agent

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.