From patchwork Tue Apr 12 22:00:09 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 702231 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3CM0Q7x014649 for ; Tue, 12 Apr 2011 22:00:27 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932415Ab1DLWAZ (ORCPT ); Tue, 12 Apr 2011 18:00:25 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:60790 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932322Ab1DLWAZ (ORCPT ); Tue, 12 Apr 2011 18:00:25 -0400 Received: from imap1.linux-foundation.org (imap1.linux-foundation.org [140.211.169.55]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p3CM0AtP030789 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 12 Apr 2011 15:00:10 -0700 Received: from akpm.mtv.corp.google.com (localhost [127.0.0.1]) by imap1.linux-foundation.org (8.13.5.20060308/8.13.5/Debian-3ubuntu1.1) with SMTP id p3CM09JG005275; Tue, 12 Apr 2011 15:00:09 -0700 Date: Tue, 12 Apr 2011 15:00:09 -0700 From: Andrew Morton To: Liu Yuan Cc: Richard Purdie , Paul Mundt , linux-fbdev@vger.kernel.org, Michael Hennerich Subject: Re: [PATCH] drivers, video: Add a check for strict_strtoul() Message-Id: <20110412150009.243f6089.akpm@linux-foundation.org> In-Reply-To: <1302167178-9216-1-git-send-email-namei.unix@gmail.com> References: <1302167178-9216-1-git-send-email-namei.unix@gmail.com> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Spam-Status: No, hits=-104.984 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED, PATCH_SUBJECT_OSDL, USER_IN_WHITELIST X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 12 Apr 2011 22:00:27 +0000 (UTC) On Thu, 7 Apr 2011 17:06:18 +0800 Liu Yuan wrote: > From: Liu Yuan > > It should check if strict_strtoul() succeeds.This > patch fixes it. > > Signed-off-by: Liu Yuan > --- > drivers/video/backlight/adp5520_bl.c | 4 +++- > 1 files changed, 3 insertions(+), 1 deletions(-) > > diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c > index af31197..fdef632 100644 > --- a/drivers/video/backlight/adp5520_bl.c > +++ b/drivers/video/backlight/adp5520_bl.c > @@ -212,7 +212,9 @@ static ssize_t adp5520_bl_daylight_max_store(struct device *dev, > { > struct adp5520_bl *data = dev_get_drvdata(dev); > > - strict_strtoul(buf, 10, &data->cached_daylight_max); > + if (strict_strtoul(buf, 10, &data->cached_daylight_max) < 0) > + return -EINVAL; > + > return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_MAX); > } It is better to propagate strict_strtoul()'s errno, rather than overriding it: --- a/drivers/video/backlight/adp5520_bl.c~drivers-video-backlight-adp5520_blc-check-strict_strtoul-return-value-fix +++ a/drivers/video/backlight/adp5520_bl.c @@ -211,9 +211,11 @@ static ssize_t adp5520_bl_daylight_max_s const char *buf, size_t count) { struct adp5520_bl *data = dev_get_drvdata(dev); + int ret; - if (strict_strtoul(buf, 10, &data->cached_daylight_max) < 0) - return -EINVAL; + ret = strict_strtoul(buf, 10, &data->cached_daylight_max); + if (ret < 0) + return ret; return adp5520_store(dev, buf, count, ADP5520_DAYLIGHT_MAX); }