Skip to content

Commit ee43f26

Browse files
Su Huiakpm00
authored andcommitted
mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
It's safer to use kmalloc_array() and size_add() because it can prevent possible overflow problem. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Su Hui <[email protected]> Reviewed-by: SeongJae Park <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 551c643 commit ee43f26

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mm/damon/sysfs-schemes.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,8 @@ static ssize_t memcg_path_store(struct kobject *kobj,
465465
{
466466
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
467467
struct damon_sysfs_scheme_filter, kobj);
468-
char *path = kmalloc(sizeof(*path) * (count + 1), GFP_KERNEL);
468+
char *path = kmalloc_array(size_add(count, 1), sizeof(*path),
469+
GFP_KERNEL);
469470

470471
if (!path)
471472
return -ENOMEM;
@@ -2064,7 +2065,7 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)
20642065
if (!memcg_path)
20652066
return -EINVAL;
20662067

2067-
path = kmalloc(sizeof(*path) * PATH_MAX, GFP_KERNEL);
2068+
path = kmalloc_array(PATH_MAX, sizeof(*path), GFP_KERNEL);
20682069
if (!path)
20692070
return -ENOMEM;
20702071

0 commit comments

Comments
 (0)