Message ID | 20221025173407.3423241-1-nathan@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1131854wru; Tue, 25 Oct 2022 10:37:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7CpeZgV9J8qiyrJtyjRGiGIdtO3mjM3/9jA5U3jyJwX5zROh41SN5uFHyB46JQOoXlxRO6 X-Received: by 2002:a17:907:763b:b0:7aa:1ae6:900b with SMTP id jy27-20020a170907763b00b007aa1ae6900bmr7844612ejc.416.1666719447629; Tue, 25 Oct 2022 10:37:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666719447; cv=none; d=google.com; s=arc-20160816; b=TVLrt5ircNE3uHQwYdvy0VVeS23LMW4QvovAq8urQbBkID6Z2RxnFniRYW3JT90KnO emNS8pV1Lo2CxAkwXjE50E/mWasfxlXb+F5DBMZy8Gz10XpfiKQFVwGBpJokSi0XDMn3 FIJaOkG3Z1gCdHtgZ1K/7/+A8YDEuBdUnzN9+0RpVu990GCgNm9/ECwpddTyq3acyxQv GeaHIaeXDGtIb3oaXp9sMymARO5cGQSvJPM8ezyR8acp+qRnOA4fD3UkuTdl7bUt4c5p /pYgIr0y3kN8xws0eHSOGyjWtMWVTmlH8B8xjglqKNCF+YdXlp/w3W1DcHJ+9jaWFv4S uEQA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=+mHtiNXReAvMVXCIfRWKShF9VKoIMvT9jGDz5sHO4OI=; b=aXnNNj6id9EQkTzBsn+vh4bv3sQDkJXmSt50aFyCQTT6HnNvkEPF8dumL+0sGH8E9E f10ixB0xFAEgh5F8lrBrf3sOPHMhvxjuz/Ewcbgf40NKtrDhrTzG0BmLVLPKvsfEhRGB jHwu94wG/ful3ZgayBXECbv80PbqOIO0NmGy7u5gkrJoz4H4XoOdiRjYP9BJyqNDUmpG FubLuBJnfhgwybsHajkuyc1kSkWRQ9z1kAI5ktMg++w+dcM2iUad3uoMbSQvmDxnOoD8 uTbVcg1vTmROLsv6NKgsWRErZGEwUjq5apBhglmEngSECu3BQAjHXWYdWS+EXO64JHKO JSSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=I3r1Nmzf; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a056402190600b004615587e410si3941845edz.315.2022.10.25.10.37.03; Tue, 25 Oct 2022 10:37:27 -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=I3r1Nmzf; 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 S229864AbiJYReu (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Tue, 25 Oct 2022 13:34:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229744AbiJYRer (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 25 Oct 2022 13:34:47 -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 98C3A193FD for <linux-kernel@vger.kernel.org>; Tue, 25 Oct 2022 10:34:45 -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 3E27D61A56 for <linux-kernel@vger.kernel.org>; Tue, 25 Oct 2022 17:34:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A339C433D6; Tue, 25 Oct 2022 17:34:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666719284; bh=LmmlmDI/9NPsq0QGCvtmuqw5lnkthpFZOpXXgGIwnck=; h=From:To:Cc:Subject:Date:From; b=I3r1NmzfeNK3f9OJUJmeldgLvABnio6QcckHU/bm2RIjlbTKtrObTxxPL4/O7Mp3w ZRuKxjgS3Kuc+MgOhoPNvRh5w3mr67uEiZffVCQV9yS+PcJGZcwNdUaZZ1LqqD5O7V RNEGsknJIdTuq+k8MYu8JhgnPB95gdZHbMlSFIQde9DokxcmVy3Eu2DaSsStb3wCyM 0yiAw6ia96ErCi0S277hG50E8lUYTPo8ELvd7JpuCZUVgGRCMpdo8J0gij3vYhEjeB XGDj1UQ6uOLkJNoCTsDoP/Mbv+smHZ3kFUprf+gYSrZyezDP1sOr+E5xETFNS4jIZW HGua5UzcUHOJg== From: Nathan Chancellor <nathan@kernel.org> To: Andrew Morton <akpm@linux-foundation.org> Cc: Gautam Menghani <gautammenghani201@gmail.com>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, patches@lists.linux.dev, Nathan Chancellor <nathan@kernel.org>, kernel test robot <lkp@intel.com> Subject: [PATCH] mm/khugepaged: Initialize index and nr in collapse_file() Date: Tue, 25 Oct 2022 10:34:07 -0700 Message-Id: <20221025173407.3423241-1-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747682011623768742?= X-GMAIL-MSGID: =?utf-8?q?1747682011623768742?= |
Series |
mm/khugepaged: Initialize index and nr in collapse_file()
|
|
Commit Message
Nathan Chancellor
Oct. 25, 2022, 5:34 p.m. UTC
Clang warns (trimmed for brevity):
mm/khugepaged.c:1729:7: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
mm/khugepaged.c:1716:6: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
mm/khugepaged.c:1729:7: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
mm/khugepaged.c:1716:6: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
There are two goto statements that will use index and nr before they
have been properly initialized. Zero initialize them so that they can be
safely used by the tracepoint at the end of the function.
Fixes: eae5270d3322 ("mm/khugepaged: add tracepoint to collapse_file()")
Link: https://github.com/ClangBuiltLinux/linux/issues/1749
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
mm/khugepaged.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
base-commit: ec24a700584c4df869282bcd92b6d88329afe395
Comments
Thanks for the fix, Nathan,
Best,
Zach
Reviewed-by: Zach O'Keefe <zokeefe@google.com>
On Tue, 25 Oct 2022 10:34:07 -0700 Nathan Chancellor <nathan@kernel.org> wrote: > Clang warns (trimmed for brevity): > > mm/khugepaged.c:1729:7: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > mm/khugepaged.c:1716:6: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > mm/khugepaged.c:1729:7: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > mm/khugepaged.c:1716:6: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > > There are two goto statements that will use index and nr before they > have been properly initialized. Zero initialize them so that they can be > safely used by the tracepoint at the end of the function. Thanks. I've actually dropped the offending patch - I'd like a resend which includes a fix such as this and a good reason for making the change.
On Tue, Oct 25, 2022 at 06:48:02PM -0700, Andrew Morton wrote: > On Tue, 25 Oct 2022 10:34:07 -0700 Nathan Chancellor <nathan@kernel.org> wrote: > > > Clang warns (trimmed for brevity): > > > > mm/khugepaged.c:1729:7: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > > mm/khugepaged.c:1716:6: warning: variable 'index' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > > mm/khugepaged.c:1729:7: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > > mm/khugepaged.c:1716:6: warning: variable 'nr' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > > > > There are two goto statements that will use index and nr before they > > have been properly initialized. Zero initialize them so that they can be > > safely used by the tracepoint at the end of the function. > > Thanks. I've actually dropped the offending patch - I'd like a resend > which includes a fix such as this and a good reason for making the > change. That certainly seems like a reasonable request. Thanks for letting me know! Cheers, Nathan
diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 977c0ff82c46..789db2f3fc06 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1702,12 +1702,12 @@ static int collapse_file(struct mm_struct *mm, unsigned long addr, { struct address_space *mapping = file->f_mapping; struct page *hpage; - pgoff_t index, end = start + HPAGE_PMD_NR; + pgoff_t index = 0, end = start + HPAGE_PMD_NR; LIST_HEAD(pagelist); XA_STATE_ORDER(xas, &mapping->i_pages, start, HPAGE_PMD_ORDER); int nr_none = 0, result = SCAN_SUCCEED; bool is_shmem = shmem_file(file); - int nr; + int nr = 0; VM_BUG_ON(!IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS) && !is_shmem); VM_BUG_ON(start & (HPAGE_PMD_NR - 1));