NTFS3 file system kernel mode driver
 help / color / mirror / Atom feed
From: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
To: Lenko Donchev <lenko.donchev@gmail.com>,
	Konstantin Komarov <almaz.alexandrovich@paragon-software.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] fs/ntfs3: use kcalloc() instead of kzalloc()
Date: Sat, 10 Feb 2024 22:31:49 -0600	[thread overview]
Message-ID: <bb7a8d29-d80d-41b0-8dde-2aba44c3fd90@embeddedor.com> (raw)
In-Reply-To: <Zcgoighe07IahAV8@nixos>



On 2/10/24 19:53, Lenko Donchev wrote:
> We are trying to get rid of all multiplications from allocation
> functions to prevent integer overflows[1]. Here the multiplication is
> obviously safe, but using kcalloc() is more appropriate and improves
> readability. This patch has no effect on runtime behavior.
> 
> Link: https://github.com/KSPP/linux/issues/162 [1]
> Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [2]
> 
> Signed-off-by: Lenko Donchev <lenko.donchev@gmail.com>
> ---
>   fs/ntfs3/frecord.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
> index 3b42938a9d3b..d435446537ca 100644
> --- a/fs/ntfs3/frecord.c
> +++ b/fs/ntfs3/frecord.c
> @@ -2636,7 +2636,7 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,
>   		goto out1;
>   	}
>   
> -	pages_disk = kzalloc(npages_disk * sizeof(struct page *), GFP_NOFS);
> +	pages_disk = kcalloc(npages_disk, sizeof(struct page *), GFP_NOFS);

`sizeof(*pages_disk)` is preferable over `sizeof(struct page *)`

Thanks
--
Gustavo

>   	if (!pages_disk) {
>   		err = -ENOMEM;
>   		goto out2;

      reply	other threads:[~2024-02-11  4:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-11  1:53 [PATCH] fs/ntfs3: use kcalloc() instead of kzalloc() Lenko Donchev
2024-02-11  4:31 ` Gustavo A. R. Silva [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=bb7a8d29-d80d-41b0-8dde-2aba44c3fd90@embeddedor.com \
    --to=gustavo@embeddedor.com \
    --cc=almaz.alexandrovich@paragon-software.com \
    --cc=gustavoars@kernel.org \
    --cc=lenko.donchev@gmail.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).