From patchwork Mon Sep 20 10:01:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12505033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E2DDC433EF for ; Mon, 20 Sep 2021 10:01:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D0B5160F4B for ; Mon, 20 Sep 2021 10:01:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D0B5160F4B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 3EEE3900003; Mon, 20 Sep 2021 06:01:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 39EFB900002; Mon, 20 Sep 2021 06:01:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28E27900003; Mon, 20 Sep 2021 06:01:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 174D6900002 for ; Mon, 20 Sep 2021 06:01:38 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B1ADF181AEF2A for ; Mon, 20 Sep 2021 10:01:37 +0000 (UTC) X-FDA: 78607509834.07.0372159 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf24.hostedemail.com (Postfix) with ESMTP id 5C144B00009D for ; Mon, 20 Sep 2021 10:01:37 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 26C2260240; Mon, 20 Sep 2021 10:01:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632132096; bh=4gD2TQrQ9ZQPtwTDSOABdc4IqZHTrav1yleSQy9Mgsg=; h=From:To:Cc:Subject:Date:From; b=OlPgtVP0ASanA3SKCfhRBq5E40+FCybrysC/24NG3R047YblWuao+S4eIPN4P9GnM otbP72YvfPrmvSKSTEhDpObFdm3hz8SP2mQBaZ52ZDsT+xkwD0CbvF60eueSY71SJp HdBFgM926vdsfrBjvC3MKGZCSdVcGhBtmlwphfnKya1m34IqohiZlAWwwWP//ycKzR P+VeQjD7FL/KSdVvRPcqqfzxQ2G3pSt/y7xe3NhlMckwtvclJBN567WSEzwEZEWOR9 0dFaen5gDyESmYzGtXt7sTpWkKdDumTRyLBkhXERQiK0o7pdcsGMcETyU+oC3V3c5C JOsn4NYsjwFRw== From: Arnd Bergmann To: SeongJae Park , Andrew Morton , Brendan Higgins Cc: Arnd Bergmann , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm/damon: fix stringop-overread warning in kunit test Date: Mon, 20 Sep 2021 12:01:23 +0200 Message-Id: <20210920100132.1390409-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=OlPgtVP0; spf=pass (imf24.hostedemail.com: domain of arnd@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=arnd@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 5C144B00009D X-Stat-Signature: wft9gr3rhr9p4egqooscxwsaf1ap45qc X-HE-Tag: 1632132097-804793 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: Arnd Bergmann gcc-11 points out that strnlen() with a fixed length on a constant input makes no sense: In file included from mm/damon/dbgfs.c:623: mm/damon/dbgfs-test.h: In function 'damon_dbgfs_test_str_to_target_ids': mm/damon/dbgfs-test.h:23:47: error: 'strnlen' specified bound 128 exceeds source size 4 [-Werror=stringop-overread] 23 | answers = str_to_target_ids(question, strnlen(question, 128), | ^~~~~~~~~~~~~~~~~~~~~~ mm/damon/dbgfs-test.h:30:47: error: 'strnlen' specified bound 128 exceeds source size 7 [-Werror=stringop-overread] 30 | answers = str_to_target_ids(question, strnlen(question, 128), | ^~~~~~~~~~~~~~~~~~~~~~ mm/damon/dbgfs-test.h:37:47: error: 'strnlen' specified bound 128 exceeds source size 5 [-Werror=stringop-overread] 37 | answers = str_to_target_ids(question, strnlen(question, 128), | ^~~~~~~~~~~~~~~~~~~~~~ Use a plain strlen() instead. Fixes: 17ccae8bb5c9 ("mm/damon: add kunit tests") Signed-off-by: Arnd Bergmann --- mm/damon/dbgfs-test.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/damon/dbgfs-test.h b/mm/damon/dbgfs-test.h index 930e83bceef0..4eddcfa73996 100644 --- a/mm/damon/dbgfs-test.h +++ b/mm/damon/dbgfs-test.h @@ -20,27 +20,27 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test) ssize_t nr_integers = 0, i; question = "123"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers); KUNIT_EXPECT_EQ(test, 123ul, answers[0]); kfree(answers); question = "123abc"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers); KUNIT_EXPECT_EQ(test, 123ul, answers[0]); kfree(answers); question = "a123"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); kfree(answers); question = "12 35"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers); for (i = 0; i < nr_integers; i++) @@ -48,7 +48,7 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test) kfree(answers); question = "12 35 46"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)3, nr_integers); for (i = 0; i < nr_integers; i++) @@ -56,7 +56,7 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test) kfree(answers); question = "12 35 abc 46"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers); for (i = 0; i < 2; i++) @@ -64,13 +64,13 @@ static void damon_dbgfs_test_str_to_target_ids(struct kunit *test) kfree(answers); question = ""; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); kfree(answers); question = "\n"; - answers = str_to_target_ids(question, strnlen(question, 128), + answers = str_to_target_ids(question, strlen(question), &nr_integers); KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); kfree(answers);