From patchwork Sat Sep 4 17:56:44 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: 12475765 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 18EBEC433F5 for ; Sat, 4 Sep 2021 17:56:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0D1B60F56 for ; Sat, 4 Sep 2021 17:56:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237247AbhIDR54 (ORCPT ); Sat, 4 Sep 2021 13:57:56 -0400 Received: from mail1.protonmail.ch ([185.70.40.18]:17734 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237178AbhIDR5z (ORCPT ); Sat, 4 Sep 2021 13:57:55 -0400 Date: Sat, 04 Sep 2021 17:56:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1630778212; bh=Lz30czYvQEjqIFQgwmtlqVRJWRZbQdHgeIDs0fZKPXI=; h=Date:To:From:Reply-To:Subject:From; b=izpsE9bT+sqGsngYWq0C4r4BpcjfKusTzxVKaSuVkwBdyNHthrOluOlZaKLzRQTZH 8Y95z/zVrw93zzXhiMmO+r9XMeJ2PjSL1HdXd1xBNjBWNGb4vz4RXs0fwlIXrfzGpJ ZIjd+bcu0oKUskPQVYtbGzMDAcpEJHVv+PlcOlqw= 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 30/30] platform/x86: wmi: more detailed error reporting in find_guid() Message-ID: <20210904175450.156801-31-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Make `find_guid()` return an acpi_status, and make it handle NULL pointer GUID strings; and adapt users accordingly. Signed-off-by: Barnabás Pőcze --- drivers/platform/x86/wmi.c | 43 ++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) -- 2.33.0 diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c index cd274de78ab4..6afe67684eef 100644 --- a/drivers/platform/x86/wmi.c +++ b/drivers/platform/x86/wmi.c @@ -114,22 +114,27 @@ static struct platform_driver acpi_wmi_driver = { * GUID parsing functions */ -static bool find_guid(const char *guid_string, struct wmi_block **out) +static acpi_status find_guid(const char *guid_string, struct wmi_block **out) { guid_t guid_input; struct wmi_block *wblock; + if (!guid_string) + return AE_BAD_PARAMETER; + if (guid_parse(guid_string, &guid_input)) - return false; + return AE_BAD_PARAMETER; list_for_each_entry(wblock, &wmi_block_list, list) { if (guid_equal(&wblock->gblock.guid, &guid_input)) { if (out) *out = wblock; - return true; + + return AE_OK; } } - return false; + + return AE_NOT_FOUND; } static const void *find_guid_context(struct wmi_block *wblock, @@ -271,9 +276,12 @@ acpi_status wmi_evaluate_method(const char *guid_string, u8 instance, u32 method const struct acpi_buffer *in, struct acpi_buffer *out) { struct wmi_block *wblock; + acpi_status status; + + status = find_guid(guid_string, &wblock); + if (ACPI_FAILURE(status)) + return status; - if (!find_guid(guid_string, &wblock)) - return AE_ERROR; return wmidev_evaluate_method(&wblock->dev, instance, method_id, in, out); } @@ -410,12 +418,11 @@ acpi_status wmi_query_block(const char *guid_string, u8 instance, struct acpi_buffer *out) { struct wmi_block *wblock; + acpi_status status; - if (!guid_string) - return AE_BAD_PARAMETER; - - if (!find_guid(guid_string, &wblock)) - return AE_ERROR; + status = find_guid(guid_string, &wblock); + if (ACPI_FAILURE(status)) + return status; return __query_block(wblock, instance, out); } @@ -450,12 +457,14 @@ acpi_status wmi_set_block(const char *guid_string, u8 instance, struct acpi_object_list input; union acpi_object params[2]; char method[WMI_ACPI_METHOD_NAME_SIZE]; + acpi_status status; - if (!guid_string || !in) + if (!in) return AE_BAD_DATA; - if (!find_guid(guid_string, &wblock)) - return AE_ERROR; + status = find_guid(guid_string, &wblock); + if (ACPI_FAILURE(status)) + return status; block = &wblock->gblock; handle = wblock->acpi_device->handle; @@ -660,7 +669,7 @@ EXPORT_SYMBOL_GPL(wmi_get_event_data); */ bool wmi_has_guid(const char *guid_string) { - return find_guid(guid_string, NULL); + return ACPI_SUCCESS(find_guid(guid_string, NULL)); } EXPORT_SYMBOL_GPL(wmi_has_guid); @@ -675,8 +684,10 @@ EXPORT_SYMBOL_GPL(wmi_has_guid); char *wmi_get_acpi_device_uid(const char *guid_string) { struct wmi_block *wblock; + acpi_status status; - if (!find_guid(guid_string, &wblock)) + status = find_guid(guid_string, &wblock); + if (ACPI_FAILURE(status)) return NULL; return acpi_device_uid(wblock->acpi_device);