From mboxrd@z Thu Jan 1 00:00:00 1970 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 BC941C83F17 for ; Tue, 15 Jul 2025 21:49:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 549926B0089; Tue, 15 Jul 2025 17:49:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FAB66B008C; Tue, 15 Jul 2025 17:49:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40F546B0095; Tue, 15 Jul 2025 17:49:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 312316B0089 for ; Tue, 15 Jul 2025 17:49:31 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A70A610D115 for ; Tue, 15 Jul 2025 21:49:30 +0000 (UTC) X-FDA: 83667840900.29.431FCB8 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf05.hostedemail.com (Postfix) with ESMTP id 27484100007 for ; Tue, 15 Jul 2025 21:49:28 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="g0As/wod"; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752616169; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Mra6z2xEdS5ABahBZ/ZvzhLPcZgzRQEAxVoU6c8ZpPU=; b=ylhft/SS+d/rN0IdwDmuKD3ZyBxtIt/rnQwEeaeukDjg7T/5zxNg18l70vbJ8IYiX2ojJo tcvcwexavqajx/ATHOWmB8kBifvjY7XAwAqCNCSAi087L7FCFZohZnruNS5LR0YNmniPTO /STSir3Wiy64qoxsyq5WVi/RipCJtUE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752616169; a=rsa-sha256; cv=none; b=HbtptjZ5bDfa7b74jdDZH+8MsVh4njAZpFkndBDHB8mga9OYRb/4DyddROpjVonY6Xe3Ms gjl8Hmhy1B0qbYxyLU/+LdbHz0mrgC6DCT1fZyqQj7YR1ZjjlKL956BKe/ATOwdbbJQpmq nwahq5SkykLAL72gfz88tbQzvF5R/C8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="g0As/wod"; spf=pass (imf05.hostedemail.com: domain of akpm@linux-foundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 5BA0CA54C2B; Tue, 15 Jul 2025 21:49:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 788B8C4CEE3; Tue, 15 Jul 2025 21:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1752616167; bh=trlF5H1bYaM4dSNd149hpjrn6kkLss+dok8sk3g3LnM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=g0As/woditO0fQse77Q8HOkzON0mKGPIbnLkXg9YXDDeJJ/Bc1sTvL4hQRNhpK/9h CzH+FjOgrus4JTTGor4EBVSr6kAAINVr/VN30Lcyer4IpzqtCBVfolnNn0762NYj6e FVp0WTxWjmZgJdF0throkVSeoLeysnr7r83OAhRg= Date: Tue, 15 Jul 2025 14:49:26 -0700 From: Andrew Morton To: Nathan Chancellor Cc: David Hildenbrand , Xu Xin , Chengming Zhou , Stefan Roesch , linux-mm@kvack.org, llvm@lists.linux.dev, stable@vger.kernel.org Subject: Re: [PATCH] mm/ksm: Fix -Wsometimes-uninitialized from clang-21 in advisor_mode_show() Message-Id: <20250715144926.90546c48efc5f288cfde319e@linux-foundation.org> In-Reply-To: <20250715-ksm-fix-clang-21-uninit-warning-v1-1-f443feb4bfc4@kernel.org> References: <20250715-ksm-fix-clang-21-uninit-warning-v1-1-f443feb4bfc4@kernel.org> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 27484100007 X-Stat-Signature: sskoxxpf46bngzpy4h4ahwfe6xjucfmb X-Rspam-User: X-HE-Tag: 1752616168-864269 X-HE-Meta: U2FsdGVkX1/T1xOQP2ECptKuPo0fDokXQmLCPmJ/6hyDEaZ+Lipf0cKemoIFWLILhu3Dw4+4Uj+DyKavjOKOc9t7ntpZlB0tJYaXfkaneOjRMQO7NEob2Rs3qeAnupXCbPnCByPllhMZGDX6nMXQXhmL9YrhFE5V6AJsNPBio3fSLA9SsRAbI4nsP5WzUU6WAq5qQ+Q5BkW5G2IgMvcemaW2ujxytE666Bmu3LGBFUxYOjO7m16jJJZ/+yHR/BVIPgPNLhyd7hfxzuY1THWpUSe8j2mdt2coUrLiqNJv7xJWEuKZBUxNIWuquCotC+NI5TBMnC4rWHTsfx8NlOrp5wU6QvGmv0eRmQ3kWeio4PR0w8CTMKsqEVCQmCm/2Y2mwNSW8LvO8MSW1p3rT2GlVKWaL1z3IhYQxHx0I06GdK/sVyB9q6phS1mp5cquGCJ6Fy7u0R2V8h7lvUUO3ThYPb9dZ0tkpKASd2biLZ8v3bpwR8RP0GeFYGiLhTtZsU84BM5xd6EUSUP4LePgE0tN7lj0OQYxyVRH4j2hbffNuJnHLxTaxJjr2JZctMZawcV07e3s+lE/q3A9Y18zY9PNiclX9XfVSuJS321MiqqO3nvIjuydqe6a65RwD13NoAnZMbc3mCEoYLM6dDb4fShVhP0b217nFCJhmem3ibaWGS3YRCcoPCk2ExFpybDW0UgAstNAm9wJD0LWIY26rKgzOPULmYpKQ0pDOasAu+pPzDEarmGS189m8r+6sg0x+uNgEcaEu+RxF+WR/TRvK/hhpBTRWP7fw3M13VmmbKjf2cB67HZsJyviCUggnys1eXZbrUdTjfAdx76m5okI1qjWsZBnSyxC0/pGgMKkAiaqUD5ZZegUD3E4mXIw4PhFs5Yk1io5rqogYkzrX3A1tHumtyRbw9ibc+3jtO+EsA9W/HfvRPhgGtNy2uQ2WZaVhh3XHy+Fm0irTI8tLs9xQ64 vJQ== 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: List-Subscribe: List-Unsubscribe: On Tue, 15 Jul 2025 12:56:16 -0700 Nathan Chancellor wrote: > After a recent change in clang to expose uninitialized warnings from > const variables [1], there is a warning from the if statement in > advisor_mode_show(). I'll change this to "a false positive warning". > mm/ksm.c:3687:11: error: variable 'output' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > 3687 | else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > mm/ksm.c:3690:33: note: uninitialized use occurs here > 3690 | return sysfs_emit(buf, "%s\n", output); > | ^~~~~~ > > Rewrite the if statement to implicitly make KSM_ADVISOR_NONE the else > branch so that it is obvious to the compiler that ksm_advisor can only > be KSM_ADVISOR_NONE or KSM_ADVISOR_SCAN_TIME due to the assignments in > advisor_mode_store(). > > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -3682,10 +3682,10 @@ static ssize_t advisor_mode_show(struct kobject *kobj, > { > const char *output; > > - if (ksm_advisor == KSM_ADVISOR_NONE) > - output = "[none] scan-time"; > - else if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) > + if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) > output = "none [scan-time]"; > + else > + output = "[none] scan-time"; > > return sysfs_emit(buf, "%s\n", output); > } Ho hum OK, but the code did deteriorate a bit. static ssize_t advisor_mode_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { const char *output; if (ksm_advisor == KSM_ADVISOR_SCAN_TIME) output = "none [scan-time]"; else output = "[none] scan-time"; return sysfs_emit(buf, "%s\n", output); } Inconsistent with the other code which looks at this enum. Previously the code explicitly recognized that there are only two modes and that became implicit. Oh well, no big deal and we don't want clang builds erroring out like this.