From patchwork Fri Apr 29 16:05:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12832418 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 AD867C433F5 for ; Fri, 29 Apr 2022 16:06:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAE566B0083; Fri, 29 Apr 2022 12:06:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C10B36B0085; Fri, 29 Apr 2022 12:06:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8B416B0087; Fri, 29 Apr 2022 12:06:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 91E7E6B0083 for ; Fri, 29 Apr 2022 12:06:21 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 7523260653 for ; Fri, 29 Apr 2022 16:06:21 +0000 (UTC) X-FDA: 79410393762.11.8A3467C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 52DC8A001B for ; Fri, 29 Apr 2022 16:06:14 +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 dfw.source.kernel.org (Postfix) with ESMTPS id A8E0D622B4; Fri, 29 Apr 2022 16:06:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AB0DC385AE; 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=1651248379; bh=rAJFo4AjkW8JUKTUipbjPgtkusxOnV1JhWTxgwk0hVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZWCcY7gjW5kSeyS4THWs03LOnctZNxnQvXDMTxoSnrcazYhHkcu0sOxrCp8xCnmYy OOAzLhZ2bqE1tW7NeiM1KqxENbWGfSOM+wut3ERMm03w9ev51THCCvMQUbkPKyQhR9 vlPML/uWh/HfM6vrl4+FuiLEQ1P440n4qD1nuf8Ww+C/PToaAVk0w0YAiIwmOYINcS a1xZGmcXg1lY7LdPFUZl/mwcmXrWUXS9PEatHqLsd2WwNwtZ/7ovRdnSQ82dhWZTdY PSl0IYmksN/WSH46PE8qoQDCMZVyEFpJ128uRtjsWmM1FvPdDMNU6/DvCGr/XyhGLJ T7usRn80m+WoA== 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 07/14] mm/damon/sysfs: move targets setup code to a separated function Date: Fri, 29 Apr 2022 16:05:59 +0000 Message-Id: <20220429160606.127307-8-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 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZWCcY7gj; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf15.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 52DC8A001B X-Rspam-User: X-Stat-Signature: 6q1an75ub1weiiqsdozzwg8ezesn5o4e X-HE-Tag: 1651248374-304426 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: From: SeongJae Park This commit separates DAMON sysfs interface's monitoring context targets setup code to a new function for better readability. Signed-off-by: SeongJae Park --- mm/damon/sysfs.c | 49 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c index 988247d35862..331647ab6396 100644 --- a/mm/damon/sysfs.c +++ b/mm/damon/sysfs.c @@ -2119,6 +2119,31 @@ static int damon_sysfs_set_regions(struct damon_target *t, return 0; } +static int damon_sysfs_add_target(struct damon_sysfs_target *sys_target, + struct damon_ctx *ctx) +{ + struct damon_target *t = damon_new_target(); + int err = -EINVAL; + + if (!t) + return -ENOMEM; + if (ctx->ops.id == DAMON_OPS_VADDR || + ctx->ops.id == DAMON_OPS_FVADDR) { + t->pid = find_get_pid(sys_target->pid); + if (!t->pid) + goto destroy_targets_out; + } + damon_add_target(ctx, t); + err = damon_sysfs_set_regions(t, sys_target->regions); + if (err) + goto destroy_targets_out; + return 0; + +destroy_targets_out: + damon_sysfs_destroy_targets(ctx); + return err; +} + static int damon_sysfs_set_targets(struct damon_ctx *ctx, struct damon_sysfs_targets *sysfs_targets) { @@ -2129,28 +2154,10 @@ static int damon_sysfs_set_targets(struct damon_ctx *ctx, return -EINVAL; for (i = 0; i < sysfs_targets->nr; i++) { - struct damon_sysfs_target *sys_target = - sysfs_targets->targets_arr[i]; - struct damon_target *t = damon_new_target(); - - if (!t) { - damon_sysfs_destroy_targets(ctx); - return -ENOMEM; - } - if (ctx->ops.id == DAMON_OPS_VADDR || - ctx->ops.id == DAMON_OPS_FVADDR) { - t->pid = find_get_pid(sys_target->pid); - if (!t->pid) { - damon_sysfs_destroy_targets(ctx); - return -EINVAL; - } - } - damon_add_target(ctx, t); - err = damon_sysfs_set_regions(t, sys_target->regions); - if (err) { - damon_sysfs_destroy_targets(ctx); + err = damon_sysfs_add_target( + sysfs_targets->targets_arr[i], ctx); + if (err) return err; - } } return 0; }