From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08D61ECAAD3 for ; Mon, 19 Sep 2022 17:22:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 294286B0071; Mon, 19 Sep 2022 13:22:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2433B6B0072; Mon, 19 Sep 2022 13:22:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 10CA7940007; Mon, 19 Sep 2022 13:22:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0163A6B0071 for ; Mon, 19 Sep 2022 13:22:57 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C25F1140686 for ; Mon, 19 Sep 2022 17:22:57 +0000 (UTC) X-FDA: 79929505194.11.29957F8 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf31.hostedemail.com (Postfix) with ESMTP id 6C28720008 for ; Mon, 19 Sep 2022 17:22:56 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E3A31B81247; Mon, 19 Sep 2022 17:22:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B5B8C433D6; Mon, 19 Sep 2022 17:22:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663608173; bh=HQIglUDLQBaVF3vEx2t8CopF+c8dwQhHTb2AFxrgu3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cv58B3MTc5nooSeZ9Qg1zHKNeXUqEIGH1PDfcEBDT9ZrVx8Rps0eTWEhDjl/WApmd Jkb3WSKtiQBsPBPGn7fZ9/3C2okpojKRa9Rkc9tLvwYdSREFXA74/mB67mujbBBpMQ sjz9o1utC+J0Cmu+DLwJN+/MFZBq0+Ed95XWkP7D+T7LmltXLzxTsz8olcNEQ8u4XD EW0Vd4aj3mYE9eT/jNvNi1vOs1xJWOA71NKadjoBr14D/QIe6KIYtwh4H6MQAQ0eTH gfIOOyxcRtkvnY0Ii2OyQV9QhirDOxWsQkfDDU4+PTK0ARp4NU36auS4CQHmQaMC4A dpWYps+/xMzmg== From: SeongJae Park To: Xin Hao Cc: sj@kernel.org, akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 2/2] mm/damon/sysfs: use kzmalloc instead kmalloc to simplify codes Date: Mon, 19 Sep 2022 17:22:51 +0000 Message-Id: <20220919172251.61428-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220919151201.66696-2-xhao@linux.alibaba.com> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663608176; a=rsa-sha256; cv=none; b=Qrgj2DOchdIPEivyKA8fWp09flEaDDzJB4r7bq7VHvB9A8K7E7pNJ0W1VSnFrUxvHdY9DT JsCOhe9vntN1pOuvCaknP/GUiy0eElJVob9D0+TCFKobVIpc3HLzoGwbBf163IRp34bm79 ZHzAY/F4Exe6IunN3R6t3vsfvE2d89w= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cv58B3MT; spf=pass (imf31.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663608176; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3t7QZPDNrIkkSJCMZMjXVsN1yuxK7fqDr5IEVuNwOUM=; b=Qw1F+Z9M1aA30tL1s1OC3XqhyLk8rNI/Khagyp7rbf88dsH5tOV2joiYrLe45TVnU7PPnF LVM2n43yZjhvdKLAGZJTXaO3UmanBJPw2Nj0Wha8z/VveBQm0WWxUq0L8TysnrSbbFpIqe VXfiTSc8g6QXFfYca3VcM/sJMukV3Wg= X-Stat-Signature: etufgxc6zd46on4wo4agp8tfgyyaxbg1 X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=cv58B3MT; spf=pass (imf31.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6C28720008 X-HE-Tag: 1663608176-313378 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, 19 Sep 2022 23:12:01 +0800 Xin Hao wrote: > 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. This definitely makes the code cleaner, thank you. But, the initial intent of the code is to initialize the fiedls that really need to be initialized at the point, for the efficiency and also for making it clear which field is needed to be initialized to what value here. It's also intended to make readers wonder about where and how the remaining fields are initialized. So, to my humble eyes, this change looks like making the code a little bit inefficient and unclear, sorry. Thanks, SJ > > Signed-off-by: Xin Hao > --- > 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