From patchwork Wed Sep 9 22:08:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 7149501 Return-Path: X-Original-To: patchwork-platform-driver-x86@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C52C39F1D3 for ; Wed, 9 Sep 2015 22:09:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD1712093B for ; Wed, 9 Sep 2015 22:09:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D35062094B for ; Wed, 9 Sep 2015 22:09:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753078AbbIIWJF (ORCPT ); Wed, 9 Sep 2015 18:09:05 -0400 Received: from mail-la0-f42.google.com ([209.85.215.42]:33766 "EHLO mail-la0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752907AbbIIWJE (ORCPT ); Wed, 9 Sep 2015 18:09:04 -0400 Received: by lamp12 with SMTP id p12so15790208lam.0 for ; Wed, 09 Sep 2015 15:09:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hlbCAZploET/c/vAVpAbpMJQiNdEK6yoDc8svmxApB8=; b=g/6Muv08VY4sQjc12+Ygz0o8Kqdo6flX2RaYYZq1vod06oPI6a6qI3G0wn6M6MKTZ5 juygN68TjdubxAtOPYF3bbCYoxSjK7PyjvqBzZo0uF3dp5/UAP0xj09n6RwxSV/Y6Xa/ MNF+fPM+eAPSQcauaQaAW5sLzn2hSwfiGFWsA= 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:in-reply-to :references; bh=hlbCAZploET/c/vAVpAbpMJQiNdEK6yoDc8svmxApB8=; b=IDBCNqqhQQO3Ft8Vr7seRIYK7zmut7fXgVdc5fEk/vPcCTWcTn0ox9J33IAnYvta8Z 2086qHBcNYMVTVOH/jI+D94hODg0EylFkCyKJwuvCZo+oFhOoMLQjiWWFRHDSDhpl4kq i1+DDULXTswr5od1tKydBZ8xkogwZsG80ogTbFd6TXe+vnGH0mfmjhyVH2C6Xgx0MAaH Th6b/jtZRAEw1UOoVbOFF70QciZs0J7LuXLkzGue4y3Pa38G2kF9JC4vyQCo7khC1NF2 oVRdVOflyohFuWYcUmtaFeNVC6OZFe7WtxMpYwNvzKBQdgCR+jwMV4XKmOTzClf8wlVP AThQ== X-Gm-Message-State: ALoCoQkOuZTeNkLxVgOgo9q8WqK0RZ8m+To1rTiTAgiFdneY4RlwJuml24N0lgOkxqYPwxbQHHbP X-Received: by 10.112.54.132 with SMTP id j4mr31275589lbp.84.1441836542293; Wed, 09 Sep 2015 15:09:02 -0700 (PDT) Received: from spencer.imf.au.dk ([130.225.20.51]) by smtp.gmail.com with ESMTPSA id nv3sm2116591lbb.24.2015.09.09.15.09.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Sep 2015 15:09:01 -0700 (PDT) From: Rasmus Villemoes To: Darren Hart Cc: Rasmus Villemoes , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86: wmi: Remove private %pUL implementation Date: Thu, 10 Sep 2015 00:08:45 +0200 Message-Id: <1441836525-26194-1-git-send-email-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.1.3 In-Reply-To: <87r3qm6lvg.fsf@rasmusvillemoes.dk> References: <87r3qm6lvg.fsf@rasmusvillemoes.dk> Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The work performed by wmi_gtoa is equivalent to simply sprintf(out, "%pUL", in), so one could replace its body by this. However, most users feed the result directly as a %s argument to some other function which also understands the %p extensions (they all ultimately use vsnprintf), so we can eliminate some stack buffers and quite a bit of code by just using %pUL directly. In wmi_dev_uevent I'm not sure whether there's room for a nul-terminator in env->buf, so I've just replaced wmi_gtoa with the equivalent sprintf call. Signed-off-by: Rasmus Villemoes --- Resending, hoping to get it picked up this time. drivers/platform/x86/wmi.c | 51 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 45 deletions(-) diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index aac47573f9ed..eb391a281833 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -194,34 +194,6 @@ static bool wmi_parse_guid(const u8 *src, u8 *dest) return true; } -/* - * Convert a raw GUID to the ACII string representation - */ -static int wmi_gtoa(const char *in, char *out) -{ - int i; - - for (i = 3; i >= 0; i--) - out += sprintf(out, "%02X", in[i] & 0xFF); - - out += sprintf(out, "-"); - out += sprintf(out, "%02X", in[5] & 0xFF); - out += sprintf(out, "%02X", in[4] & 0xFF); - out += sprintf(out, "-"); - out += sprintf(out, "%02X", in[7] & 0xFF); - out += sprintf(out, "%02X", in[6] & 0xFF); - out += sprintf(out, "-"); - out += sprintf(out, "%02X", in[8] & 0xFF); - out += sprintf(out, "%02X", in[9] & 0xFF); - out += sprintf(out, "-"); - - for (i = 10; i <= 15; i++) - out += sprintf(out, "%02X", in[i] & 0xFF); - - *out = '\0'; - return 0; -} - static bool find_guid(const char *guid_string, struct wmi_block **out) { char tmp[16], guid_input[16]; @@ -457,11 +429,7 @@ EXPORT_SYMBOL_GPL(wmi_set_block); static void wmi_dump_wdg(const struct guid_block *g) { - char guid_string[37]; - - wmi_gtoa(g->guid, guid_string); - - pr_info("%s:\n", guid_string); + pr_info("%pUL:\n", g->guid); pr_info("\tobject_id: %c%c\n", g->object_id[0], g->object_id[1]); pr_info("\tnotify_id: %02X\n", g->notify_id); pr_info("\treserved: %02X\n", g->reserved); @@ -661,7 +629,6 @@ EXPORT_SYMBOL_GPL(wmi_has_guid); static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) { - char guid_string[37]; struct wmi_block *wblock; wblock = dev_get_drvdata(dev); @@ -670,9 +637,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, return strlen(buf); } - wmi_gtoa(wblock->gblock.guid, guid_string); - - return sprintf(buf, "wmi:%s\n", guid_string); + return sprintf(buf, "wmi:%pUL\n", wblock->gblock.guid); } static DEVICE_ATTR_RO(modalias); @@ -695,7 +660,7 @@ static int wmi_dev_uevent(struct device *dev, struct kobj_uevent_env *env) if (!wblock) return -ENOMEM; - wmi_gtoa(wblock->gblock.guid, guid_string); + sprintf(guid_string, "%pUL", wblock->gblock.guid); strcpy(&env->buf[env->buflen - 1], "wmi:"); memcpy(&env->buf[env->buflen - 1 + 4], guid_string, 36); @@ -721,12 +686,9 @@ static struct class wmi_class = { static int wmi_create_device(const struct guid_block *gblock, struct wmi_block *wblock, acpi_handle handle) { - char guid_string[37]; - wblock->dev.class = &wmi_class; - wmi_gtoa(gblock->guid, guid_string); - dev_set_name(&wblock->dev, "%s", guid_string); + dev_set_name(&wblock->dev, "%pUL", gblock->guid); dev_set_drvdata(&wblock->dev, wblock); @@ -877,7 +839,6 @@ static void acpi_wmi_notify(struct acpi_device *device, u32 event) struct guid_block *block; struct wmi_block *wblock; struct list_head *p; - char guid_string[37]; list_for_each(p, &wmi_block_list) { wblock = list_entry(p, struct wmi_block, list); @@ -888,8 +849,8 @@ static void acpi_wmi_notify(struct acpi_device *device, u32 event) if (wblock->handler) wblock->handler(event, wblock->handler_data); if (debug_event) { - wmi_gtoa(wblock->gblock.guid, guid_string); - pr_info("DEBUG Event GUID: %s\n", guid_string); + pr_info("DEBUG Event GUID: %pUL\n", + wblock->gblock.guid); } acpi_bus_generate_netlink_event(