]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.14.111/iio-adc-fix-warning-in-qualcomm-pm8xxx-hk-xoadc-driv.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.14.111 / iio-adc-fix-warning-in-qualcomm-pm8xxx-hk-xoadc-driv.patch
CommitLineData
04fd09d4
SL
1From c0f68ddd6dd37351490e451431bf1567ce7e8944 Mon Sep 17 00:00:00 2001
2From: Linus Torvalds <torvalds@linux-foundation.org>
3Date: Wed, 6 Mar 2019 15:41:29 -0800
4Subject: iio: adc: fix warning in Qualcomm PM8xxx HK/XOADC driver
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9[ Upstream commit e0f0ae838a25464179d37f355d763f9ec139fc15 ]
10
11The pm8xxx_get_channel() implementation is unclear, and causes gcc to
12suddenly generate odd warnings. The trigger for the warning (at least
13for me) was the entirely unrelated commit 79a4e91d1bb2 ("device.h: Add
14__cold to dev_<level> logging functions"), which apparently changes gcc
15code generation in the caller function enough to cause this:
16
17 drivers/iio/adc/qcom-pm8xxx-xoadc.c: In function ‘pm8xxx_xoadc_probe’:
18 drivers/iio/adc/qcom-pm8xxx-xoadc.c:633:8: warning: ‘ch’ may be used uninitialized in this function [-Wmaybe-uninitialized]
19 ret = pm8xxx_read_channel_rsv(adc, ch, AMUX_RSV4,
20 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
21 &read_nomux_rsv4, true);
22 ~~~~~~~~~~~~~~~~~~~~~~~
23 drivers/iio/adc/qcom-pm8xxx-xoadc.c:426:27: note: ‘ch’ was declared here
24 struct pm8xxx_chan_info *ch;
25 ^~
26
27because gcc for some reason then isn't able to see that the termination
28condition for the "for( )" loop in that function is also the condition
29for returning NULL.
30
31So it's not _actually_ uninitialized, but the function is admittedly
32just unnecessarily oddly written.
33
34Simplify and clarify the function, making gcc also see that it always
35returns a valid initialized value.
36
37Cc: Joe Perches <joe@perches.com>
38Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
39Cc: Andy Gross <andy.gross@linaro.org>
40Cc: David Brown <david.brown@linaro.org>
41Cc: Jonathan Cameron <jic23@kernel.org>
42Cc: Hartmut Knaack <knaack.h@gmx.de>
43Cc: Lars-Peter Clausen <lars@metafoo.de>
44Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net>
45Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
46Signed-off-by: Sasha Levin <sashal@kernel.org>
47---
48 drivers/iio/adc/qcom-pm8xxx-xoadc.c | 10 +++-------
49 1 file changed, 3 insertions(+), 7 deletions(-)
50
51diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
52index cea8f1fb444a..7e8da418a7b7 100644
53--- a/drivers/iio/adc/qcom-pm8xxx-xoadc.c
54+++ b/drivers/iio/adc/qcom-pm8xxx-xoadc.c
55@@ -423,18 +423,14 @@ static irqreturn_t pm8xxx_eoc_irq(int irq, void *d)
56 static struct pm8xxx_chan_info *
57 pm8xxx_get_channel(struct pm8xxx_xoadc *adc, u8 chan)
58 {
59- struct pm8xxx_chan_info *ch;
60 int i;
61
62 for (i = 0; i < adc->nchans; i++) {
63- ch = &adc->chans[i];
64+ struct pm8xxx_chan_info *ch = &adc->chans[i];
65 if (ch->hwchan->amux_channel == chan)
66- break;
67+ return ch;
68 }
69- if (i == adc->nchans)
70- return NULL;
71-
72- return ch;
73+ return NULL;
74 }
75
76 static int pm8xxx_read_channel_rsv(struct pm8xxx_xoadc *adc,
77--
782.19.1
79