From patchwork Fri Aug 9 12:32:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13758752 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 514FCC3DA4A for ; Fri, 9 Aug 2024 12:32:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6BC26B0095; Fri, 9 Aug 2024 08:32:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1AF26B0098; Fri, 9 Aug 2024 08:32:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B09876B009A; Fri, 9 Aug 2024 08:32:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 945776B0095 for ; Fri, 9 Aug 2024 08:32:39 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0DC6B160E68 for ; Fri, 9 Aug 2024 12:32:39 +0000 (UTC) X-FDA: 82432645638.09.2357F85 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf17.hostedemail.com (Postfix) with ESMTP id 09DF540028 for ; Fri, 9 Aug 2024 12:32:36 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=tyY6JyZw; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf17.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.167.52 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723206703; a=rsa-sha256; cv=none; b=dEZTiqYlRHSK8/hFbkcec4YhwP3AO37h7UDp87vpAoUNqXQDYiLBvcGxsOunoFeYJT/lZA ymwlZTf/gCxEcRey/nJ0/zyfKrw4I3qaCQWaewwPKZTCzuZemFl30uQyyWmU1Ewf6jsRdt GHzqW2kmjyaUi38RR2bgpNwIxWQlfb4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=tyY6JyZw; dmarc=pass (policy=none) header.from=linaro.org; spf=pass (imf17.hostedemail.com: domain of dan.carpenter@linaro.org designates 209.85.167.52 as permitted sender) smtp.mailfrom=dan.carpenter@linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723206703; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=XEvmrJApAdAdB8IUGlSUXCcZKgELg0TXzRkX9FYQA2E=; b=Df+TgF8/qoJqPSeH7axG8LyIEXEARkWWMC8FnCSUjYjK3Tc5xWjudLpv8lihio/AakMXvE V7niQBHALnun/gRY8uBxXvJENGX/VklkUeoUxH12oZC3KhU/zvE22lBu6YH02jk7hG+EDN /x6rY5KL/b2wQ60+rIfEYu/BHyS5DQ4= Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-52ef95ec938so2116279e87.3 for ; Fri, 09 Aug 2024 05:32:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1723206755; x=1723811555; darn=kvack.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=XEvmrJApAdAdB8IUGlSUXCcZKgELg0TXzRkX9FYQA2E=; b=tyY6JyZwo5ZvIfmu1ZhGXG8aGV9i55DA14qeLrn7O1U1TmhxN86GVljJTcS/knX9J2 bWkJYiwRUICsc4gnZCfJ0obA2BqUIvzjgl4vZY90oxqSBdMIMMd7dUlMN7J49HxZUyAt n6OAxeFaYKyfcy5C+qcnpOUI6gERXzxt8RrRYH38kbphz969hwhMyrXDqD5244LUDWxT P9e0cUa9/eeAxMMo6m75/eLtgiGVHnp0BB+mLDHd21UgqrAW0Np7RGbOpHeHquoWSMfu gquxhqzC30cwHF4m/VfYA2C1znrF1aJcVhtnTWHogSrrDeGLKSwpE3l2a3HhPjMFKwF+ vs6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723206755; x=1723811555; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XEvmrJApAdAdB8IUGlSUXCcZKgELg0TXzRkX9FYQA2E=; b=SwFxcrvx53oZMomx86ZWUNyYWtoBd3daoxwGUU+UqpqalorVHJoFBHBOE3FJB2lJ2V FDVUMhlzZcLeGL43lp8uLVFjUoOwn+QQfHTlxI6TCfrFxyyvS2fHorqjYE2VRI7S9LHp yhKbmE4jGq/R6LleR8yz23J++bhDgSsnIJQ3NoWkJIZ+QXv7RWXlGAPeGyEDX2aGQ432 egHku9g+VpuEbbm0+CA8l+eZFZGXJ7XEdGWP86yXX65vE4KWeMnKBUcE0hd1fsjM1Dss n4yhiYuA/YCYbJxLLtuyaGL1DGBEcOUewGWO6HjFYRYSK3SzbcLEuFfXQCHdycLneBmq MLyw== X-Forwarded-Encrypted: i=1; AJvYcCU88hT45qpG60leaNmxU0oft19fwfdDsp/teTIHwOytkYgYK4K0wkyu41zzX9Sbe7KEU7TIG3X/ruJLhbEG45GLTWw= X-Gm-Message-State: AOJu0YwBREwAFIjYc96eBfLCrVhYbn6UToVePxzmjn970G1tMUuJyOT5 LEDIUj7jiU/5OFl07cgD+mm6VZOWMChv9eSoF3XIZcTYqln1LtM440l1jFPOezU= X-Google-Smtp-Source: AGHT+IGzPu2doVLDNZ6syQ8+456inTtlzazWj4IP4I0oNXM1Sz9cwjKQLoWzh+mGsvT5bHuN4rBo4A== X-Received: by 2002:a05:6512:3b0b:b0:52c:6461:e913 with SMTP id 2adb3069b0e04-530ee97436fmr1248689e87.16.1723206754996; Fri, 09 Aug 2024 05:32:34 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bbb2bf8666sm1495151a12.9.2024.08.09.05.32.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 05:32:34 -0700 (PDT) Date: Fri, 9 Aug 2024 15:32:30 +0300 From: Dan Carpenter To: Dev Jain Cc: Andrew Morton , Shuah Khan , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [PATCH] selftests/mm: compaction_test: Fix off by one in check_compaction() Message-ID: <87470c06-b45a-4e83-92ff-aac2e7b9c6ba@stanley.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 09DF540028 X-Stat-Signature: rim1i7hp1cqb1iswncpg6i3qj4bg1a17 X-Rspam-User: X-HE-Tag: 1723206756-228907 X-HE-Meta: U2FsdGVkX18zgf5Yr05NDj3Kyo7LwQc1V5GiPK7+1wASXeKTMa9N19C5YxoJOUQvs1JF857NbDA8C2I4TcsZsJdORoCGirSyu9NofLRYWO15OFyGXMfx3SQb0T+B6UcuMXoMpE6TzLmwubzJ7ld356wVkFMuTd/XLcnp1/DALvGJDQb9mPTeeT26ONnr4DWo6Cw5VcLBz/NTKEHbxZx+xP0nfutJQh7OheoFQLFowNEd8qrtsGz1LdHjRW8/JzUo5A/tTSCe9Tt1K0SKeWOWb18O/loPvgXilwiX8yVkMntFcYuIKlg/+sMCou4rDavYzyfvLe6vf6RkrkiKAqxr1OrS/vjRT4oN3cnyKGzBJDt06eAVilNMTtCDWVFURt+mo0sOpvWyXQrFA9i2yTFQEv8KjFFjfhhf5HcoQ6DPJ8iqcZIhji8DzCz9v00zZOPNC4M/T7UdiaZJcSN0bP5CtAmd7sszOpthPC9Kt7WezdZfEXF4yGn+gCNrAE8EEOXY5PZjba5niKw/wGAG5MdV+V6UQAflDTvuvmA/2TdRketGDam81Mpr49vW+ZkRBLYtv+YBeBUBCmOksGNLR5+wJ2oyiq4o/8WSFGy0yqco4SLecmffaIe0TJ6Ug3RkKDm/8z4XGZgAN5pfjkmJZZZV/GfvFru++2hMbUXbpCuTLTGGhO/CG/x4NH0dztVejYD3a3KYq5BrwxA+dqT7LJ1XanoiQSIZdq5BssbjAl/KFKaKnFLMMi38G8cOspizhDsCoxT/cpOCssbg7UvZ9ns0j3rCmtBbDsILk/Ph9aWr8j87E3357dTAaSHOpe1lhWKnz8YTpZ3w0vdnQRoHiNWLpRxZKPiisAmzqvrtOXsAZM0xyZ6C6tStCOf+dmek6nZRTecG8xG1CBUCEaQ49Is97HhGzMIFmKntDWHYGUSraZFOcAZb1YmNL507Vl+E/pWQQKtnWE1okFLTjxfo+Wu xcWAos7v oVIlbfui0HJyIEQlqhACHcSS9ufiSyfJeZhp6r4z119U/6nV2+6pkvuFDDoR6GEIv+S42P4shjLt4gqTk0GjaCM4rCCWxdF3Gl1/frqjA0PM88RMlj7x+/293ATGCpnrO02zFr/zkEhpkp2D640Ox45pDdJJe5aBV9L6UIgrFcdBuhbsTP54lH0DaEl72HE93vVaYLzM6IciBt6KEW/igLJZ81v6TaSb4NeQJl/U2nQzRFFfHNg662qHCwRRMdCA3J5ojcyGth12//oYz+l2xqRg1/tU09D0oNpylg3QygXb5UdGJYyU3yu29lMIpO6c9jH9tOTTeYTItl0myR+VNhAxFW7zTY7zhcio2 X-Bogosity: Ham, tests=bogofilter, spamicity=0.009652, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The "initial_nr_hugepages" variable is unsigned long so it takes up to 20 characters to print, plus 1 more character for the NUL terminator. Unfortunately, this buffer is not quite large enough for the terminator to fit. Also use snprintf() for a belt and suspenders approach. Fixes: fb9293b6b015 ("selftests/mm: compaction_test: fix bogus test success and reduce probability of OOM-killer invocation") Signed-off-by: Dan Carpenter Reviewed-by: Shuah Khan --- tools/testing/selftests/mm/compaction_test.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c index e140558e6f53..2c3a0eb6b22d 100644 --- a/tools/testing/selftests/mm/compaction_test.c +++ b/tools/testing/selftests/mm/compaction_test.c @@ -89,9 +89,10 @@ int check_compaction(unsigned long mem_free, unsigned long hugepage_size, int fd, ret = -1; int compaction_index = 0; char nr_hugepages[20] = {0}; - char init_nr_hugepages[20] = {0}; + char init_nr_hugepages[24] = {0}; - sprintf(init_nr_hugepages, "%lu", initial_nr_hugepages); + snprintf(init_nr_hugepages, sizeof(init_nr_hugepages), + "%lu", initial_nr_hugepages); /* We want to test with 80% of available memory. Else, OOM killer comes in to play */