Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2868577rwb; Mon, 19 Sep 2022 11:10:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4uAbbuGXsn4vjyWCQTidncz766c5pTX/aPoFgstCE5taHGOZMITRZmGw5dvKV8yAtwSX/x X-Received: by 2002:a17:902:c189:b0:176:b871:8a1 with SMTP id d9-20020a170902c18900b00176b87108a1mr986921pld.30.1663611009657; Mon, 19 Sep 2022 11:10:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663611009; cv=none; d=google.com; s=arc-20160816; b=PJWH/zgt+z2ftK7DjrtOXnq0gUY2KnoVk9HNpCTLkw0Ngs/HLe5/ZuUOr3PGaIljsC c14IcvbBI6gTuCTNhUgi8Gj7ZIvddmsAKKarm2d8W2XzVo9ahUs/mAUtlwRaYa9TncJO daNFEI9zqKmw6HLTTsPy7pVz/5VUl+FGGoaE3vWfLIFfnEnqQct8xkl0sCG18TAsowvV Y7+RGG064iUISJt5ccElKfNUnEn1/5WGmgl7z/b22qRLSakHxf/+ADyhyUq8UnAQyQyI CKoJ3Rg1xMfaiYLqV/sUx2f6HaEAKmRV82Q4GxPqklCjwtxwUxQeCD15Iib1LfqxZMJU iQMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3t7QZPDNrIkkSJCMZMjXVsN1yuxK7fqDr5IEVuNwOUM=; b=Hw8SIFq0zSqpLW17fPfQPq7JlLeb6yyb0W1B2HVBj91JYFkNMpbiwmR22Fx+mqeC8S Txwy3aI2CrjipS65kevyJe+lanKTmLEibUJl7nYzNYO1ZUN10xOO/9ocAbkW8ocVbtzP XETAnvyxjDbYaF5ern0z1u7iwv/5U7TsI8sqDUHRvJrA6JtGUqONCFChNNVBiGRCqMbU jrLjvkhW9MNsA+ojRzytze5Wg+BvX7tjVxF8EQjuNswkAW6O6ZwBb7zMJr9yUiK5QnNE ETgjdyf8HSJHtrpkyy0cfLSw1XxfB0XtiqPRzzkh+Af+DE2+JwFYv4E1ypewnMyclRvj jbnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cv58B3MT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a631f10000000b00439ae523fd2si391899pgf.289.2022.09.19.11.09.57; Mon, 19 Sep 2022 11:10:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cv58B3MT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230158AbiISRW7 (ORCPT + 99 others); Mon, 19 Sep 2022 13:22:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229617AbiISRW5 (ORCPT ); Mon, 19 Sep 2022 13:22:57 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35AB43A48A for ; Mon, 19 Sep 2022 10:22:56 -0700 (PDT) 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 DF18DB8069D for ; 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 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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