From patchwork Fri Aug 5 20:57:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Giedrius Statkevi?ius X-Patchwork-Id: 9265743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E382860839 for ; Fri, 5 Aug 2016 20:57:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5CD728472 for ; Fri, 5 Aug 2016 20:57:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9E7528486; Fri, 5 Aug 2016 20:57:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B74128472 for ; Fri, 5 Aug 2016 20:57:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2998834AbcHEU5b (ORCPT ); Fri, 5 Aug 2016 16:57:31 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36329 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2998820AbcHEU50 (ORCPT ); Fri, 5 Aug 2016 16:57:26 -0400 Received: by mail-wm0-f67.google.com with SMTP id x83so5308741wma.3; Fri, 05 Aug 2016 13:57:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kYEdsP7umJCWWT9WQ+Rtd+QhAiVaJ7LnHgwRwjTIw88=; b=Sjg3O3Kh6AG90XSmb5bFerTftDUFJYarRCah4rQbGeLfKO8V/PyRsq5dV2FP1FPtn1 El35O3gHu5RMn+G0ofYE15LjCEsyywgSDNwQysADtopy+ul2h7UqBC7atZ3QuUiNbHP0 07qGy8sXI3tTJ7LKtli8szWvfGaMIj7CxksjLr4b2ENWUd04EgQLdJhq+Eexa4tQlVRk rpjHtcDPnyotpcbeIYgJ66j+rqevOqglCoUAE3reN0PcAwzFMgQQARS9uAnHO6G40bg5 wNjMdwDwvBdgXKY+abqNWqSv28UJP/Zgr7GE9snSDRsdmwed0iIYljmlaWMts5HdJPBj dXzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kYEdsP7umJCWWT9WQ+Rtd+QhAiVaJ7LnHgwRwjTIw88=; b=eluXeKoX4UmbhGC4j4MhdZ/pzvxvJjp5XeTpSdfgSyrZBC/FsWUKmr5Wm6VTdijoDM y8gtExeV2/jLCgV+md650yutDip3rhmOmoOp5P7CH9iZIUo8DzRy5dUR7FG99uCZFFRr gJZRkvJXrL2BgsgL8bUBCjADezkaPDC1IvsfBfSVlajfVP6CwTdAHuCoB8kNEu651FIU 4hCK2/B+TafxEpTovPFOvy2bxxvb1etzW2f4QH7CkzSPlf8t1pmIrDicFy6QHf0Z0xiT pGN5bOzlrhIIzjojhE8gnLA7BqZwQiD/zodIkXRDOF3l0+K7TtZHl40QAAaqrou/nH1m DGTw== X-Gm-Message-State: AEkoousV9+DV+86ksahMNQSp1AvnMpyUSUzCDf0ILdKFJRFgj3Wa9BjaQSlWgq8EMyxnSA== X-Received: by 10.28.35.193 with SMTP id j184mr4988152wmj.33.1470430644086; Fri, 05 Aug 2016 13:57:24 -0700 (PDT) Received: from localhost.localdomain (78-57-189-147.static.zebra.lt. [78.57.189.147]) by smtp.gmail.com with ESMTPSA id vv2sm8193675wjc.29.2016.08.05.13.57.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 05 Aug 2016 13:57:23 -0700 (PDT) From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= To: corentin.chary@gmail.com, dvhart@infradead.org Cc: acpi4asus-user@lists.sourceforge.net, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Subject: [PATCH] asus-laptop: get rid of parse_arg() Date: Fri, 5 Aug 2016 23:57:10 +0300 Message-Id: <20160805205710.4735-1-giedrius.statkevicius@gmail.com> X-Mailer: git-send-email 2.9.0 MIME-Version: 1.0 Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP parse_arg() duplicates the funcionality of kstrtoint() so use the latter function instead. There is no funcionality change except that in the case of input being too big -ERANGE will be returned instead of -EINVAL which is not bad because -ERANGE makes more sense here. The check for !count is already done by the sysfs core so no need to duplicate it again. Also, add some minor corrections to error handling to accommodate the change in return values (parse_arg returned count if everything succeeded whereas kstrtoint returns 0 in the same situation) As a result of this patch asus-laptop.ko size is reduced by almost 1%: add/remove: 0/1 grow/shrink: 1/6 up/down: 1/-149 (-148) function old new delta __UNIQUE_ID_vermagic0 69 70 +1 ls_switch_store 133 117 -16 ledd_store 175 159 -16 display_store 157 141 -16 ls_level_store 193 176 -17 gps_store 200 178 -22 sysfs_acpi_set.isra 148 125 -23 parse_arg.part 39 - -39 Total: Before=19160, After=19012, chg -0.77% Signed-off-by: Giedrius Statkevičius --- drivers/platform/x86/asus-laptop.c | 77 ++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index 15f1311..28551f5 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -932,30 +932,19 @@ static ssize_t infos_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(infos); -static int parse_arg(const char *buf, unsigned long count, int *val) -{ - if (!count) - return 0; - if (count > 31) - return -EINVAL; - if (sscanf(buf, "%i", val) != 1) - return -EINVAL; - return count; -} - static ssize_t sysfs_acpi_set(struct asus_laptop *asus, const char *buf, size_t count, const char *method) { int rv, value; - rv = parse_arg(buf, count, &value); - if (rv <= 0) + rv = kstrtoint(buf, 0, &value); + if (rv < 0) return rv; if (write_acpi_int(asus->handle, method, value)) return -ENODEV; - return rv; + return count; } /* @@ -975,15 +964,17 @@ static ssize_t ledd_store(struct device *dev, struct device_attribute *attr, struct asus_laptop *asus = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) { - if (write_acpi_int(asus->handle, METHOD_LEDD, value)) { - pr_warn("LED display write failed\n"); - return -ENODEV; - } - asus->ledd_status = (u32) value; + rv = kstrtoint(buf, 0, &value); + if (rv < 0) + return rv; + + if (write_acpi_int(asus->handle, METHOD_LEDD, value)) { + pr_warn("LED display write failed\n"); + return -ENODEV; } - return rv; + + asus->ledd_status = (u32) value; + return count; } static DEVICE_ATTR_RW(ledd); @@ -1148,10 +1139,12 @@ static ssize_t display_store(struct device *dev, struct device_attribute *attr, struct asus_laptop *asus = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) - asus_set_display(asus, value); - return rv; + rv = kstrtoint(buf, 0, &value); + if (rv < 0) + return rv; + + asus_set_display(asus, value); + return count; } static DEVICE_ATTR_WO(display); @@ -1190,11 +1183,12 @@ static ssize_t ls_switch_store(struct device *dev, struct asus_laptop *asus = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) - asus_als_switch(asus, value ? 1 : 0); + rv = kstrtoint(buf, 0, &value); + if (rv < 0) + return rv; - return rv; + asus_als_switch(asus, value ? 1 : 0); + return count; } static DEVICE_ATTR_RW(ls_switch); @@ -1219,14 +1213,15 @@ static ssize_t ls_level_store(struct device *dev, struct device_attribute *attr, struct asus_laptop *asus = dev_get_drvdata(dev); int rv, value; - rv = parse_arg(buf, count, &value); - if (rv > 0) { - value = (0 < value) ? ((15 < value) ? 15 : value) : 0; - /* 0 <= value <= 15 */ - asus_als_level(asus, value); - } + rv = kstrtoint(buf, 0, &value); + if (rv < 0) + return rv; + + value = (0 < value) ? ((15 < value) ? 15 : value) : 0; + /* 0 <= value <= 15 */ + asus_als_level(asus, value); - return rv; + return count; } static DEVICE_ATTR_RW(ls_level); @@ -1301,14 +1296,14 @@ static ssize_t gps_store(struct device *dev, struct device_attribute *attr, int rv, value; int ret; - rv = parse_arg(buf, count, &value); - if (rv <= 0) - return -EINVAL; + rv = kstrtoint(buf, 0, &value); + if (rv < 0) + return rv; ret = asus_gps_switch(asus, !!value); if (ret) return ret; rfkill_set_sw_state(asus->gps.rfkill, !value); - return rv; + return count; } static DEVICE_ATTR_RW(gps);