Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3960156pxb; Mon, 27 Sep 2021 06:32:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2evHbAtutkO9shaA4eIQ7QIhZrNC8DktubkK/cKD1r9QLVZJ9xIjIT63CyF3ikil87UGW X-Received: by 2002:a17:906:1454:: with SMTP id q20mr60154ejc.446.1632749565214; Mon, 27 Sep 2021 06:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632749565; cv=none; d=google.com; s=arc-20160816; b=iJY/qifoKLvd22ROo9E7ncJrkm6Dn6HbMCJ41CP0mLasIewCRzSCRSqlV1oO6J2rYz A6GlocRbidC4hFuIvYcCERsA61oXcEaZhwAqn/85K6Wypykc4axTFh/+YIg1aM4QWNep kK0j6U7eel0axqQlcMowZBHOWW39/Rgn50ns1eWiyYrhrvlSuLkb1AttZQNCXTBtkUqD vQDda/19flMakM1MWMLgd4ItOLfyxmdO/7reIjlaGf4hxZ29xdnp/0JvEw3pCkXL1e7P /au9/9xmoIRX6aLW4+oXpcEI6da1dznfzG18gE7PkftQOeNIszCbrS1I0lXlPNkF3dxO UvJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=v5ssxCTvMeIIC7ksbm34scOVC2DyEUeo0f0n/X9zJYs=; b=Cj3w7GyQ9TdNxR8TbvFrJzXAmZdUo5uHvkx/yaL5lf1Sr9XMkVqMxVj4DR7OmJVXwX EBqJHIcwEr6Auy8YiG1XFh802BJHmuRaMZglDvg7VjsgeTRy9WKr1wwTDnSh/NtJtomX dmYO083mECmaTd7JweJu5sX2Ffx9efUNdts8HGr6nROu7nh+a3Hgj277f7jJXjmT9BPa 2A40GVVEjGBxbgJfVubpiIYYpUy8u6CeO7hVb72rNqtU4t8IQhvz/JkUbPJxbwkBas4N 6d7q4lul4jAyZO+DrgRQayxSvG5PHmzvvmY9h3DkYIf+pL4w6MwGWUelMhzWztQvvIb9 C4rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rhhWa5RW; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si23028058ejo.637.2021.09.27.06.32.21; Mon, 27 Sep 2021 06:32:45 -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=@kernel.org header.s=k20201202 header.b=rhhWa5RW; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234360AbhI0NaS (ORCPT + 99 others); Mon, 27 Sep 2021 09:30:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:59388 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234058AbhI0NaS (ORCPT ); Mon, 27 Sep 2021 09:30:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 688CC61058 for ; Mon, 27 Sep 2021 13:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632749320; bh=vns6d7q7snjlnOGxuPZz3LzGfbU3pA9uIcUCFNFCBl0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=rhhWa5RW0yQoJ4jqoEt5H5Uofm+jScQJy35aNLJ8PXqNbOcyKf2XD/jgwAfSdt3pB M3FWGdOlZTUrpTCAaddDpXdsWXc1Z/OBuQ5++wdyvmpKg5uj/k8/q69ormsZIgSyrX iIQgHs0qvuwnYWepuH2y9TPA+0pQIXNkZY/G0Rig+Z4MEe0yj1SKhmLVze4NzgLxIe iuC1W0XQMvp9TH7sWmhFTKnc4tPSN5ojmoeupA+c4+NBXteLHhgRL8oITIjJ/1vMX8 8UzDqzxBX8eztOurMyEa9jTnKkiDIDOgTuGAjoN2FmqP66lGogVi6kcNxUqkP81BSU ToF3bTNBQqV/g== Received: by mail-wr1-f44.google.com with SMTP id w29so51843822wra.8 for ; Mon, 27 Sep 2021 06:28:40 -0700 (PDT) X-Gm-Message-State: AOAM532gfr+ST+0PQavxV8PxnIrFl6GsGyNrr9+1nP6uNceUSODzrKHi 7s+u4ds54tBFlD+notY+oAiVQEB3QJq/o28tbDQ= X-Received: by 2002:a5d:4b50:: with SMTP id w16mr27956996wrs.71.1632749318987; Mon, 27 Sep 2021 06:28:38 -0700 (PDT) MIME-Version: 1.0 References: <20210927125007.1581919-1-arnd@kernel.org> In-Reply-To: From: Arnd Bergmann Date: Mon, 27 Sep 2021 15:28:23 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] printk: avoid -Wsometimes-uninitialized warning To: Chris Down 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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". > >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. Arnd