Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp4723821pxb; Tue, 28 Sep 2021 02:36:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3MTOf62Iu9WIZqMQmXOfbkAvF5yBOeX3No9x0EpenYLasxbfa9gpeiun0rSQJu4yLcwT9 X-Received: by 2002:a17:907:2098:: with SMTP id pv24mr5728736ejb.426.1632821806085; Tue, 28 Sep 2021 02:36:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632821806; cv=none; d=google.com; s=arc-20160816; b=OOn4KOxPuMbXsIrgaH9T8O9ofXAdmszfTfoOJofxXhIO+Bq/sHdZ50YYtOL2WUB/bO jn6qB5toMKP/uXeyKE0MeUqJOPUu0C9GvzRcSG6AnMnGAdmBJl1+lJ5N+3G1YRjxkmqc RuxiG6y8RabLCj5z5cRwc9GoPI8SJ76vIaf06AZhltR5bmf8dA86KOUjoyb/vMZwXBRZ DeST8ILt1CE+oYss8ySAOvYkfeuTkSBlRMsBIMmZ+f3ssLGpq2TVQmM9Hym0FtgW41WE UrzLiW7bzwk62mVf8Ge1G8EPwpUTGDyAuemojNB6Mi2dQMq6tki8vzZ7coa+l5bUAixV S70w== 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=UcbiR6BCGeYFhQYjRGJAlBm/e2jOh5eH5Wtd66oLjlE=; b=HsAVCoU0g+mGgKMCBRMIuL7nccobzEF5oi3eWJ1G+3duqvqyZ6/QfvOhSDZ4wOmaXs vGqbBtc80nz5pmRccGc1gjbPzlE6ufGlBnVlmo2V8E9R6RrNPmmm7hgFfQqXi+B+9RBd gcc/kL1J1ds4FFleqUUir999hZPnNrnYOK4ZrmNHBZztNqQuSYEeVT/5tbcQRBp6VHys Sk+I1Tv0gsWpf03pLX0eBPfVdJkQ5iVyTipiLAUjQ0Qe1uDUxQ5slor/3rERZMvlT2FE nWbiAaa5iwwJ4wMQY5jpdY3PDNlx9JkU4VboGGYYggzwb3eTfq6ndACkcX+2tdp/p2jF JofA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mSiKHiGE; 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 h13si22520012edf.534.2021.09.28.02.36.21; Tue, 28 Sep 2021 02:36:46 -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=mSiKHiGE; 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 S239952AbhI1Jgk (ORCPT + 99 others); Tue, 28 Sep 2021 05:36:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:34944 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239724AbhI1Jgk (ORCPT ); Tue, 28 Sep 2021 05:36:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A2091610E5; Tue, 28 Sep 2021 09:34:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632821701; bh=C25EEUziHpymaVoXyCUtu9/yeAR6P+59r636iT5bdE4=; h=From:To:Cc:Subject:Date:From; b=mSiKHiGEYpXRI79JFMg03dOw4Ju8ad8RSoLqmTxoyCxlPzHvXHtSxnBET3tjpTZm4 eror797UKeXhgEzAF3N685Kx9ii+cF/qVreuofHrOyXSOdJagqv7jolEKIZgO0c3hm zeOlSfZMrz7brIBZvtLac3pr5wrwlfRtWorQz3LEGBxLSg565C8FqGHuOiLkLccMjR IpC4wGXMkHAu/hWOWGZorUVH6VTOFS40VfC5meMBAx7LlCz1i9ie1MFAhBmMX1Ulwi 752117BBy0DQlOE1jWaYWBO5DSNvoBpd7VLfF1M3km2Vwu6jTC+E2bvwWSmT4mHEyF Zl/3fczbOEamw== From: Arnd Bergmann To: Petr Mladek , Sergey Senozhatsky Cc: Arnd Bergmann , Steven Rostedt , Chris Down , John Ogness , Nathan Chancellor , Nick Desaulniers , YueHaibing , Jessica Yu , Andy Shevchenko , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] [v2] printk: avoid -Wsometimes-uninitialized warning Date: Tue, 28 Sep 2021 11:34:33 +0200 Message-Id: <20210928093456.2438109-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: 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. Fixes: 337015573718 ("printk: Userspace format indexing support") Suggested-by: Steven Rostedt Signed-off-by: Arnd Bergmann -- v2: use a simpler trick of having an 'else' in the #ifdef block, as Steven suggested. --- kernel/printk/index.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/printk/index.c b/kernel/printk/index.c index d3709408debe..43b45a916ff6 100644 --- a/kernel/printk/index.c +++ b/kernel/printk/index.c @@ -26,10 +26,9 @@ static struct pi_entry *pi_get_entry(const struct module *mod, loff_t pos) if (mod) { entries = mod->printk_index_start; nr_entries = mod->printk_index_size; - } + } else #endif - - if (!mod) { + { /* vmlinux, comes from linker symbols */ entries = __start_printk_index; nr_entries = __stop_printk_index - __start_printk_index; -- 2.29.2