Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1705733iob; Fri, 29 Apr 2022 10:52:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvCGjncKfIXCbbhHzE8DQPSapq4pBCZxrgtVfGchhXWLwSnMgcjGjXytAwG3QH9sod7/Y5 X-Received: by 2002:a19:2d57:0:b0:472:1867:79f9 with SMTP id t23-20020a192d57000000b00472186779f9mr246508lft.483.1651254763817; Fri, 29 Apr 2022 10:52:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651254763; cv=none; d=google.com; s=arc-20160816; b=SFwigmeMuiFUMrotS04k9B15EX/BiWURjW7nOM2jfh8OMn5mYBlojHUgnKFn2yY4A+ a3/e1gqIHT/EKLvj99FfYXK8J/9yafy6/Ec7Kv93xtJZS8etGSOoMiPeeTljQI3+f2A8 Bk1Aro2FMGG5QZjs+UZI47ZtoXtvCEf+Ur2UR/9s+XhFh3bXLsqoWMCLnjzBtkZ5l3Pr tINXcYEZ2th/VpliQ/YILYJ6PeR5wxR8trK9Dpqrhnkvk1lIdy4U/UanocCuSCr4g/ZY tk79fdxGg39/vZlbzovMtLxdBDnLd5hHTbvKPZIRglKBKFMSMXmlD8AMJbYSeh/1HnP7 gFIg== 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=MM73vho4bEOItkkjU/oVvcYqmudpfgwzxPfSKdIB5Z0=; b=DxYHuCf4TGnuM8b5tZ0xHhpIVkkbKiEUkvK6TpbfMHwKfsQF25jSeoy3P0FN4FvvdM czf21F2RMOTnLsgEme+YI+kKpHtunS0KG/ncGRNKC6fuW8Lee74IEfazUKAuUI9pDVef VPi6XExjB+LXQjBQAjsPolTh9/SieWN8YgLjf9cf4X4OLUITru5ihIueBMx7GdPGkpxb Uwhbw2+hJODNfhZQPpFij9Yj8eYh1UrrOg1A6p/Tu1nifscMDSq7rSdgbe6kOuyYl1fr b3dWtNdGDiiL+54JZ5OYAK7g0n8q6qMYgSFb4g6xFWTeYQuWzPMR/QT6qnR0cANKX1Yk doZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OJBRW49W; 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 e17-20020a05651c04d100b0024f312799fdsi6507212lji.582.2022.04.29.10.52.16; Fri, 29 Apr 2022 10:52:43 -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=OJBRW49W; 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 S1378904AbiD2QKL (ORCPT + 99 others); Fri, 29 Apr 2022 12:10:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378827AbiD2QJj (ORCPT ); Fri, 29 Apr 2022 12:09:39 -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 CFEEBA7766 for ; Fri, 29 Apr 2022 09:06:20 -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 4CDBF622B1 for ; Fri, 29 Apr 2022 16:06:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B39E6C385B2; Fri, 29 Apr 2022 16:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651248380; bh=5YMNTMsgfge8ubKXp7EhKpr2TL9m6guiVctUmtgprC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OJBRW49WESwGwEdpEAB5f/EIx6t8TTqQTTGFRq80FMowxFxMpMTuFpW3pdSo/Qh+3 gx1vbm1C9d8sh1hSOX7a9XDM7KACYx5c7lXTVc8pSCg/vGpKnRvlYs+7pMNhluTazQ QtQ7RgTdR4KHxzvD+GcRuSxFio72EL7GiTVwqv7DT1fv8WQqdLeJy1sg1v6452zR7f xhfqBWSwyhvZiSNfiNj0fIyj8XPG2+sQmR54VFU0cFztw1alugFZnQO0uz7RYQj+/J xYQRiS2iyfQijMDqkIL8qMhikKGiee8PWGjHG30yUh+xs9KfJXgyHpK9AYmm2XTV4H lDW22HdPZkt7w== From: sj@kernel.org To: akpm@linux-foundation.org Cc: linux-damon@amazon.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 08/14] mm/damon/sysfs: reuse damon_set_regions() for regions setting Date: Fri, 29 Apr 2022 16:06:00 +0000 Message-Id: <20220429160606.127307-9-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220429160606.127307-1-sj@kernel.org> References: <20220429160606.127307-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 From: SeongJae Park 'damon_set_regions()' is general enough so that it can also be used for only creating regions. This commit makes DAMON sysfs interface to reuse the function rather keeping two implementations for a same purpose. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 331647ab6396..0d6cb9b5bd5b 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2095,28 +2095,31 @@ static void damon_sysfs_destroy_targets(struct damon_ctx *ctx) static int damon_sysfs_set_regions(struct damon_target *t, struct damon_sysfs_regions *sysfs_regions) { - int i; + struct damon_addr_range *ranges = kmalloc_array(sysfs_regions->nr, + sizeof(*ranges), GFP_KERNEL | __GFP_NOWARN); + int i, err = -EINVAL; + if (!ranges) + return -ENOMEM; for (i = 0; i < sysfs_regions->nr; i++) { struct damon_sysfs_region *sys_region = sysfs_regions->regions_arr[i]; - struct damon_region *prev, *r; if (sys_region->start > sys_region->end) - return -EINVAL; - r = damon_new_region(sys_region->start, sys_region->end); - if (!r) - return -ENOMEM; - damon_add_region(r, t); - if (damon_nr_regions(t) > 1) { - prev = damon_prev_region(r); - if (prev->ar.end > r->ar.start) { - damon_destroy_region(r, t); - return -EINVAL; - } - } + goto out; + + ranges[i].start = sys_region->start; + ranges[i].end = sys_region->end; + if (i == 0) + continue; + if (ranges[i - 1].end > ranges[i].start) + goto out; } - return 0; + err = damon_set_regions(t, ranges, sysfs_regions->nr); +out: + kfree(ranges); + return err; + } static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target, -- 2.25.1