Skip to content

Commit

Permalink
udf: Use kvzalloc() in udf_sb_alloc_bitmap()
Browse files Browse the repository at this point in the history
Use kvzalloc() in udf_sb_alloc_bitmap() instead of open-coding it.
Size computation wrapped in struct_size() macro to prevent potential
integer overflows.

Link: https://lore.kernel.org/r/20200827221652.64660-1-efremov@linux.com
Signed-off-by: Denis Efremov <efremov@linux.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
  • Loading branch information
evdenis authored and jankara committed Aug 28, 2020
1 parent 25094ed commit 256ccb9
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions fs/udf/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 256ccb9

Please sign in to comment.