Re: [PATCH] selftests/ipc: Use IPC_STAT to get queue information
From: Asiye Sarıyıldız
Date: Thu Nov 26 2026 - 00:12:36 EST
Hi Shuah,
Just a gentle ping on this patch.
Thanks,
Muhammed
Asiye Sarıyıldız <asiyee994@xxxxxxxxx>, 26 Kas 2026 Per, 08:03
tarihinde şunu yazdı:
>
> Hi Shuah,
>
> Just a gentle ping on this patch.
>
> Thanks,
> Muhammed
>
> 15 Kas 2026 Paz 09:05 tarihinde Asiye Sarıyıldız <asiyee994@xxxxxxxxx> şunu yazdı:
>>
>> Hi Shuah,
>>
>> Just a gentle ping on this patch.
>>
>> Thanks,
>> Muhammed
>>
>> Muhammed Sariyildiz <asiyee994@xxxxxxxxx>, 1 Kas 2026 Paz, 22:48
>> tarihinde şunu yazdı:
>> >
>> > 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@xxxxxxxxx>
>> > ---
>> > 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
>> >