* [PATCH] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
@ 2020-08-27 15:19 Denis Efremov
2020-08-27 15:28 ` Denis Efremov
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Denis Efremov @ 2020-08-27 15:19 UTC (permalink / raw)
To: Jan Kara; +Cc: Denis Efremov, linux-kernel
Use kvzalloc() in udf_sb_alloc_bitmap() instead of open-coding it.
Signed-off-by: Denis Efremov <efremov@linux.com>
---
I'm not sure about TODO comment, through.
fs/udf/super.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 1c42f544096d..c7cd15219b7c 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -1013,10 +1013,7 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 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 */
+ bitmap = kvzalloc(size, GFP_KERNEL);
if (!bitmap)
return NULL;
--
2.26.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
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:16 ` [PATCH v3] " Denis Efremov
2 siblings, 1 reply; 9+ messages in thread
From: Denis Efremov @ 2020-08-27 15:28 UTC (permalink / raw)
To: Jan Kara; +Cc: linux-kernel
> @@ -1013,10 +1013,7 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
> size = sizeof(struct udf_bitmap) +
> (sizeof(struct buffer_head *) * nr_groups);
I missed that this size is a good place to use struct_size for
overflow checking. I will send v2 instead.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
2020-08-27 15:28 ` Denis Efremov
@ 2020-08-27 15:49 ` Joe Perches
0 siblings, 0 replies; 9+ messages in thread
From: Joe Perches @ 2020-08-27 15:49 UTC (permalink / raw)
To: Denis Efremov, Jan Kara; +Cc: linux-kernel
On Thu, 2020-08-27 at 18:28 +0300, Denis Efremov wrote:
> > @@ -1013,10 +1013,7 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
> > size = sizeof(struct udf_bitmap) +
> > (sizeof(struct buffer_head *) * nr_groups);
>
> I missed that this size is a good place to use struct_size for
> overflow checking. I will send v2 instead.
And you could cuddle the
if (!bitmap)
return NULL;
by removing the blank line between the alloc and test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
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 21:25 ` Denis Efremov
2020-08-27 22:09 ` Gustavo A. R. Silva
2020-08-27 22:16 ` [PATCH v3] " Denis Efremov
2 siblings, 1 reply; 9+ messages in thread
From: Denis Efremov @ 2020-08-27 21:25 UTC (permalink / raw)
To: Jan Kara; +Cc: Denis Efremov, linux-kernel, Joe Perches
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>
---
fs/udf/super.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 1c42f544096d..bdf51bea54f3 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -1010,14 +1010,9 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
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 */
+ size = struct_size(bitmap, s_block_bitmap, nr_groups);
+ bitmap = kvzalloc(size, GFP_KERNEL);
if (!bitmap)
return NULL;
--
2.26.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v2] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
2020-08-27 22:09 ` Gustavo A. R. Silva
@ 2020-08-27 22:07 ` Denis Efremov
0 siblings, 0 replies; 9+ messages in thread
From: Denis Efremov @ 2020-08-27 22:07 UTC (permalink / raw)
To: Gustavo A. R. Silva, Jan Kara; +Cc: linux-kernel, Joe Perches
On 8/28/20 1:09 AM, Gustavo A. R. Silva wrote:
>
>
> On 8/27/20 16:25, Denis Efremov wrote:
>> 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>
>> ---
>
> Please, comment here what changed in v2, vn... e.g.:
>
> Changes in v2:
> - Use struct_size() helper.
>
Ah, thanks. I added this initially and accidentally regenerated the patch
file with format-patch.
>
> Why not this:
>
> bitmap = kvzalloc(struct_size(bitmap, s_block_bitmap, nr_groups),
> GFP_KERNEL);
>
> and you can also get rid of _size_ entirely.
>
My bad, I missed that only nr_groups is used down the code.
Thanks, I will resend it as v3.
Denis
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v2] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
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
0 siblings, 1 reply; 9+ messages in thread
From: Gustavo A. R. Silva @ 2020-08-27 22:09 UTC (permalink / raw)
To: Denis Efremov, Jan Kara; +Cc: linux-kernel, Joe Perches
On 8/27/20 16:25, Denis Efremov wrote:
> 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>
> ---
Please, comment here what changed in v2, vn... e.g.:
Changes in v2:
- Use struct_size() helper.
> fs/udf/super.c | 9 ++-------
> 1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/fs/udf/super.c b/fs/udf/super.c
> index 1c42f544096d..bdf51bea54f3 100644
> --- a/fs/udf/super.c
> +++ b/fs/udf/super.c
> @@ -1010,14 +1010,9 @@ static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
> 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 */
> + size = struct_size(bitmap, s_block_bitmap, nr_groups);
>
> + bitmap = kvzalloc(size, GFP_KERNEL);
Why not this:
bitmap = kvzalloc(struct_size(bitmap, s_block_bitmap, nr_groups),
GFP_KERNEL);
and you can also get rid of _size_ entirely.
Thanks
--
Gustavo
> if (!bitmap)
> return NULL;
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v3] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
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 21:25 ` [PATCH v2] " Denis Efremov
@ 2020-08-27 22:16 ` Denis Efremov
2020-08-27 22:29 ` Gustavo A. R. Silva
2 siblings, 1 reply; 9+ messages in thread
From: Denis Efremov @ 2020-08-27 22:16 UTC (permalink / raw)
To: Jan Kara; +Cc: Denis Efremov, linux-kernel, Joe Perches, Gustavo A . R . Silva
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
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH v3] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
2020-08-27 22:16 ` [PATCH v3] " Denis Efremov
@ 2020-08-27 22:29 ` Gustavo A. R. Silva
2020-08-28 10:29 ` Jan Kara
0 siblings, 1 reply; 9+ messages in thread
From: Gustavo A. R. Silva @ 2020-08-27 22:29 UTC (permalink / raw)
To: Denis Efremov, Jan Kara; +Cc: linux-kernel, Joe Perches
On 8/27/20 17:16, Denis Efremov wrote:
> 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>
Looks good. :)
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks
--
Gustavo
> ---
> 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;
>
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH v3] udf: Use kvzalloc() in udf_sb_alloc_bitmap()
2020-08-27 22:29 ` Gustavo A. R. Silva
@ 2020-08-28 10:29 ` Jan Kara
0 siblings, 0 replies; 9+ messages in thread
From: Jan Kara @ 2020-08-28 10:29 UTC (permalink / raw)
To: Gustavo A. R. Silva; +Cc: Denis Efremov, Jan Kara, linux-kernel, Joe Perches
On Thu 27-08-20 17:29:25, Gustavo A. R. Silva wrote:
>
>
> On 8/27/20 17:16, Denis Efremov wrote:
> > 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>
>
> Looks good. :)
>
> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thank you both. I've added the patch to my tree.
Honza
>
> Thanks
> --
> Gustavo
>
> > ---
> > 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;
> >
> >
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2020-08-28 10:29 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v3] " Denis Efremov
2020-08-27 22:29 ` Gustavo A. R. Silva
2020-08-28 10:29 ` Jan Kara
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).