From patchwork Mon Oct 24 20:49:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 10360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp683906wru; Mon, 24 Oct 2022 15:36:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54eD2xQ3npru9EaekLj1kJeUNfWzl5at3nhPToj9qZDE/+4AyrWkVtemDgQIQ2hwHqge09 X-Received: by 2002:a17:907:3e85:b0:73d:60cc:5d06 with SMTP id hs5-20020a1709073e8500b0073d60cc5d06mr30529120ejc.722.1666650966030; Mon, 24 Oct 2022 15:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666650966; cv=none; d=google.com; s=arc-20160816; b=cNAA3e+kJkhxGA3/U0r9zqxThwwqXwrmzapt4m/ZxRvMgKyrFK8Pbz7IS0d+Sej6aL d3zZNAcc7G+bylkJDdgEmiQhGATnKDjDLaRfR0LaSe9NgLZoA+zgtW+0C0VzYrl9gaCW 3FQPk5nQKCkpF95hHq61TCC7vb4TfFT1R0PhA+/ojuGhfmccVVn+PX2zmP1diEJQDowp KxlBXX1NyHwgv+iWe+SfulA902LcnL2FmaX8y+ZUl24Y68gIdo/FpkcldjDmF5ql6J4O LxTGCKvzKBS8SqUd+lohN2jcHaLfHLjnRgeYsg0S/K2TSXQGGjBEeW4ydgjYPpqRdH4H w6/w== 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=7n+YCXhSActcFsJQM+bMjwhqitqXcBT33KamBQXu4Hs=; b=jEusl3VfSgIikJpM8coXH/jY1zvjgqvRZuKDkL3Mdc69I4aJ1L7GpDHpcK40a3BXMB UJDyOrWcATvzN7COmYsEYIruXzRVKyVelio/7dV3SDkNdK0R5RHkQzeSgQVX9wl+CRo2 hiUAJmnFRQH5O930rSCC3WJQ3Cg/KSKe5G64Jp10wLPa4/RY+GQlvCaR6Fxyf8LDKm0g y39dG3oWWH708vUCWr5QW6ihLi/Kss9UtbqXNCaUH7IsNnsS2HztiDUYrClSE0zudJXf R58obIhr9t0OaL7okswcxhzH2H//hfXxqQrOJiL0I7OHZ8OhyFW86khB/gLDdPdm6XzX q+ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YDdPWy+h; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r7-20020a50d687000000b00459039258b2si1007619edi.289.2022.10.24.15.35.42; Mon, 24 Oct 2022 15:36:06 -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=YDdPWy+h; 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 S230313AbiJXW3t (ORCPT + 99 others); Mon, 24 Oct 2022 18:29:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231667AbiJXW3O (ORCPT ); Mon, 24 Oct 2022 18:29:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C954319CF9 for ; Mon, 24 Oct 2022 13:51:25 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 81606615A8 for ; Mon, 24 Oct 2022 20:49:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94284C43470; Mon, 24 Oct 2022 20:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666644568; bh=sv1BrnKGZiPaDlM88kZTZVyO+ljEIr4/QgXhQUY8YPk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YDdPWy+hk/dA6bO1JvIxHQEsUadklBlUEuvRHSxp8TUizL8iK7lQE+1JK5yx3EiBJ DIY+QpAeB1tdtqIcxsIwmwDIWQjNvZ9nwue1mo4qgY/I5jWfHjH56yu7xsSaYmgGb4 PQiwORUnIyXxcyX7K9EGsZ5wIZaBqrDaXiTF4QTavo3eoUVdhk7sjt5c5jOTcvsTLC SMcKFOiF8eqBqt7LICtCoXlPK5r0ai0fjcWL/O+XsGrZI0Ytwmxk4HbEOAsDeeDQPt TRaZn2P/ZnGqu/bRmAxiTM+OvV6/f2fnCMfE6qG0nbrjgqs+H9ICKjlRuHQSNbYGwS 3I03m0XNVTL7w== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/11] mm/damon/sysfs: use damon_addr_range for regions' start and end values Date: Mon, 24 Oct 2022 20:49:13 +0000 Message-Id: <20221024204919.18524-6-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221024204919.18524-1-sj@kernel.org> References: <20221024204919.18524-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747610203843479820?= X-GMAIL-MSGID: =?utf-8?q?1747610203843479820?= DAMON has a struct for each address range but DAMON sysfs interface is using the low type (unsigned long) for storing the start and end addresses of regions. Use the dedicated struct for better type safety. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 9f1219a67e3f..b9183063bfea 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -1062,13 +1062,11 @@ static struct kobj_type damon_sysfs_schemes_ktype = { struct damon_sysfs_region { struct kobject kobj; - unsigned long start; - unsigned long end; + struct damon_addr_range ar; }; static struct damon_sysfs_region *damon_sysfs_region_alloc( - unsigned long start, - unsigned long end) + struct damon_addr_range ar) { struct damon_sysfs_region *region = kmalloc(sizeof(*region), GFP_KERNEL); @@ -1076,8 +1074,7 @@ static struct damon_sysfs_region *damon_sysfs_region_alloc( if (!region) return NULL; region->kobj = (struct kobject){}; - region->start = start; - region->end = end; + region->ar = ar; return region; } @@ -1087,7 +1084,7 @@ static ssize_t start_show(struct kobject *kobj, struct kobj_attribute *attr, struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - return sysfs_emit(buf, "%lu\n", region->start); + return sysfs_emit(buf, "%lu\n", region->ar.start); } static ssize_t start_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -1095,7 +1092,7 @@ static ssize_t start_store(struct kobject *kobj, struct kobj_attribute *attr, { struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - int err = kstrtoul(buf, 0, ®ion->start); + int err = kstrtoul(buf, 0, ®ion->ar.start); return err ? err : count; } @@ -1106,7 +1103,7 @@ static ssize_t end_show(struct kobject *kobj, struct kobj_attribute *attr, struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - return sysfs_emit(buf, "%lu\n", region->end); + return sysfs_emit(buf, "%lu\n", region->ar.end); } static ssize_t end_store(struct kobject *kobj, struct kobj_attribute *attr, @@ -1114,7 +1111,7 @@ static ssize_t end_store(struct kobject *kobj, struct kobj_attribute *attr, { struct damon_sysfs_region *region = container_of(kobj, struct damon_sysfs_region, kobj); - int err = kstrtoul(buf, 0, ®ion->end); + int err = kstrtoul(buf, 0, ®ion->ar.end); return err ? err : count; } @@ -1187,7 +1184,7 @@ static int damon_sysfs_regions_add_dirs(struct damon_sysfs_regions *regions, regions->regions_arr = regions_arr; for (i = 0; i < nr_regions; i++) { - region = damon_sysfs_region_alloc(0, 0); + region = damon_sysfs_region_alloc((struct damon_addr_range){}); if (!region) { damon_sysfs_regions_rm_dirs(regions); return -ENOMEM; @@ -2147,11 +2144,11 @@ static int damon_sysfs_set_regions(struct damon_target *t, struct damon_sysfs_region *sys_region = sysfs_regions->regions_arr[i]; - if (sys_region->start > sys_region->end) + if (sys_region->ar.start > sys_region->ar.end) goto out; - ranges[i].start = sys_region->start; - ranges[i].end = sys_region->end; + ranges[i].start = sys_region->ar.start; + ranges[i].end = sys_region->ar.end; if (i == 0) continue; if (ranges[i - 1].end > ranges[i].start)