Skip to contentSkip to conversation

mem/hugetlb: use SAFE_SHMGET() and fix checkpatch warnings in hugeshmget

PATCH In review Samir Mulani 3 participants 3 messages Aug 18 – Aug 25

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 mem/hugetlb: use SAFE_SHMGET() and fix checkpatch warnings in hugeshmget

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

---
Patch v2: https://lore.kernel.org/ltp/[email protected]/
Patch v1: https://lore.kernel.org/ltp/[email protected]/

 .../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(-)
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c +7 -8
index bbd968c06..c1fd41509 100644
@@ -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)
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c +5 -7
index 0e9c7d5f0..8a5e2708d 100644
@@ -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)
testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c +5 -6
index 336319603..de96d9824 100644
@@ -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);
Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Samir,

testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c static void test_hugeshmget(void) · line 41

Quoted 9 lines · Samir Mulani

mem/hugetlb: use SAFE_SHMGET() and fix checkpatch warnings in hugeshmget

testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c +4 -2
+	shm_id_1 = SAFE_SHMGET(shmkey, shm_size,
+			      SHM_HUGETLB | IPC_CREAT | IPC_EXCL | SHM_RW);
 
-		tst_res(TFAIL | TTERRNO, "shmget failed unexpectedly "
-				"- expect errno=ENOSPC, got");
+		tst_res(TFAIL | TTERRNO,
+			"shmget failed unexpectedly - expect errno=ENOSPC, got");

Severity: medium

Could the checkpatch-only changes be moved to a separate patch? The SAFE_SHMGET() conversion is a behavioral API cleanup, while hugeshmget03 contains only independent message-formatting changes. LTP requires each patch to contain one logical change.

Verdict - Needs revision

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hi Samir,

Quoted 4 lines

Could the checkpatch-only changes be moved to a separate patch? The SAFE_SHMGET() conversion is a behavioral API cleanup, while hugeshmget03 contains only independent message-formatting changes. LTP requires each patch to contain one logical change.

This agent review is actually accurate. Please split the patch in two, so SAFE_SHMGET() and checkpatch cleanup are separated.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp