aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSu Hui <[email protected]>2025-04-21 06:24:24 +0000
committerAndrew Morton <[email protected]>2025-05-13 06:50:45 +0000
commitee43f26b49e9ddad0f06c149085343613a9d73a4 (patch)
tree620ca3824813710321c7636797d220b62531f43a
parentmm: workingset: simplify lockdep check in update_node (diff)
downloadkernel-ee43f26b49e9ddad0f06c149085343613a9d73a4.tar.gz
kernel-ee43f26b49e9ddad0f06c149085343613a9d73a4.zip
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]>
-rw-r--r--mm/damon/sysfs-schemes.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
index 729fe5f1ef30..c2b8a9cb44ec 100644
--- a/mm/damon/sysfs-schemes.c
+++ b/mm/damon/sysfs-schemes.c
@@ -465,7 +465,8 @@ static ssize_t memcg_path_store(struct kobject *kobj,
{
struct damon_sysfs_scheme_filter *filter = container_of(kobj,
struct damon_sysfs_scheme_filter, kobj);
- char *path = kmalloc(sizeof(*path) * (count + 1), GFP_KERNEL);
+ char *path = kmalloc_array(size_add(count, 1), sizeof(*path),
+ GFP_KERNEL);
if (!path)
return -ENOMEM;
@@ -2064,7 +2065,7 @@ static int damon_sysfs_memcg_path_to_id(char *memcg_path, unsigned short *id)
if (!memcg_path)
return -EINVAL;
- path = kmalloc(sizeof(*path) * PATH_MAX, GFP_KERNEL);
+ path = kmalloc_array(PATH_MAX, sizeof(*path), GFP_KERNEL);
if (!path)
return -ENOMEM;