2014-06-16 18:13:39

by Fabian Frédérick

[permalink] [raw]
Subject: [PATCH 1/1] fs/squashfs/file_direct.c: replace count*size kmalloc by kcalloc

kcalloc manages count*sizeof overflow.

Cc: Phillip Lougher <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Fabian Frederick <[email protected]>
---
fs/squashfs/file_direct.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c
index 62a0de6..e9f9cf2 100644
--- a/fs/squashfs/file_direct.c
+++ b/fs/squashfs/file_direct.c
@@ -44,7 +44,7 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize)

pages = end_index - start_index + 1;

- page = kmalloc(sizeof(void *) * pages, GFP_KERNEL);
+ page = kcalloc(pages, sizeof(void *), GFP_KERNEL);
if (page == NULL)
return res;

--
1.8.4.5


2014-06-16 18:37:51

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 1/1] fs/squashfs/file_direct.c: replace count*size kmalloc by kcalloc

On Mon, 2014-06-16 at 20:12 +0200, Fabian Frederick wrote:
> kcalloc manages count*sizeof overflow.

so does kmalloc_array

> diff --git a/fs/squashfs/file_direct.c b/fs/squashfs/file_direct.c
[]
> - page = kmalloc(sizeof(void *) * pages, GFP_KERNEL);
> + page = kcalloc(pages, sizeof(void *), GFP_KERNEL);


kmalloc(a * sizeof(b), GFP) -> kmalloc_array(a, sizeof(b), GFP)
kzalloc(a * sizeof(b), GFP) -> kcalloc(a, sizeof(b), GFP)