All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samir Mulani <samir@linux.ibm.com>
To: ltp@lists.linux.it
Cc: Samir Mulani <samir@linux.ibm.com>
Subject: [LTP] [PATCH v3] mem/hugetlb: use SAFE_SHMGET() and fix checkpatch warnings in hugeshmget
Date: Tue, 18 Aug 2026 18:48:00 +0530	[thread overview]
Message-ID: <20260818131800.42931-1-samir@linux.ibm.com> (raw)

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

             reply	other threads:[~2026-08-18 18:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 13:18 Samir Mulani [this message]
2026-08-18 19:29 ` [LTP] mem/hugetlb: use SAFE_SHMGET() and fix checkpatch warnings in hugeshmget linuxtestproject.agent

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=20260818131800.42931-1-samir@linux.ibm.com \
    --to=samir@linux.ibm.com \
    --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.