Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5655753img; Wed, 27 Mar 2019 12:33:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOftNkMGCQtHkeqJAzJ5I7vyqRlYPSRDLEed1ntTzRO4cO63ytr61Y/4Mz1Uilp2cUvoKy X-Received: by 2002:a62:292:: with SMTP id 140mr4080757pfc.206.1553715205278; Wed, 27 Mar 2019 12:33:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715205; cv=none; d=google.com; s=arc-20160816; b=wK7/CL/VpULXqmGZoKyQeuxAzvar1ea9M+ZR1jxvbQZhcr+jnJBRFyn2/Ddg/RVXXq O80BYXb8lMIGhUZ1sxlaVOYToFhKENmpSHIXBnA4DLf9wgvE3bXwOAafRyClmyOgO142 B4PyiXPj+Y5R6ga6S5cPhMhz+qU7XcEvudB33yEttejr6IKLbShEC0fOpuljNmcOe+go FXt78qyYMObuEToCYPtWrBp/KuEKMcHDuj495lf1uc4b/O1RmAo96VQ9M4izMWRXtZNX E+7wMwUQRlQbR9YznmdEqtldkI89H8JjR0CDdWMDncEOJhT4aNUUYugSrWeXCTcoHJKs /58A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LwnSwTbOwv8tt8RSEahQA+eMcKnyHlAIw7maAlOUVnA=; b=XM0DIr0KUfq9p9zndFFsy36r73dO3wbXF8LXfuhfLF846X8IEmSpcHh5u+oJ/A+6lM u7wYM+nsNKEroo3ZYl9J5uOp0cZoi22Qbtwo4VKUCCSUs6QSgAuUh7Yxo57tojPCIzCO vceIudO+sYdpRJxbp28jlvErEWAqiwfe/vl9QL5OMz/dlbB8k9aLLG3Rm8BjzZbgLmvF sHmXauvqVpNAecYN9dMuXIZWYm7y0/akd7G/SiBfJ4Ux2t0/42G6qW2f60pPO6ypMlbP lcBw/iS/aSXGxCO2t8dMo3svuDWrgzS82A4enHsORJ0hxIBXdXmOAvEOpCp3dZGp2oem UoAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oRmwNyJG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a95si21707874pla.350.2019.03.27.12.33.10; Wed, 27 Mar 2019 12:33:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oRmwNyJG; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1732968AbfC0TcO (ORCPT + 99 others); Wed, 27 Mar 2019 15:32:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:42646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731337AbfC0SCn (ORCPT ); Wed, 27 Mar 2019 14:02:43 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 14BF92183F; Wed, 27 Mar 2019 18:02:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709762; bh=CbAhMA3lg9JDPTBM/DaZXG/h9VWpHuEJOUQzn66PHgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oRmwNyJG63fnfRebzQaINBoI/wb3e7JIrtsWV0RU0wLTq48gxYwP5ZHd6e9JzFsxX sDLQyXj7cH1SWaW3CYJw0SwP74VgIgziGQz88iLvaHEBRW7BqJS33Vnp5UVGlAZgca Zb+Y7OdPPI/cpOP4zKqP1vsX39jlmjxy4fBiA9VA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Joe Perches , Greg Kroah-Hartman , Andy Gross , David Brown , Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Sasha Levin , linux-arm-msm@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 027/262] iio: adc: fix warning in Qualcomm PM8xxx HK/XOADC driver Date: Wed, 27 Mar 2019 13:58:02 -0400 Message-Id: <20190327180158.10245-27-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Linus Torvalds [ Upstream commit e0f0ae838a25464179d37f355d763f9ec139fc15 ] The pm8xxx_get_channel() implementation is unclear, and causes gcc to suddenly generate odd warnings. The trigger for the warning (at least for me) was the entirely unrelated commit 79a4e91d1bb2 ("device.h: Add __cold to dev_ logging functions"), which apparently changes gcc code generation in the caller function enough to cause this: drivers/iio/adc/qcom-pm8xxx-xoadc.c: In function ‘pm8xxx_xoadc_probe’: drivers/iio/adc/qcom-pm8xxx-xoadc.c:633:8: warning: ‘ch’ may be used uninitialized in this function [-Wmaybe-uninitialized] ret = pm8xxx_read_channel_rsv(adc, ch, AMUX_RSV4, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ &read_nomux_rsv4, true); ~~~~~~~~~~~~~~~~~~~~~~~ drivers/iio/adc/qcom-pm8xxx-xoadc.c:426:27: note: ‘ch’ was declared here struct pm8xxx_chan_info *ch; ^~ because gcc for some reason then isn't able to see that the termination condition for the "for( )" loop in that function is also the condition for returning NULL. So it's not _actually_ uninitialized, but the function is admittedly just unnecessarily oddly written. Simplify and clarify the function, making gcc also see that it always returns a valid initialized value. Cc: Joe Perches Cc: Greg Kroah-Hartman Cc: Andy Gross Cc: David Brown Cc: Jonathan Cameron Cc: Hartmut Knaack Cc: Lars-Peter Clausen Cc: Peter Meerwald-Stadler Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c index c30c002f1fef..4735f8a1ca9d 100644 --- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c +++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c @@ -423,18 +423,14 @@ static irqreturn_t pm8xxx_eoc_irq(int irq, void *d) static struct pm8xxx_chan_info * pm8xxx_get_channel(struct pm8xxx_xoadc *adc, u8 chan) { - struct pm8xxx_chan_info *ch; int i; for (i = 0; i < adc->nchans; i++) { - ch = &adc->chans[i]; + struct pm8xxx_chan_info *ch = &adc->chans[i]; if (ch->hwchan->amux_channel == chan) - break; + return ch; } - if (i == adc->nchans) - return NULL; - - return ch; + return NULL; } static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc, -- 2.19.1