From patchwork Mon Jan 25 15:52:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 101117 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1437678lbb; Mon, 25 Jan 2016 07:53:43 -0800 (PST) X-Received: by 10.98.14.69 with SMTP id w66mr26852219pfi.144.1453737223704; Mon, 25 Jan 2016 07:53:43 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n63si20543938pfb.139.2016.01.25.07.53.43; Mon, 25 Jan 2016 07:53:43 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933033AbcAYPxl (ORCPT + 30 others); Mon, 25 Jan 2016 10:53:41 -0500 Received: from mout.kundenserver.de ([217.72.192.74]:52183 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932224AbcAYPxg (ORCPT ); Mon, 25 Jan 2016 10:53:36 -0500 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue103) with ESMTPA (Nemesis) id 0MTNxP-1aV7Yy0P4B-00SQgq; Mon, 25 Jan 2016 16:52:59 +0100 From: Arnd Bergmann To: Lars-Peter Clausen , Michael Hennerich Cc: linux-arm-kernel@lists.infradead.org, Arnd Bergmann , Jonathan Cameron , Hartmut Knaack , Peter Meerwald , Greg Kroah-Hartman , linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH] iio: ade7753: avoid uninitialized data Date: Mon, 25 Jan 2016 16:52:40 +0100 Message-Id: <1453737174-1959778-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:TRlBUoKgCBt916gIvk8uCblpcX6lcGja5eMJ0JgTtAiyogPqraS ssw3PJSdKf0KED9l+n6sOR+amU6kyo8112f3qBlTBGGAvUbCd2FDYg0V/BtjiPNRTwaM+cb ShdobyYgCwlGxqxboZvT2nY7AbWHUsQMsvF5MA/c+IbTso+SWHuZHQbgcE/sCNDxHEHNRMd 8iDHrFOiil7U5dqYAaWLg== X-UI-Out-Filterresults: notjunk:1; V01:K0:M2b0adGrYXE=:A2rcO5cmzNKtKiIUTCvfRP moojbnlM48yWFUrTKFoXUODAut3nJsJoijWKs4H/JuVVFZJtsabbfzFBr/n0KIkOLZvFnGgxn 88KsJxyJNbWLkiXg6GKUA7dpbD1+kY4kne7slNOx9drij5JF3evTVV9sRyp0LZfM2T5DmyAo7 dxXBrhaZC8/EdB2i8pyWcOF5QCWl18mWPpZ3izGJovDuLyc3F8mULQi8fq64O6+t3JTnI2bqU d3gj/wOBPyajdJ/A38oqZWGxuDoVgZZPF/ux7fpd550gcD3Q0p23z75oL0JRsb8QhZoDtnorp jgFcjrEcKjDGBnlTVajFbjeVgqtl5Mk7J2vW63/0TYsXekEnqol1xmLSQZLGiGS5IGMErLk8A ukX/UOLT4M7m8J9u6N2/zba2lrkap0sXRqNzVLcEX1INmTXv+OuQXTGq860oR4LkcKvLRSCPt dO39j140fZukwYB7YPDtRtO1F1QCzu1HDmqUpKYbg4dH2EqoQyVCFmem5h9zEA/1fbfqMPktI zQjXKWTfwNT7kaVckomuhhDpgEFVH771WhBWSX/omFSVkhshk5uRgUbzMGtccFWXqDwniScpX a8Pql6AlTpQgPaDPIzovLdqrtry+ZQbtOTYKIMtCJHf2Eb+KqVaeaxLm7Zey1Rj9oq/7+63c4 jAFrVVuhNZk0yBymvMqSJbSLXy6tOovdoe2k7PZ2WMIrsAjxvhBqyvbIYPM1QkMwQtL4= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ade7753_spi_read_reg_16() will either successfully read a value from SPI, or return a failure code without delivering data. However, the ade7753_stop_device() and ade7753_reset() functions use the returned data without checking for an error condition first. Gcc detects this as a possible bug and warns about it: drivers/staging/iio/meter/ade7753.c: In function 'ade7753_remove': drivers/staging/iio/meter/ade7753.c:348:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized] val |= BIT(4); /* AD converters can be turned off */ ^ drivers/staging/iio/meter/ade7753.c:345:6: note: 'val' was declared here u16 val; ^ drivers/staging/iio/meter/ade7753.c: In function 'ade7753_probe': drivers/staging/iio/meter/ade7753.c:222:6: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized] In both cases, we can avoids the warning by checking the return code before using the data. Signed-off-by: Arnd Bergmann --- drivers/staging/iio/meter/ade7753.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) -- 2.7.0 diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c index f129039bece3..69287108f793 100644 --- a/drivers/staging/iio/meter/ade7753.c +++ b/drivers/staging/iio/meter/ade7753.c @@ -217,8 +217,12 @@ error_ret: static int ade7753_reset(struct device *dev) { u16 val; + int ret; + + ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val); + if (ret) + return ret; - ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val); val |= BIT(6); /* Software Chip Reset */ return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val); @@ -343,8 +347,12 @@ error_ret: static int ade7753_stop_device(struct device *dev) { u16 val; + int ret; + + ret = ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val); + if (ret) + return ret; - ade7753_spi_read_reg_16(dev, ADE7753_MODE, &val); val |= BIT(4); /* AD converters can be turned off */ return ade7753_spi_write_reg_16(dev, ADE7753_MODE, val);