From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933750AbaIDBOW (ORCPT ); Wed, 3 Sep 2014 21:14:22 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47979 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933250AbaIDBOV (ORCPT ); Wed, 3 Sep 2014 21:14:21 -0400 Date: Wed, 3 Sep 2014 18:14:20 -0700 From: Greg Kroah-Hartman To: Darren Hart Cc: Frans Klaver , Corentin Chary , Matthew Garrett , acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] eeepc-laptop: remove possible use of uninitialized value Message-ID: <20140904011420.GA31350@kroah.com> References: <1409784805-14190-1-git-send-email-fransklaver@gmail.com> <20140904004947.GA17138@vmdeb7> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140904004947.GA17138@vmdeb7> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 03, 2014 at 05:49:47PM -0700, Darren Hart wrote: > On Thu, Sep 04, 2014 at 12:53:25AM +0200, Frans Klaver wrote: > > In store_sys_acpi, if count equals zero, or parse_arg()s sscanf call > > fails, 'value' remains possibly uninitialized. In that case 'value' > > shouldn't be used to produce the store_sys_acpi()s return value. > > > > Only test the return value of set_acpi() if we can actually call it. > > Return rv otherwise. > > > > Signed-off-by: Frans Klaver > > --- > > drivers/platform/x86/eeepc-laptop.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c > > index bd533c2..41f12ba 100644 > > --- a/drivers/platform/x86/eeepc-laptop.c > > +++ b/drivers/platform/x86/eeepc-laptop.c > > @@ -279,10 +279,10 @@ static ssize_t store_sys_acpi(struct device *dev, int cm, > > int rv, value; > > > > rv = parse_arg(buf, count, &value); > > - if (rv > 0) > > - value = set_acpi(eeepc, cm, value); > > That was rather horrible wasn't it? :-) > > > - if (value < 0) > > - return -EIO; > > + if (rv > 0) { > > + if (set_acpi(eeepc, cm, value) < 0) > > + return -EIO; > > Is there a compelling reason not to propogate the return code of set_acpi? > (ENODEV specifically). I see -EIO in Documentation/filesystems/sysfs.txt, but > it's used by default if the show() pointer is NULL (for example), but otherwise > propogates the error. > > Specifically it states: > > - show() or store() can always return errors. If a bad value comes > through, be sure to return an error. > > Greg, does this need to be -EIO? or is returning someting like ENODEV preferable > if it more accurately reflects the error? Just return the value of set_acpi() and you should be fine. thanks, greg k-h