Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3926240pxb; Mon, 27 Sep 2021 05:52:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbwZpmW+vA3b2EuG1dta4Zdc+ao/ygT3FFBIOxnJbMLmha5DaTgWQK7G4kPdlwjSS92EOn X-Received: by 2002:a17:906:63ca:: with SMTP id u10mr26723164ejk.411.1632747155805; Mon, 27 Sep 2021 05:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632747155; cv=none; d=google.com; s=arc-20160816; b=sQouaXDWt7VqDEIqKBiA6s/Q86x+DHcFbBff1erdsiCrVqLWJTdRd6GNgi5ut6qCWb 7EbSMYjrQDncRrusLA6HZirHWbYTxzDBggvLza7A8ZdS9Cq7K8IeadAyJMY+RhqoALKL zmbo1dBIZQVTByATgDxgoX2qSkZunmxgIRAQAvvTCBvcNG5vK+g1KMcdfkM6SE80k4Ar Wllw1AQseyOfs1MRwd4ahJJET5gmy4A+tuCDj6ImxtA6zdFvB8oNd3Pq9DFznCj4wGzf ogq4HVweEgPV+OaX/rszBkg9N7/8jWdxgwy5BrPjEJT8xYj/9Y1RKV8ai9FdBla3SLj/ GQTA== 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=dwOLolenk1C0BAmRcYOrrImYF0Ex1YzNpuVRtxreAb8=; b=nb0jF4e+5hLzI7k54XoIdWkTPTndVwkOyDX3dirK8+5hwH/nD/oUR2xUr3ZR76YzuJ X44wIyfNsJwNL0d8YhmtlfAOJR/qmdhhZTG/M9hhAYZeKUGjTNfvKA14pCs39NB5FaG+ sHk9jCfnStMaCD9w9kLJZ1JGWcDx1I3vmEiKxwx3TdEGL+sNDIoWdlRXr5D2el2xHeZx LQ/vsWfSxkEZpBODtGgWfHnk+nUj+zWGc2AB444IyOoRgrLD8042W2oFyc9Xy/51ueFe q8ZU99KzoVREHh8IVTe3e9pH9V3+K7qHxydABP9Ocd6rGzQl5tkErAqIuzsXz34IOHKB Scfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LdxOEOBx; 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 b10si3148037edf.629.2021.09.27.05.52.11; Mon, 27 Sep 2021 05:52:35 -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=LdxOEOBx; 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 S234430AbhI0Mv4 (ORCPT + 99 others); Mon, 27 Sep 2021 08:51:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:38500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234427AbhI0Mvt (ORCPT ); Mon, 27 Sep 2021 08:51:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AD20E61052; Mon, 27 Sep 2021 12:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632747012; bh=Mn3+/4wak9bCLKuXFHDiBxA5y8otZjMtkB/6idWI6Ys=; h=From:To:Cc:Subject:Date:From; b=LdxOEOBxib7D/G1ojHvOuzTpBfflhMVKlZ4u0YyjbyKCmn0xXyDTxJE6UYU33LjvO dmPCUgC2MXvr9C22wAznHUq/Wx1ec236k+IvUDH+YpVolkQUCDIYtNi9Q4aeRMi4Sj fSnyKZgjBVzzhqIeHVaIaqh4kwqCHFcB7BjtDjTi6N07FFk13uC2WbgOqyvmDYHYmL LJe+2Lrnxt7oWSQSXHgy+YzGL3vHR+L8yCn9+4BiWhMIGuqA4n9NleEa9jEILGnstU cJYIoyb4apYYePy39RQYts7mIB7ZX+pjg4jpWPzWWJOYSDXKGcy+SN9I4XQ/PPAwMz PeZZzg4kPQSSg== From: Arnd Bergmann To: Petr Mladek , Sergey Senozhatsky , Andy Shevchenko , Jessica Yu , Chris Down Cc: Arnd Bergmann , Steven Rostedt , John Ogness , Nathan Chancellor , Nick Desaulniers , YueHaibing , linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] printk: avoid -Wsometimes-uninitialized warning Date: Mon, 27 Sep 2021 14:49:47 +0200 Message-Id: <20210927125007.1581919-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") Signed-off-by: Arnd Bergmann --- kernel/printk/index.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/printk/index.c b/kernel/printk/index.c index d3709408debe..b4d90bab6d4d 100644 --- a/kernel/printk/index.c +++ b/kernel/printk/index.c @@ -22,14 +22,12 @@ static struct pi_entry *pi_get_entry(const struct module *mod, loff_t pos) struct pi_entry **entries; unsigned int nr_entries; + if (IS_ENABLED(CONFIG_MODULES) && mod) { #ifdef CONFIG_MODULES - if (mod) { entries = mod->printk_index_start; nr_entries = mod->printk_index_size; - } #endif - - if (!mod) { + } else { /* vmlinux, comes from linker symbols */ entries = __start_printk_index; nr_entries = __stop_printk_index - __start_printk_index; -- 2.29.2