From: Andrew Morton <akpm@linux-foundation.org>
To: Gavrilov Ilia <Ilia.Gavrilov@infotecs.ru>
Cc: Colin Ian King <colin.i.king@gmail.com>,
wuchi <wuchi.zero@gmail.com>, Jens Axboe <axboe@kernel.dk>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"lvc-project@linuxtesting.org" <lvc-project@linuxtesting.org>
Subject: Re: [PATCH] relay: Fix type mismatch when allocating memory in relay_create_buf()
Date: Tue, 29 Nov 2022 15:30:37 -0800 [thread overview]
Message-ID: <20221129153037.d9c9496c291e5cefa4aec762@linux-foundation.org> (raw)
In-Reply-To: <20221129092002.3538384-1-Ilia.Gavrilov@infotecs.ru>
On Tue, 29 Nov 2022 09:23:38 +0000 Gavrilov Ilia <Ilia.Gavrilov@infotecs.ru> wrote:
> The 'padding' field of the 'rchan_buf' structure is an array of 'size_t'
> elements, but the memory is allocated for an array of 'size_t *' elements.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> --- a/kernel/relay.c
> +++ b/kernel/relay.c
> @@ -148,13 +148,13 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan)
> {
> struct rchan_buf *buf;
>
> - if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t *))
> + if (chan->n_subbufs > KMALLOC_MAX_SIZE / sizeof(size_t))
> return NULL;
>
> buf = kzalloc(sizeof(struct rchan_buf), GFP_KERNEL);
> if (!buf)
> return NULL;
> - buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t *),
> + buf->padding = kmalloc_array(chan->n_subbufs, sizeof(size_t),
> GFP_KERNEL);
This is why I prefer kmalloc_array(N, sizeof(*(buf->padding)), ...)
Because the reviewer doesn't have to go check that the types match up,
and because the code doesn't need changing if the type of
*(buf->padding) is changed.
Others don't like this practice, but I forget why.
prev parent reply other threads:[~2022-11-29 23:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 9:23 Gavrilov Ilia
2022-11-29 23:30 ` Andrew Morton [this message]
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=20221129153037.d9c9496c291e5cefa4aec762@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=Ilia.Gavrilov@infotecs.ru \
--cc=axboe@kernel.dk \
--cc=colin.i.king@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=wuchi.zero@gmail.com \
/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®