From: Gautam Menghani <gautam@linux.ibm.com>
To: Chaithanya Lagisetty <nagachaithanya9911@gmail.com>
Cc: pbonzini@redhat.com, seanjc@google.com, shuah@kernel.org,
kvm@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests: kvm: Fix transposed calloc() arguments in the uffd helper
Date: Wed, 9 Sep 2026 19:19:36 +0530 [thread overview]
Message-ID: <aqFj8Iu7cUM7koH0@Gautams-MacBook-Pro.local> (raw)
In-Reply-To: <20260904052033.3648259-1-nagachaithanya9911@gmail.com>
On Fri, Sep 04, 2026 at 05:20:33AM +0000, Chaithanya Lagisetty wrote:
> uffd_setup_demand_paging() passes the element size as the first argument
> to calloc() and the element count as the second:
>
> uffd_desc->pipefds = calloc(sizeof(int), num_readers);
>
> calloc() expects the number of elements first and the size of each element
> second. The product, and therefore the allocation size, is the same either
> way, so this is not a functional change, but the arguments are misleading
> and GCC 14 diagnoses them with -Wcalloc-transposed-args, which is enabled
> by -Wextra.
>
> Swap the arguments to match the calloc() prototype.
>
> Signed-off-by: Chaithanya Lagisetty <nagachaithanya9911@gmail.com>
> ---
> tools/testing/selftests/kvm/lib/userfaultfd_util.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/userfaultfd_util.c b/tools/testing/selftests/kvm/lib/userfaultfd_util.c
> index f7ce5a6ddcc2..49eff05b7d39 100644
> --- a/tools/testing/selftests/kvm/lib/userfaultfd_util.c
> +++ b/tools/testing/selftests/kvm/lib/userfaultfd_util.c
> @@ -119,13 +119,13 @@ struct uffd_desc *uffd_setup_demand_paging(int uffd_mode, useconds_t delay,
> uffd_desc = malloc(sizeof(struct uffd_desc));
> TEST_ASSERT(uffd_desc, "Failed to malloc uffd descriptor");
>
> - uffd_desc->pipefds = calloc(sizeof(int), num_readers);
> + uffd_desc->pipefds = calloc(num_readers, sizeof(int));
> TEST_ASSERT(uffd_desc->pipefds, "Failed to alloc pipes");
>
> - uffd_desc->readers = calloc(sizeof(pthread_t), num_readers);
> + uffd_desc->readers = calloc(num_readers, sizeof(pthread_t));
> TEST_ASSERT(uffd_desc->readers, "Failed to alloc reader threads");
>
> - uffd_desc->reader_args = calloc(sizeof(struct uffd_reader_args), num_readers);
> + uffd_desc->reader_args = calloc(num_readers, sizeof(struct uffd_reader_args));
> TEST_ASSERT(uffd_desc->reader_args, "Failed to alloc reader_args");
>
> uffd_desc->num_readers = num_readers;
> --
> 2.43.0
>
Good catch
Reviewed-by: Gautam Menghani <gautam@linux.ibm.com>
next prev parent reply other threads:[~2026-09-09 13:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-04 5:20 Chaithanya Lagisetty
2026-09-09 13:49 ` Gautam Menghani [this message]
2026-09-11 16:02 ` Sean Christopherson
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=aqFj8Iu7cUM7koH0@Gautams-MacBook-Pro.local \
--to=gautam@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=nagachaithanya9911@gmail.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--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®