From: Xin Hao <xhao@linux.alibaba.com>
To: sj@kernel.org
Cc: akpm@linux-foundation.org, damon@lists.linux.dev,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
xhao@linux.alibaba.com
Subject: [PATCH v1 2/2] mm/damon/sysfs: use kzmalloc instead kmalloc to simplify codes
Date: Mon, 19 Sep 2022 23:12:01 +0800 [thread overview]
Message-ID: <20220919151201.66696-2-xhao@linux.alibaba.com> (raw)
In-Reply-To: <20220919151201.66696-1-xhao@linux.alibaba.com>
In damon_sysfs_access_pattern_alloc() adn damon_sysfs_attrs_alloc(),
we can use kzmalloc to alloc instance of the related structs, This makes
the function code much cleaner.
Signed-off-by: Xin Hao <xhao@linux.alibaba.com>
---
mm/damon/sysfs.c | 15 ++-------------
1 file changed, 2 insertions(+), 13 deletions(-)
diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index b852a75b9f39..06154ece7960 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -657,13 +657,7 @@ struct damon_sysfs_access_pattern {
static
struct damon_sysfs_access_pattern *damon_sysfs_access_pattern_alloc(void)
{
- struct damon_sysfs_access_pattern *access_pattern =
- kmalloc(sizeof(*access_pattern), GFP_KERNEL);
-
- if (!access_pattern)
- return NULL;
- access_pattern->kobj = (struct kobject){};
- return access_pattern;
+ return kzalloc(sizeof(struct damon_sysfs_access_pattern), GFP_KERNEL);
}
static int damon_sysfs_access_pattern_add_range_dir(
@@ -1620,12 +1614,7 @@ struct damon_sysfs_attrs {
static struct damon_sysfs_attrs *damon_sysfs_attrs_alloc(void)
{
- struct damon_sysfs_attrs *attrs = kmalloc(sizeof(*attrs), GFP_KERNEL);
-
- if (!attrs)
- return NULL;
- attrs->kobj = (struct kobject){};
- return attrs;
+ return kzalloc(sizeof(struct damon_sysfs_attrs), GFP_KERNEL);
}
static int damon_sysfs_attrs_add_dirs(struct damon_sysfs_attrs *attrs)
--
2.31.0
next prev parent reply other threads:[~2022-09-19 15:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-19 15:12 [PATCH v1 1/2] mm/damon/sysfs: remove unnecessary variables Xin Hao
2022-09-19 15:12 ` Xin Hao [this message]
2022-09-19 17:22 ` [PATCH v1 2/2] mm/damon/sysfs: use kzmalloc instead kmalloc to simplify codes SeongJae Park
2022-09-20 1:58 ` haoxin
2022-09-20 16:25 ` SeongJae Park
2022-09-21 5:20 ` haoxin
2022-09-19 17:03 ` [PATCH v1 1/2] mm/damon/sysfs: remove unnecessary variables SeongJae Park
2022-09-20 1:54 ` haoxin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220919151201.66696-2-xhao@linux.alibaba.com \
--to=xhao@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=damon@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=sj@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).