From: Muhammed Sariyildiz <asiyee994@gmail.com>
To: shuah@kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] selftests/ipc: Use IPC_STAT to get queue information
Date: Sun, 1 Nov 2026 22:48:14 +0300 [thread overview]
Message-ID: <20261101194814.188536-1-asiyee994@gmail.com> (raw)
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
reply other threads:[~2026-11-01 19:48 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261101194814.188536-1-asiyee994@gmail.com \
--to=asiyee994@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
/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 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®