Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4846560iog; Wed, 22 Jun 2022 07:02:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t8G05G+jaLPuEmW/ZkIWb9rDrtxyrUEo2U92s95Ufi9bAlezw38I5oL1XR5FmUA0RAblYD X-Received: by 2002:a17:902:c115:b0:16a:1848:89e0 with SMTP id 21-20020a170902c11500b0016a184889e0mr20072213pli.44.1655906528546; Wed, 22 Jun 2022 07:02:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655906528; cv=none; d=google.com; s=arc-20160816; b=kMTyLJsLecSCnXIzkfNyx72LOQc1iO4YijNVhQStEyvBX0a9ZGzeWuAgLLqUDenjC1 xJ0nYLdWWhieAs0KtS69L9dhX3q50Vb3PSUN6QXcw4jMvS16VPpt5Mikugz8S/azG8so moxwkLnghNz3bM2VrF7/K89XWMAC/hh25x+a8NvIaiigWanafO6TIu7B39YbctyRARvH fuJlmdt7wiP9A+LS2z0ir0gbf59CLb3nLJfy3AHY+iMVyPH6NuDULers4deQbQsBP793 SAw3TInEqnzQ66g3DFxhmlZ/1QoyfVedJOZrj7FZKnPwmz3209U3l4YWmbwJivQisnwg x78w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=JqOQ1mRCFn6Ej3pl8pj+iDE9h6BQbGKpcTypXijaYr0=; b=dnCf7tuXekVIh2PgsGM8GOiaI4MG8AYYnLZFlpscxnGatZsfzknAaQSZTDxrzmAbpz MSf2fn8Hjub7LEyhalumINwlSwnvuC7mUIvNnjuCG0MZDXRoUEYrpCN7Mpyw0yEMdA2a 7R9a1zCjcxIUkGlbmENKZyIikJ6pfa//X3KQYPLjKns99YcBYwmTSJMoZXKUwOlGOFOu 9zaBBelLWeNyCBcvX7YmkOPW0BqE66TWjZdbmOOmRyBP5aVvjaDr4DNFc6bbDDQUL3RW Xu0BY6Vf6W/sBj5xrJKRqvg4piAeslVI082ZzIlkgrpueWjgdD5/RtQa1TTmRdNzKUzm nTkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u21-20020a056a00159500b0051e77ab004fsi27446675pfk.10.2022.06.22.07.01.41; Wed, 22 Jun 2022 07:02:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352459AbiFVNTz (ORCPT + 99 others); Wed, 22 Jun 2022 09:19:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242604AbiFVNTw (ORCPT ); Wed, 22 Jun 2022 09:19:52 -0400 Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFAD82F01F; Wed, 22 Jun 2022 06:19:51 -0700 (PDT) Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-31772f8495fso161616017b3.4; Wed, 22 Jun 2022 06:19:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=JqOQ1mRCFn6Ej3pl8pj+iDE9h6BQbGKpcTypXijaYr0=; b=0tQ8NA9u/3hnZsK81/BvJnnUSvICkO0g/Wp0ibQM1F3Odcv7enRTgwzVAALGz4rYeh C8MihQmlQMiN0Yk0d4+e3cVfMupzbyKvlc3K2ct48spQ7WTEdTqYMoOr/A7N8wbOpeet D5c2BDN6q1iW1OJuv5PvYbArmcd5wOhrVUcIFew84qZWc9StjxLQxDiG+nTso0HNR1x8 Zx8Ty8GWq1QiIRaFf/HiXZI7m8jt+6NDSrGxZzChDRfIUUuWboXa1rOuvXiRuzc0jvsL 6VN7xjrtq23gNOOjWbffMIgg/7zjOoPIO2j12C9QnyE7ZbtiAJZhPXs0Nn2VTRCy3zj9 5PRA== X-Gm-Message-State: AJIora8SE7fkp9w1HUvTN7+Lf63bcKnkun4/A+orbxayWH3IrBebTeKw BDs/c8rKzRaHmmXdNc6Y++obyTTSFjdEDHd4E8E= X-Received: by 2002:a0d:ed83:0:b0:317:50bb:5463 with SMTP id w125-20020a0ded83000000b0031750bb5463mr4185434ywe.149.1655903990990; Wed, 22 Jun 2022 06:19:50 -0700 (PDT) MIME-Version: 1.0 References: <20220622130730.1573747-1-sbinding@opensource.cirrus.com> <20220622130730.1573747-2-sbinding@opensource.cirrus.com> In-Reply-To: <20220622130730.1573747-2-sbinding@opensource.cirrus.com> From: "Rafael J. Wysocki" Date: Wed, 22 Jun 2022 15:19:40 +0200 Message-ID: Subject: Re: [PATCH v1 1/2] ACPI: utils: Add api to read _SUB from ACPI To: Stefan Binding Cc: "Rafael J . Wysocki" , Len Brown , Mark Brown , Liam Girdwood , ACPI Devel Maling List , "moderated list:SOUND - SOC LAYER / DYNAMIC AUDIO POWER MANAGEM..." , Linux Kernel Mailing List , patches@opensource.cirrus.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 22, 2022 at 3:08 PM Stefan Binding wrote: > > Add a wrapper function to read the _SUB string from ACPI. > > Signed-off-by: Stefan Binding > --- > drivers/acpi/utils.c | 26 ++++++++++++++++++++++++++ > include/linux/acpi.h | 8 ++++++++ > 2 files changed, 34 insertions(+) > > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c > index 3a9773a09e19..5d1bdb79e372 100644 > --- a/drivers/acpi/utils.c > +++ b/drivers/acpi/utils.c > @@ -291,6 +291,32 @@ int acpi_get_local_address(acpi_handle handle, u32 *addr) > } > EXPORT_SYMBOL(acpi_get_local_address); > > +int acpi_get_sub(acpi_handle handle, char *sub, size_t size) I'd call it acpi_get_subsystem_id(). > +{ > + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; > + union acpi_object *obj; > + acpi_status status; > + int ret; > + > + status = acpi_evaluate_object(handle, METHOD_NAME__SUB, NULL, &buffer); > + if (!ACPI_SUCCESS(status)) { Typically, ACPI_FAILURE() is used in checks like this. > + acpi_handle_debug(handle, "Reading ACPI _SUB failed: %#x\n", status); It would be enough to say "_SUB evaluation failed". > + return -ENOENT; Why not use -ENODATA here? > + } > + > + obj = buffer.pointer; > + if (obj->type == ACPI_TYPE_STRING) { > + ret = strscpy(sub, obj->string.pointer, size); It may be simpler to allocate the memory here so that callers don't have to worry about it. Also, this is expected to be a proper device ID, not just a string, so maybe some validation checks could be made here? > + } else { > + acpi_handle_warn(handle, "Warning ACPI _SUB did not return a string\n"); > + ret = -EINVAL; > + } > + acpi_os_free(buffer.pointer); > + > + return ret; > +} > +EXPORT_SYMBOL_GPL(acpi_get_sub); > + > acpi_status > acpi_evaluate_reference(acpi_handle handle, > acpi_string pathname, > diff --git a/include/linux/acpi.h b/include/linux/acpi.h > index 4f82a5bc6d98..9bf18adf5920 100644 > --- a/include/linux/acpi.h > +++ b/include/linux/acpi.h > @@ -21,6 +21,8 @@ > #endif > #include > > +#define ACPI_MAX_SUB_BUF_SIZE 9 > + > #ifdef CONFIG_ACPI > > #include > @@ -762,6 +764,7 @@ static inline u64 acpi_arch_get_root_pointer(void) > #endif > > int acpi_get_local_address(acpi_handle handle, u32 *addr); > +int acpi_get_sub(acpi_handle handle, char *sub, size_t size); > > #else /* !CONFIG_ACPI */ > > @@ -1023,6 +1026,11 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) > return -ENODEV; > } > > +static int acpi_get_sub(acpi_handle handle, char *sub, size_t size) > +{ > + return -ENODEV; > +} > + > static inline int acpi_register_wakeup_handler(int wake_irq, > bool (*wakeup)(void *context), void *context) > { > --