* [PATCH] selftests/ipc: Use IPC_STAT to get queue information
@ 2026-11-01 19:48 Muhammed Sariyildiz
0 siblings, 0 replies; only message in thread
From: Muhammed Sariyildiz @ 2026-11-01 19:48 UTC (permalink / raw)
To: shuah; +Cc: linux-kselftest, linux-kernel
dump_queue() finds the message queue's stats by brute-forcing kernel
indexes 0..255 with MSG_STAT and comparing the returned identifier with
msgque->msq_id. This misses queues whose index is 256 or larger, and if
no match is found the loop ends and the code goes on using a stale
or uninitialized struct msqid_ds.
The identifier is already known, so query it directly with IPC_STAT.
This removes the loop and reports a failure if the queue cannot be
queried.
Signed-off-by: Muhammed Sariyildiz <asiyee994@gmail.com>
---
tools/testing/selftests/ipc/msgque.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git a/tools/testing/selftests/ipc/msgque.c b/tools/testing/selftests/ipc/msgque.c
index 4b4c1ab..f4168c7 100644
--- a/tools/testing/selftests/ipc/msgque.c
+++ b/tools/testing/selftests/ipc/msgque.c
@@ -130,21 +130,13 @@ err:
int dump_queue(struct msgque_data *msgque)
{
struct msqid_ds ds;
- int kern_id;
int i, ret;
- for (kern_id = 0; kern_id < 256; kern_id++) {
- ret = msgctl(kern_id, MSG_STAT, &ds);
- if (ret < 0) {
- if (errno == EINVAL)
- continue;
- ksft_test_result_fail("Failed to get stats for IPC queue with id %d\n",
- kern_id);
- return -errno;
- }
-
- if (ret == msgque->msq_id)
- break;
+ ret = msgctl(msgque->msq_id, IPC_STAT, &ds);
+ if (ret < 0) {
+ ksft_test_result_fail("Failed to get stats for IPC queue with id %d\n",
+ msgque->msq_id);
+ return -errno;
}
msgque->messages = malloc(sizeof(struct msg1) * ds.msg_qnum);
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-01 19:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-01 19:48 [PATCH] selftests/ipc: Use IPC_STAT to get queue information Muhammed Sariyildiz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®