Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3963075pxb; Mon, 27 Sep 2021 06:36:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKGX14SCH//ChvYXaplAhvliLECzaTaxeVJ9EHnp5xJkrFFQ3pNxBQhhMqU/JFt07XI5HO X-Received: by 2002:a62:ab07:0:b0:440:3c5b:ae7c with SMTP id p7-20020a62ab07000000b004403c5bae7cmr23609166pff.49.1632749785527; Mon, 27 Sep 2021 06:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632749785; cv=none; d=google.com; s=arc-20160816; b=T4iJjvbKQoAbd0tKynXHMwxp6YXmVwhjWlV2ZZS4325tKwjIxS/ZeNu1IJ5X+3jhHW zB5kQ0v8TcyValWCB0IppTH/6OV1+n1XJHod/jcm9LdPpgXzM1eOMVBD5Njmo6qIrg7+ g45SgIy99EOUuUeoDe5elTXBak2HnOzIKMnA7sv+iqTpuK4wmKSrco4B2r8kDWshbtxu wcr7buvTqxwK9JqVt8x7ONc1XEV0dSl3CILHGVNuREpkXGgTq/f5F/g3zIoWb+mz5wF0 2X313FRFMPpUE4219eE9CsaSFFBebMxgwl+vMneI0eMRpVgc4ZR+E2q5/0ikee67iPTs 10jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=HcnQqbopaKTbfNCFEcMRHjZ29Aha5URcI+niusbKs7Q=; b=XBDpGmcP9f5ztjwaw5FtOBCKdTHIHPaLRVTFve4Cof8s/oiJmedoTirunSUbpNh603 1g9OX4exMwM7lTM8B5PeBRBFtEuYkYHooymvEcTdbVMTlDF9ZJKPhSp2snNWzGqpnlH7 X7+eYYEFdwix/GhxTzxjtuZ78pdPX8YVQAwgEXHGENqmDUKlMB2ngyMprnqdlks9YIC3 /leMVM7AXsodGVTHULBWPyJlgk5QgvunhNIX6ofnKuf0Kn7htLSHsZ52knMH9tT3pwP1 C5dsEKvoyrWeT7tsSQWBgGe6Y1aXmkdZFqLtmzb+IAbyC1xlzXrnVmCYGAhRM2A4f4lM LQew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=bIL2RJd8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si24679609pjh.27.2021.09.27.06.36.10; Mon, 27 Sep 2021 06:36:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chrisdown.name header.s=google header.b=bIL2RJd8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chrisdown.name Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234484AbhI0NfP (ORCPT + 99 others); Mon, 27 Sep 2021 09:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234103AbhI0NfP (ORCPT ); Mon, 27 Sep 2021 09:35:15 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33332C061575 for ; Mon, 27 Sep 2021 06:33:37 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id l8so21767914edw.2 for ; Mon, 27 Sep 2021 06:33:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HcnQqbopaKTbfNCFEcMRHjZ29Aha5URcI+niusbKs7Q=; b=bIL2RJd81JX5T4t+0lu9GBa3k8wPjjj9YkUb8wAwqlBOyAvYoPNPdv5+6in4BmWHJm dMjLYDSR1cs2cBsaGIQNVqr38EnEezzssfFp/Ca1+wkVNHgCIpSlVUGHBFEpIn7+Gh5p cvWoa1brBiqwgjE+JFKnt5UUUZ4j7icUGxVW4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HcnQqbopaKTbfNCFEcMRHjZ29Aha5URcI+niusbKs7Q=; b=frTib1Iw3Z56qhrNcfcCsJek+EQ6ma33RmYqmAUW9lFpu6RTYcP/9MbZXtI9413cen rrfrN/EIvrCj1COSeQBA/si6oPcM/QYbVj6bqvx90efXFMzXg8UiisCAzfHFmj/gT6EB 9j5FmpY5gTc0nWVWEGytbEbnCOCmLfo7Ls31s0tlFIVphv6uAYUDX+baAqMXPs+3nUZU PW73MFQgFra/vRJSEn7mQDoro7clh5el99KoX6ewTNmSwEryB/+Mi/9hcTX9eSXmRGdN 1YRBDw0A2utia0nkwvu+oB78/cYvzGClz8PbPlOs3QsNRmhODzWSK0eHz/MET2TzooKc qC/Q== X-Gm-Message-State: AOAM531qvaIQuva9qW5sM8EGA93LHO7oHOpBLuS7jmt672ro7A8Bb0PE n/XRe5U/aHzeolLZFK2fVGgvEg== X-Received: by 2002:a50:9d02:: with SMTP id v2mr23415268ede.105.1632749615754; Mon, 27 Sep 2021 06:33:35 -0700 (PDT) Received: from localhost ([2620:10d:c093:400::5:6664]) by smtp.gmail.com with ESMTPSA id ca4sm8717419ejb.1.2021.09.27.06.33.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Sep 2021 06:33:35 -0700 (PDT) Date: Mon, 27 Sep 2021 14:33:34 +0100 From: Chris Down To: Arnd Bergmann Cc: Petr Mladek , Sergey Senozhatsky , Andy Shevchenko , Jessica Yu , Arnd Bergmann , Steven Rostedt , John Ogness , Nathan Chancellor , Nick Desaulniers , YueHaibing , Linux Kernel Mailing List , llvm@lists.linux.dev Subject: Re: [PATCH] printk: avoid -Wsometimes-uninitialized warning Message-ID: References: <20210927125007.1581919-1-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.1.3 (987dde4c) (2021-09-10) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Arnd Bergmann writes: >On Mon, Sep 27, 2021 at 3:20 PM Chris Down wrote: >> >> Hi Arnd, >> >> Arnd Bergmann writes: >> >From: Arnd Bergmann >> > >> >clang notices that the pi_get_entry() function would use >> >uninitialized data if it was called with a non-NULL module >> >pointer on a kernel that does not support modules: >> >> On a !CONFIG_MODULES kernel, we _never_ pass a non-NULL module pointer. This >> isn't just convention: we don't even have `struct module` fully fleshed out, so >> it technically cannot be so. > >Yes, I understand that part, hence the "if it was called" rather then >"when it is called". But there's no "if", it's simply not possible. >> >kernel/printk/index.c:32:6: error: variable 'nr_entries' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] >> > if (!mod) { >> > ^~~~ >> >kernel/printk/index.c:38:13: note: uninitialized use occurs here >> > if (pos >= nr_entries) >> > ^~~~~~~~~~ >> >kernel/printk/index.c:32:2: note: remove the 'if' if its condition is always true >> > if (!mod) { >> > >> >Rework the condition to make it clear to the compiler that we are always >> >in the second case. Unfortunately the #ifdef is still required as the >> >definition of 'struct module' is hidden when modules are disabled. >> >> Having IS_ENABLED and then an #ifdef seems to hurt code readability to me. >> >> >Fixes: 337015573718 ("printk: Userspace format indexing support") >> >> Does this really fix anything, or just clang's ignorance? If the latter, clang >> needs to be smarter here: as far as I can see there are no occasions where >> there's even any opportunity for a non-NULL pointer to come in on a >> !CONFIG_MODULES kernel, since `struct module` isn't even complete. > >I don't see how you would expect clang to understand that part. It does >not do cross-function analysis for the purpose of diagnostic output, and >even if it did, then this caller > >static void *pi_next(struct seq_file *s, void *v, loff_t *pos) >{ > const struct module *mod = s->file->f_inode->i_private; > struct pi_entry *entry = pi_get_entry(mod, *pos); >... >} > >has no indication that "s->file->f_inode->i_private" is guaranteed to >be a NULL pointer. Sure, but it seems unnecessary to me to gum up the code because of clang's inability to understand that.