linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Denis Efremov <efremov@linux.com>
To: Jan Kara <jack@suse.com>
Cc: Denis Efremov <efremov@linux.com>,
	linux-kernel@vger.kernel.org, Joe Perches <joe@perches.com>,
	"Gustavo A . R . Silva" <gustavo@embeddedor.com>
Subject: [PATCH v3] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
Date: Fri, 28 Aug 2020 01:16:52 +0300	[thread overview]
Message-ID: <20200827221652.64660-1-efremov@linux.com> (raw)
In-Reply-To: <20200827151923.40067-1-efremov@linux.com>

Use kvzalloc() in udf_sb_alloc_bitmap() instead of open-coding it.
Size computation wrapped in struct_size() macro to prevent potential
integer overflows.

Signed-off-by: Denis Efremov <efremov@linux.com>
---
Changes in v2:
 - size computation wrapped in struct_size()
Changes in v3:
 - int size dropped

 fs/udf/super.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/fs/udf/super.c b/fs/udf/super.c
index 1c42f544096d..d9eabbe368ff 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -1006,18 +1006,10 @@ int udf_compute_nr_groups(struct super_block *sb, u32 partition)
 static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
 {
 	struct udf_bitmap *bitmap;
-	int nr_groups;
-	int size;
-
-	nr_groups = udf_compute_nr_groups(sb, index);
-	size = sizeof(struct udf_bitmap) +
-		(sizeof(struct buffer_head *) * nr_groups);
-
-	if (size <= PAGE_SIZE)
-		bitmap = kzalloc(size, GFP_KERNEL);
-	else
-		bitmap = vzalloc(size); /* TODO: get rid of vzalloc */
+	int nr_groups = udf_compute_nr_groups(sb, index);
 
+	bitmap = kvzalloc(struct_size(bitmap, s_block_bitmap, nr_groups),
+			  GFP_KERNEL);
 	if (!bitmap)
 		return NULL;
 
-- 
2.26.2


  parent reply	other threads:[~2020-08-27 22:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 15:19 [PATCH] udf: Use kvzalloc() in udf_sb_alloc_bitmap() Denis Efremov
2020-08-27 15:28 ` Denis Efremov
2020-08-27 15:49   ` Joe Perches
2020-08-27 21:25 ` [PATCH v2] " Denis Efremov
2020-08-27 22:09   ` Gustavo A. R. Silva
2020-08-27 22:07     ` Denis Efremov
2020-08-27 22:16 ` Denis Efremov [this message]
2020-08-27 22:29   ` [PATCH v3] " Gustavo A. R. Silva
2020-08-28 10:29     ` Jan Kara

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=20200827221652.64660-1-efremov@linux.com \
    --to=efremov@linux.com \
    --cc=gustavo@embeddedor.com \
    --cc=jack@suse.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).