From patchwork Fri Mar 8 21:01:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 2240351 Return-Path: X-Original-To: patchwork-linux-fbdev@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 406A24006E for ; Fri, 8 Mar 2013 21:01:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932383Ab3CHVBC (ORCPT ); Fri, 8 Mar 2013 16:01:02 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:49898 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932158Ab3CHVBC (ORCPT ); Fri, 8 Mar 2013 16:01:02 -0500 Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.95]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1539F864; Fri, 8 Mar 2013 21:01:01 +0000 (UTC) Date: Fri, 8 Mar 2013 13:01:00 -0800 From: Andrew Morton To: Devendra Naga Cc: Michael Hennerich , Richard Purdie , device-drivers-devel@blackfin.uclinux.org, linux-fbdev@vger.kernel.org, Jingoo Han Subject: Re: [PATCH 1/3] video: backlight: adp5520: fix compiler warning in adp5520_show Message-Id: <20130308130100.f0db69f823e6451e5ed06c9f@linux-foundation.org> In-Reply-To: <1362771069-16345-1-git-send-email-devendra.aaru@gmail.com> References: <1362771069-16345-1-git-send-email-devendra.aaru@gmail.com> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org On Fri, 8 Mar 2013 14:31:07 -0500 Devendra Naga wrote: > while compiling with make W=1 (gcc gcc (GCC) 4.7.2 20121109 (Red Hat 4.7.2-8)) > > found the following warning > > drivers/video/backlight/adp5520_bl.c: In function ___adp5520_show___: > drivers/video/backlight/adp5520_bl.c:146:6: warning: variable ___error___ set but not used [-Wunused-but-set-variable] > > fixed by removing the variable > > ... > > --- a/drivers/video/backlight/adp5520_bl.c > +++ b/drivers/video/backlight/adp5520_bl.c > @@ -143,11 +143,10 @@ static int adp5520_bl_setup(struct backlight_device *bl) > static ssize_t adp5520_show(struct device *dev, char *buf, int reg) > { > struct adp5520_bl *data = dev_get_drvdata(dev); > - int error; > uint8_t reg_val; > > mutex_lock(&data->lock); > - error = adp5520_read(data->master, reg, ®_val); > + adp5520_read(data->master, reg, ®_val); > mutex_unlock(&data->lock); > > return sprintf(buf, "%u\n", reg_val); We shouldn't just ignore the error; with the code as it stands, a adp5520_read() failure will result in the kernel displaying uninitialised garbage. So it would be better to propagate the adp5520_read() return value back to the caller if it's negative. (This assumes that the i2c layer returns a sane return value - if it does, that would make i2c pretty unique :( We could get paranoid and return a hard-wired -EIO, but it would be bad of us to overwrite things like -ENOMEM). So I'd suggest this: --- a/drivers/video/backlight/adp5520_bl.c~video-backlight-adp5520-fix-compiler-warning-in-adp5520_show +++ a/drivers/video/backlight/adp5520_bl.c @@ -143,13 +143,15 @@ static int adp5520_bl_setup(struct backl static ssize_t adp5520_show(struct device *dev, char *buf, int reg) { struct adp5520_bl *data = dev_get_drvdata(dev); - int error; + int ret; uint8_t reg_val; mutex_lock(&data->lock); - error = adp5520_read(data->master, reg, ®_val); + ret = adp5520_read(data->master, reg, ®_val); mutex_unlock(&data->lock); + if (ret < 0) + return ret; return sprintf(buf, "%u\n", reg_val); }