From patchwork Sat Mar 30 17:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dev Jain X-Patchwork-Id: 13611623 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 B75D0CD1288 for ; Sat, 30 Mar 2024 17:37:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34AD06B0087; Sat, 30 Mar 2024 13:37:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FB726B0088; Sat, 30 Mar 2024 13:37:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C3256B0089; Sat, 30 Mar 2024 13:37:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F1D806B0087 for ; Sat, 30 Mar 2024 13:37:50 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B5A0840189 for ; Sat, 30 Mar 2024 17:37:50 +0000 (UTC) X-FDA: 81954413100.13.D194BDF Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 451142000E for ; Sat, 30 Mar 2024 17:37:49 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711820269; 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; bh=8c0uUObWm0hvYQbz6NLtxGEuA7R6BgUnr5sLFNNiplE=; b=DUnYRE4a9pW/Gkon9nPgHweMp8U7a2PQNRt9L42f5Sis8+iAnjs7+yeXpjHuX1QWi/0MD4 vNBUIp+uFfi0LTRYCQ6K51Tb00puxYCiHQcPmN27jFe+0yilrOioN4Zx2oFVBVDbuucKfP +2O8AHCPsr7lACqCoT0N6cUm+i6MLic= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf03.hostedemail.com: domain of dev.jain@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=dev.jain@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711820269; a=rsa-sha256; cv=none; b=MbkWJ0nQvCLjhSsooA4CJdQrshNkFTX52H9NFGXKJfxBIDyGBhIpaajdj1ubseLy3hrWsS BTTbPC49UMLih2YYfuH53iCg9zQLWER5N3Ggqn47CPDHwEyvZlTpLnJS5ARwZpCYfNdfR0 KfgrhmRzgr8eNVyMNAmOqEN7IWPosiU= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68863106F; Sat, 30 Mar 2024 10:38:21 -0700 (PDT) Received: from e116581.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9E2183F7B4; Sat, 30 Mar 2024 10:37:44 -0700 (PDT) From: Dev Jain To: akpm@linux-foundation.org Cc: shuah@kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kaleshsingh@google.com, jhubbard@nvidia.com, Anshuman.Khandual@arm.com, Dev Jain Subject: [PATCH 3/3] selftests/mm: mremap_test: Use sscanf to parse /proc/self/maps Date: Sat, 30 Mar 2024 23:05:57 +0530 Message-Id: <20240330173557.2697684-4-dev.jain@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240330173557.2697684-1-dev.jain@arm.com> References: <20240330173557.2697684-1-dev.jain@arm.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 451142000E X-Stat-Signature: yrfoyrk5ru54c47zoxskn9rjsgzbdct5 X-Rspam-User: X-HE-Tag: 1711820269-617688 X-HE-Meta: U2FsdGVkX1/RKMQGGf0OLqGdBKTyOtaKCyqMnBOtEgGBk60t6EmF7taAVtEoJ/WUpf8Xvfp5BXfn2f20QmmfRNqL7uCtkyEUxXROguesywDZjeHFqUeJTTQyId1oHoKHsLR+porBC9Ip0d5JVl8PlJCG//oU9oRpbcHOMkTCgBcCow7b8BlhGoI/K+bL/0W7sy5ET1yg0tn32bPpvNr0E63v8diGZFbOECcWJKAOqkd/KIr525dvrGGmQefHeiUqOzRHwHfvuZOGbAHV6pTJUpjP6lz6Ds/kv9xvT3JBVyLKMi9kEBLo9V3THj2YOYHFn9ZYnzVn+F/JlfHfcikmkt24RISh4lVqZuDoVbGpvj0XWdhOsA9lDT/ZYJY6P7t+N5LEK3bmEFVIlGPKH9/wTOA+pm4oRmF9Rp54GRAfNUyd9EDbi7eZfjfMFRMM0FIrz1UjMxaAdooKbe/oDvyxECLeIkVQ69CmK8jx+xqiMXZzxoF0CSjwyHwa5gznwNuyYLdi9bzxYeEJPop2hGgHaQqeYG2VDCCFvwwmhMyASohB/6y4lbqeqmFHoOJkswlHRD39W5wAx9FQz5Whb0fjJqab+WZvrw6DHcMHF+FdVzfqagfvF1KsyYLJqj4qxPcGKSW6emEhG0+qTixKzQ8rJZQhn3KvcVPYOfy7NjlkfyA2YYdIW+XA/srefbWnCucb0gPD6FDk7TRALighD38CzDlpMBmjASTaf9XL74YfhESqQP7c7BqPwbg6mdx321KSmRCacI+YJeDI1/qWoe+ELk/xH5YP5rv19h8WXlZwVpjsUxFs2uNWAWqXKrtksmLTxA4/bD8HpDLDJyE0HAH14+6G6TleWgIfbGph1EBp0DjuNTKuz1JzSF+SpOm/NTiBWDFEJZhKecA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Enforce consistency across files by avoiding two separate functions to parse /proc/self/maps, replacing them with a simple sscanf(). Signed-off-by: Dev Jain --- tools/testing/selftests/mm/mremap_test.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_test.c b/tools/testing/selftests/mm/mremap_test.c index 678c79d5b8ef..1b03bcfaefdf 100644 --- a/tools/testing/selftests/mm/mremap_test.c +++ b/tools/testing/selftests/mm/mremap_test.c @@ -148,19 +148,21 @@ static unsigned long long get_mmap_min_addr(void) * Using /proc/self/maps, assert that the specified address range is contained * within a single mapping. */ -static bool is_range_mapped(FILE *maps_fp, void *start, void *end) +static bool is_range_mapped(FILE *maps_fp, unsigned long start, + unsigned long end) { char *line = NULL; size_t len = 0; bool success = false; + unsigned long first_val, second_val; rewind(maps_fp); while (getline(&line, &len, maps_fp) != -1) { - char *first = strtok(line, "- "); - void *first_val = (void *)strtol(first, NULL, 16); - char *second = strtok(NULL, "- "); - void *second_val = (void *) strtol(second, NULL, 16); + if (sscanf(line, "%lx-%lx", &first_val, &second_val) != 2) { + ksft_exit_fail_msg("cannot parse /proc/self/maps\n"); + break; + } if (first_val <= start && second_val >= end) { success = true; @@ -255,7 +257,8 @@ static void mremap_expand_merge(FILE *maps_fp, unsigned long page_size) goto out; } - success = is_range_mapped(maps_fp, start, start + 3 * page_size); + success = is_range_mapped(maps_fp, (unsigned long)start, + (unsigned long)(start + 3 * page_size)); munmap(start, 3 * page_size); out: @@ -294,7 +297,8 @@ static void mremap_expand_merge_offset(FILE *maps_fp, unsigned long page_size) goto out; } - success = is_range_mapped(maps_fp, start, start + 3 * page_size); + success = is_range_mapped(maps_fp, (unsigned long)start, + (unsigned long)(start + 3 * page_size)); munmap(start, 3 * page_size); out: