]>
Commit | Line | Data |
---|---|---|
04fd09d4 SL |
1 | From c0f68ddd6dd37351490e451431bf1567ce7e8944 Mon Sep 17 00:00:00 2001 |
2 | From: Linus Torvalds <torvalds@linux-foundation.org> | |
3 | Date: Wed, 6 Mar 2019 15:41:29 -0800 | |
4 | Subject: iio: adc: fix warning in Qualcomm PM8xxx HK/XOADC driver | |
5 | MIME-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | [ Upstream commit e0f0ae838a25464179d37f355d763f9ec139fc15 ] | |
10 | ||
11 | The pm8xxx_get_channel() implementation is unclear, and causes gcc to | |
12 | suddenly generate odd warnings. The trigger for the warning (at least | |
13 | for me) was the entirely unrelated commit 79a4e91d1bb2 ("device.h: Add | |
14 | __cold to dev_<level> logging functions"), which apparently changes gcc | |
15 | code 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 | ||
27 | because gcc for some reason then isn't able to see that the termination | |
28 | condition for the "for( )" loop in that function is also the condition | |
29 | for returning NULL. | |
30 | ||
31 | So it's not _actually_ uninitialized, but the function is admittedly | |
32 | just unnecessarily oddly written. | |
33 | ||
34 | Simplify and clarify the function, making gcc also see that it always | |
35 | returns a valid initialized value. | |
36 | ||
37 | Cc: Joe Perches <joe@perches.com> | |
38 | Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
39 | Cc: Andy Gross <andy.gross@linaro.org> | |
40 | Cc: David Brown <david.brown@linaro.org> | |
41 | Cc: Jonathan Cameron <jic23@kernel.org> | |
42 | Cc: Hartmut Knaack <knaack.h@gmx.de> | |
43 | Cc: Lars-Peter Clausen <lars@metafoo.de> | |
44 | Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> | |
45 | Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> | |
46 | Signed-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 | ||
51 | diff --git a/drivers/iio/adc/qcom-pm8xxx-xoadc.c b/drivers/iio/adc/qcom-pm8xxx-xoadc.c | |
52 | index 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 | -- | |
78 | 2.19.1 | |
79 |