projects
/
linux-2.6-microblaze.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
551c643
)
mm/damon/sysfs-schemes: use kmalloc_array() and size_add()
author
Su Hui
<suhui@nfschina.com>
Mon, 21 Apr 2025 06:24:24 +0000
(14:24 +0800)
committer
Andrew Morton
<akpm@linux-foundation.org>
Tue, 13 May 2025 06:50:45 +0000
(23:50 -0700)
It's safer to use kmalloc_array() and size_add() because it can prevent
possible overflow problem.
Link:
https://lkml.kernel.org/r/20250421062423.740605-1-suhui@nfschina.com
Signed-off-by: Su Hui <suhui@nfschina.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/damon/sysfs-schemes.c
patch
|
blob
|
history
diff --git
a/mm/damon/sysfs-schemes.c
b/mm/damon/sysfs-schemes.c
index
729fe5f
..
c2b8a9c
100644
(file)
--- 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;