From patchwork Mon Nov 23 13:44:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 7682151 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 79D159F1D3 for ; Mon, 23 Nov 2015 13:47:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91D8D20707 for ; Mon, 23 Nov 2015 13:47:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A87CA20704 for ; Mon, 23 Nov 2015 13:47:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751120AbbKWNrS (ORCPT ); Mon, 23 Nov 2015 08:47:18 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:58578 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750964AbbKWNrS (ORCPT ); Mon, 23 Nov 2015 08:47:18 -0500 Received: from wuerfel.localnet ([134.3.118.24]) by mrelayeu.kundenserver.de (mreue002) with ESMTPSA (Nemesis) id 0Mc5pe-1Zjt3g1IX8-00JKew; Mon, 23 Nov 2015 14:44:14 +0100 From: Arnd Bergmann To: Jingoo Han , Lee Jones Cc: Michael Hennerich , Jean-Christophe Plagniol-Villard , Tomi Valkeinen , linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] backlight: adp88x0: fix uninitialized variable use Date: Mon, 23 Nov 2015 14:44:13 +0100 Message-ID: <3850346.cL1ocQLBvP@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) MIME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el.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP gcc correctly warns about both the adp8860 and adp8870 backlight drivers using an uninitialized variable in their error handling path: drivers/video/backlight/adp8870_bl.c: In function 'adp8870_bl_ambient_light_zone_store': drivers/video/backlight/adp8870_bl.c:811:11: warning: 'reg_val' may be used uninitialized in this function This changes the code to only write back the data if it was correctly read to start with. As a side-note, the drivers are mostly identical, so I think they should really be merged into one file to avoid having to fix every bug twice. Signed-off-by: Arnd Bergmann Acked-by: Michael Hennerich --- To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c index 98ffe71e8af2..f0d4c0324580 100644 --- a/drivers/video/backlight/adp8860_bl.c +++ b/drivers/video/backlight/adp8860_bl.c @@ -621,10 +621,12 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev, /* Set user supplied ambient light zone */ mutex_lock(&data->lock); - adp8860_read(data->client, ADP8860_CFGR, ®_val); - reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); - reg_val |= (val - 1) << CFGR_BLV_SHIFT; - adp8860_write(data->client, ADP8860_CFGR, reg_val); + ret = adp8860_read(data->client, ADP8860_CFGR, ®_val); + if (!ret) { + reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); + reg_val |= (val - 1) << CFGR_BLV_SHIFT; + adp8860_write(data->client, ADP8860_CFGR, reg_val); + } mutex_unlock(&data->lock); } diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c index 9d738352d7d4..21acac90fd77 100644 --- a/drivers/video/backlight/adp8870_bl.c +++ b/drivers/video/backlight/adp8870_bl.c @@ -807,10 +807,12 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev, /* Set user supplied ambient light zone */ mutex_lock(&data->lock); - adp8870_read(data->client, ADP8870_CFGR, ®_val); - reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); - reg_val |= (val - 1) << CFGR_BLV_SHIFT; - adp8870_write(data->client, ADP8870_CFGR, reg_val); + ret = adp8870_read(data->client, ADP8870_CFGR, ®_val); + if (!ret) { + reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); + reg_val |= (val - 1) << CFGR_BLV_SHIFT; + adp8870_write(data->client, ADP8870_CFGR, reg_val); + } mutex_unlock(&data->lock); }