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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE5FDC48260 for ; Fri, 16 Feb 2024 17:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c/46p1/1vpGmejvcFYyGwRRza3WpvgwNxruCMxIy9Tk=; b=2QDanzC+acsXmM oZNqBeHPgKNLrwWlsxyLhkjso6B9Ml6NvMRW1TvjZJlEnXWXjP5oltuzOj9WvpxxYfK3OuP/EYjWj ZF4cRZuLzT8rbzy4RH8WaNBuOtOXnEjGp9Z71vik7g2nEf0RM2/HYh9YOPo55bkmj9ZjBoI0Af5vA nclzSldfMWHI+L6fXtv0p4bqy60jMsp06x0eUW0udc6uBsV/ot+p3H6zaUcG7sS+ouT+YDeZz4Nez 2TcCn1Mth0pppnifbkIFI58hPYuyst3oVMpdBLakAMOdMLBfJvgjw7X41T4XCPjdLgVBRjQR0BqGp kRzCBl3ff0jE7zAy/D6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb1tj-00000003BFD-3gh1; Fri, 16 Feb 2024 17:21:15 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rb1tg-00000003BEh-2v0Y for linux-arm-kernel@lists.infradead.org; Fri, 16 Feb 2024 17:21:14 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 29067DA7; Fri, 16 Feb 2024 09:21:47 -0800 (PST) Received: from pluto (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A04A63F694; Fri, 16 Feb 2024 09:21:04 -0800 (PST) Date: Fri, 16 Feb 2024 17:21:02 +0000 From: Cristian Marussi To: Arnd Bergmann Cc: Sudeep Holla , Arnd Bergmann , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] firmware: arm_scmi: avoid returning uninialized data Message-ID: References: <20240216163259.1927967-1-arnd@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240216163259.1927967-1-arnd@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240216_092112_874705_F488D79F X-CRM114-Status: GOOD ( 20.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Feb 16, 2024 at 05:32:53PM +0100, Arnd Bergmann wrote: > From: Arnd Bergmann > > Clang notices that there is a code path through > scmi_powercap_notify_supported() that returns an > undefined value: > Hi Arnd, > drivers/firmware/arm_scmi/powercap.c:821:11: error: variable 'supported' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized] > 821 | else if (evt_id == SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > drivers/firmware/arm_scmi/powercap.c:824:9: note: uninitialized use occurs here > 824 | return supported; > | ^~~~~~~~~ > drivers/firmware/arm_scmi/powercap.c:821:7: note: remove the 'if' if its condition is always true > 821 | else if (evt_id == SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED) > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 822 | supported = dom_info->notify_powercap_measurement_change; > drivers/firmware/arm_scmi/powercap.c:811:16: note: initialize the variable 'supported' to silence this warning > 811 | bool supported; > | ^ > > Return 'false' here, which is probably what was intended. > > Fixes: c92a75fe84ce ("firmware: arm_scmi: Implement Powercap .is_notify_supported callback") > Signed-off-by: Arnd Bergmann thanks for looking at this, this series that I've just posted is still to be reviewd at all, so I would expect issues :D...BUT in this case I dont think that the clang report is valid since, inside the culprit function scmi_powercap_notify_supported(), a few lines before the reported usage of unitialized data there is a check (@line 816) on the 'bounds' of evt_id itself if (evt_id >= ARRAY_SIZE(evt_2_cmd) || src_id >= pi->num_domains) return false; so basically the mentioned if/else WILL be evaluated in some of its branches for sure and supported wont be uninitialized. Indeed, I removed from here (and from all the series) the explicit initialization at definition time right before posting the series. Having saidm that...maybe it is just brain-dead this approach of mine since it is able to fool clang & friends...I would add bACK an explicit initialization of supported all across this series in V2, if this sounds good to you. Thanks, Cristian > --- > drivers/firmware/arm_scmi/powercap.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/firmware/arm_scmi/powercap.c b/drivers/firmware/arm_scmi/powercap.c > index aae91f47303e..8ee3be8776b0 100644 > --- a/drivers/firmware/arm_scmi/powercap.c > +++ b/drivers/firmware/arm_scmi/powercap.c > @@ -820,6 +820,8 @@ scmi_powercap_notify_supported(const struct scmi_protocol_handle *ph, > supported = dom_info->notify_powercap_cap_change; > else if (evt_id == SCMI_EVENT_POWERCAP_MEASUREMENTS_CHANGED) > supported = dom_info->notify_powercap_measurement_change; > + else > + supported = false; > > return supported; > } > -- > 2.39.2 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel