From patchwork Sat Sep 4 17:56:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 12475761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5336C433EF for ; Sat, 4 Sep 2021 17:56:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B375C60F56 for ; Sat, 4 Sep 2021 17:56:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237334AbhIDR5r (ORCPT ); Sat, 4 Sep 2021 13:57:47 -0400 Received: from mail-0301.mail-europe.com ([188.165.51.139]:55162 "EHLO mail-0301.mail-europe.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237178AbhIDR5r (ORCPT ); Sat, 4 Sep 2021 13:57:47 -0400 Date: Sat, 04 Sep 2021 17:56:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1630778202; bh=1JuGZtWbEyLbOtMIRxVOBDmGks9yhQamvsxhZwQ5oJs=; h=Date:To:From:Reply-To:Subject:From; b=oiJT9uGEzaKTssh5Bx1zfw56+3nlvRNB9HZBTjMJranpYEOdi/PDLmzuoWWLtz/jR jZsdj45e2NzbfgWVP7LlpG9oQR4ElH8ww4Ln4Oiad7P7KZbhJB/MffnBW1G8F/Gf11 BPc+rVl1aenehPJDRnnCVcKEpzh9XO02aqu4DiDU= To: Hans de Goede , Mark Gross , platform-driver-x86@vger.kernel.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [RFC PATCH v1 27/30] platform/x86: wmi: introduce helper to generate method names Message-ID: <20210904175450.156801-28-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Instead of "manually" constructing the ACPI method name and hard-coding sizes in WMI functions, introduce a helper method which generates the method name for an arbitrary WMI block. Furthermore, save the appropriate buffer size into a macro. Signed-off-by: Barnabás Pőcze --- drivers/platform/x86/wmi.c | 42 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 15 deletions(-) -- 2.33.0 diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index ff33ad2053f0..4f484677759b 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -195,6 +195,22 @@ static acpi_status wmi_method_enable(struct wmi_block *wblock, bool enable) return status; } +#define WMI_ACPI_METHOD_NAME_SIZE 5 + +static inline void get_acpi_method_name(const struct wmi_block *wblock, + const char method, + char buffer[static WMI_ACPI_METHOD_NAME_SIZE]) +{ + static_assert(ARRAY_SIZE(wblock->gblock.object_id) == 2); + static_assert(WMI_ACPI_METHOD_NAME_SIZE >= 5); + + buffer[0] = 'W'; + buffer[1] = method; + buffer[2] = wblock->gblock.object_id[0]; + buffer[3] = wblock->gblock.object_id[1]; + buffer[4] = '\0'; +} + /* * Exported WMI functions */ @@ -257,7 +273,7 @@ acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance, u32 met acpi_handle handle; struct acpi_object_list input; union acpi_object params[3]; - char method[5] = "WM"; + char method[WMI_ACPI_METHOD_NAME_SIZE]; wblock = container_of(wdev, struct wmi_block, dev); block = &wblock->gblock; @@ -288,7 +304,7 @@ acpi_status wmidev_evaluate_method(struct wmi_device *wdev, u8 instance, u32 met params[2].buffer.pointer = in->pointer; } - strncat(method, block->object_id, 2); + get_acpi_method_name(wblock, 'M', method); return acpi_evaluate_object(handle, method, &input, out); } @@ -302,8 +318,8 @@ static acpi_status __query_block(struct wmi_block *wblock, u8 instance, acpi_status status, wc_status = AE_ERROR; struct acpi_object_list input; union acpi_object wq_params[1]; - char method[5]; - char wc_method[5] = "WC"; + char wc_method[WMI_ACPI_METHOD_NAME_SIZE]; + char method[WMI_ACPI_METHOD_NAME_SIZE]; if (!out) return AE_BAD_PARAMETER; @@ -331,7 +347,7 @@ static acpi_status __query_block(struct wmi_block *wblock, u8 instance, * enable collection. */ if (block->flags & ACPI_WMI_EXPENSIVE) { - strncat(wc_method, block->object_id, 2); + get_acpi_method_name(wblock, 'C', wc_method); /* * Some GUIDs break the specification by declaring themselves @@ -341,9 +357,7 @@ static acpi_status __query_block(struct wmi_block *wblock, u8 instance, wc_status = acpi_execute_simple_method(handle, wc_method, 1); } - strcpy(method, "WQ"); - strncat(method, block->object_id, 2); - + get_acpi_method_name(wblock, 'Q', method); status = acpi_evaluate_object(handle, method, &input, out); /* @@ -415,7 +429,7 @@ acpi_status wmi_set_block(const char *guid_string, u8 instance, acpi_handle handle; struct acpi_object_list input; union acpi_object params[2]; - char method[5] = "WS"; + char method[WMI_ACPI_METHOD_NAME_SIZE]; if (!guid_string || !in) return AE_BAD_DATA; @@ -446,7 +460,7 @@ acpi_status wmi_set_block(const char *guid_string, u8 instance, params[1].buffer.length = in->length; params[1].buffer.pointer = in->pointer; - strncat(method, block->object_id, 2); + get_acpi_method_name(wblock, 'S', method); return acpi_evaluate_object(handle, method, &input, NULL); } @@ -1040,7 +1054,7 @@ static int wmi_create_device(struct device *wmi_bus_dev, struct acpi_device *device) { struct acpi_device_info *info; - char method[5]; + char method[WMI_ACPI_METHOD_NAME_SIZE]; int result; if (wblock->gblock.flags & ACPI_WMI_EVENT) { @@ -1059,8 +1073,7 @@ static int wmi_create_device(struct device *wmi_bus_dev, * required per the WMI documentation. If it is not present, * we ignore this data block. */ - strcpy(method, "WQ"); - strncat(method, wblock->gblock.object_id, 2); + get_acpi_method_name(wblock, 'Q', method); result = get_subobj_info(device->handle, method, &info); if (result) { @@ -1087,8 +1100,7 @@ static int wmi_create_device(struct device *wmi_bus_dev, kfree(info); - strcpy(method, "WS"); - strncat(method, wblock->gblock.object_id, 2); + get_acpi_method_name(wblock, 'S', method); result = get_subobj_info(device->handle, method, NULL); if (result == 0)