Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3339664imu; Sun, 11 Nov 2018 12:44:10 -0800 (PST) X-Google-Smtp-Source: AJdET5ejJSh7UCdsOCO1hKdYaQH5V6nUfvbBgq8TS7mJwH/k45hlKNYfZ59hEmKsvYfoTpcY/huu X-Received: by 2002:a17:902:31a4:: with SMTP id x33-v6mr17253189plb.105.1541969050730; Sun, 11 Nov 2018 12:44:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541969050; cv=none; d=google.com; s=arc-20160816; b=oEavOsSFVEFsU1CtUJIlQ+qCqntrvMIMVP9w5Ks5XRSSIEt9f5RQ+OeyjxgBqmeyAq rTv/Rkq4ch2Ds5npzy7XZUNbgh3f/6nyFQuJ26ktrQs+JPgXQ9zlCDtCpVwk2npsaY+C ibumJiLv2Njh9KYv+2YZAuHVwE9aK6qsfmR++qb8DKLyJFrL09Xga9VQK6jPqKITWyaC rdbgLfJOeXicvwq9pXf0NK7PFd7Zh/kZFgK8eV55OkxwFt0dgmzZ5hxQSOPR4o7Xd17V b7iQCWvRQafEtCW6tyTzyWWLe3/LBHz5jQfP5WHLscI+WWCWqDD8IMb424EttaB1oB67 MJkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=Br09m6RGk53KEqxrspMEM+yM60evmNsTaIUlj7kwVHY=; b=XiO2A19jSwJpQGb/GEwS5oIovnVUXPYik8izfmw6ZaAyPOZixCzXD5thkxKPy7WJB+ gcSkF6jUYL3yL8XxXq6OqYJnlwLG+FMXjQSEK124zegEkpOqyrr4DGoVBqzGdLPlWoBK YkYyNA49DAPjh4FBGvSr73QJn3a2dakEnQfJogz7DLINzbMz3g84uwehGC2y0S7z7Bfn 2BfgdbgkC1LCRgskSsUuT1UZr/AnKn4JE4xcT4+NtPgFWadfugodOmOnsOIAKjSu5+rs olccKHBiVuJWo+mlJL8YJMMCuR+ELWTioUttiGV/WJJURE38AJxvC3kBmatXh2uehHsD 8Fwg== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o4-v6si13170082pgj.306.2018.11.11.12.43.56; Sun, 11 Nov 2018 12:44:10 -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 S1729955AbeKLGcc (ORCPT + 99 others); Mon, 12 Nov 2018 01:32:32 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:49320 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729753AbeKLFsB (ORCPT ); Mon, 12 Nov 2018 00:48:01 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsN-0000lD-Qs; Sun, 11 Nov 2018 19:58:31 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsN-0001Mj-LF; Sun, 11 Nov 2018 19:58:31 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Darren Hart" , "Paul Bolle" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 009/366] eeepc-laptop: simplify parse_arg() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paul Bolle commit 95369a73a957ad221f1d6b8f11a63a376f38c544 upstream. parse_arg() has three possible return values: -EINVAL if sscanf(), in short, fails; zero if "count" is zero; and "count" in all other cases But "count" will never be zero. See, parse_arg() is called by the various store functions. And the callchain of these functions starts with sysfs_kf_write(). And that function checks for a zero "count". So we can stop checking for a zero "count", drop the "count" argument entirely, and transform parse_arg() into a function that returns zero on success or a negative error. That, in turn, allows to make those store functions just return "count" on success. The net effect is that the code becomes a bit easier to understand. A nice side effect is that this GCC warning is silenced too: drivers/platform/x86/eeepc-laptop.c: In function ‘store_sys_acpi’: drivers/platform/x86/eeepc-laptop.c:279:10: warning: ‘value’ may be used uninitialized in this function [-Wmaybe-uninitialized] int rv, value; Which is, of course, the reason to have a look at parse_arg(). Signed-off-by: Paul Bolle Signed-off-by: Darren Hart Signed-off-by: Ben Hutchings --- drivers/platform/x86/eeepc-laptop.c | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -263,13 +263,11 @@ static int acpi_setter_handle(struct eee /* * Sys helpers */ -static int parse_arg(const char *buf, unsigned long count, int *val) +static int parse_arg(const char *buf, int *val) { - if (!count) - return 0; if (sscanf(buf, "%i", val) != 1) return -EINVAL; - return count; + return 0; } static ssize_t store_sys_acpi(struct device *dev, int cm, @@ -278,12 +276,13 @@ static ssize_t store_sys_acpi(struct dev struct eeepc_laptop *eeepc = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) - value = set_acpi(eeepc, cm, value); - if (value < 0) + rv = parse_arg(buf, &value); + if (rv < 0) + return rv; + rv = set_acpi(eeepc, cm, value); + if (rv < 0) return -EIO; - return rv; + return count; } static ssize_t show_sys_acpi(struct device *dev, int cm, char *buf) @@ -377,13 +376,13 @@ static ssize_t store_cpufv(struct device return -EPERM; if (get_cpufv(eeepc, &c)) return -ENODEV; - rv = parse_arg(buf, count, &value); + rv = parse_arg(buf, &value); if (rv < 0) return rv; - if (!rv || value < 0 || value >= c.num) + if (value < 0 || value >= c.num) return -EINVAL; set_acpi(eeepc, CM_ASL_CPUFV, value); - return rv; + return count; } static ssize_t show_cpufv_disabled(struct device *dev, @@ -402,7 +401,7 @@ static ssize_t store_cpufv_disabled(stru struct eeepc_laptop *eeepc = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); + rv = parse_arg(buf, &value); if (rv < 0) return rv; @@ -412,7 +411,7 @@ static ssize_t store_cpufv_disabled(stru pr_warn("cpufv enabled (not officially supported " "on this model)\n"); eeepc->cpufv_disabled = false; - return rv; + return count; case 1: return -EPERM; default: @@ -1042,10 +1041,11 @@ static ssize_t store_sys_hwmon(void (*se { int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) - set(value); - return rv; + rv = parse_arg(buf, &value); + if (rv < 0) + return rv; + set(value); + return count; } static ssize_t show_sys_hwmon(int (*get)(void), char *buf)