Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp453302pxb; Wed, 3 Mar 2021 07:20:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHlfeYVmGTbctTPN5ro7B7zP7NIAkd5ccrQ9L3fpw8PqXLSgpoOA9gy+yWneWKn1/lEXxX X-Received: by 2002:a17:906:f01:: with SMTP id z1mr27224940eji.235.1614784851949; Wed, 03 Mar 2021 07:20:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614784851; cv=none; d=google.com; s=arc-20160816; b=v3/oF2OsqXqTxxgquLiS2sU6zx7eFnezJS7ifTDIg0ZsSRWCgbfDhyQYpFzHYa38EZ 0+yoDuNa/GxSmAHefkB+WaZWMvF6jvXx/La58E/IFcTlXACQsVJ3xuHeAfy5Y9D4BlGr vP0ZpM6ZGygegqxTAfB1FKo+crO6+831Js5y3gwu4sRw9sIuSHDTil5YeolkKE6vSWGs nY1YVVnZWtlLSWrW/TBxbzgnf9vWCS4g6QF+cYkZeHNVcG3kf2qsIzIyDd2jaMZwkv6o fKShroIbkHTBTw6Nk6zjWS1Ko8fNgjAwH1yVfbC2aQPesa/BqMaxpHnW7U1V2R0f+2Vg U/cQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Wc33xVnqumowd/4QWaeC6cYVC2ZicKny2nLHMQr1WBA=; b=GfzNilTigPMuU7B0cTsM8cggQPJKvnQBCUqibQtYPoEdLelf69I/jw8KzYPhmShgR3 b1PRQLs99L91v5gNhcauCYUqdE2/+DMV7JsX8YB9OVBOtl8aDJy8p9D+ItpxDLPbNVI1 iMsU98dSfcFc5JISQsR45FZMI2Zldy6T/6tO/2i4XwyBhyRMTh6Ch6h+CSJk4NYfwTEQ /yOs0PPtBYauznf6Am8bRQooZ7YuohXUF7bqmP5zkjuAwzgpUxq7UmHixp6V/0ycOaV9 nrtJf/HsvR0iAwVxe8XUO5IDylG6ytBzWm6dsyZPOX7iGlfiYYjQtfVJ/FjiYIajNZ2r 3jYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KD4tXAkH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bg8si15404051ejb.188.2021.03.03.07.19.58; Wed, 03 Mar 2021 07:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KD4tXAkH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343737AbhCAWhg (ORCPT + 99 others); Mon, 1 Mar 2021 17:37:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:33832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238937AbhCARn5 (ORCPT ); Mon, 1 Mar 2021 12:43:57 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2A92C650D3; Mon, 1 Mar 2021 16:58:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617898; bh=FTaQVIumihL/faDEce6NNWhpcs0q93R8S1P12fmHzio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KD4tXAkHCEdDb51n1dTb8jKmsiURx5i7Se49sx7/8IWAdmn9QQOKTugJiyaI6kAHN CxpTgCyfVMlOn5r4YQX19vGsRYvLHpiTrowZAz+HmaKI6QYl8CUOJYcjrPe3XKlCol M2PauVzTe5U+DFXUhKp6Wg74cEDZoS0RQkKi29jI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Calvin Johnson , "Rafael J. Wysocki" , Sakari Ailus , Mika Westerberg , Andy Shevchenko Subject: [PATCH 5.4 236/340] ACPI: property: Fix fwnode string properties matching Date: Mon, 1 Mar 2021 17:13:00 +0100 Message-Id: <20210301161059.908567444@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161048.294656001@linuxfoundation.org> References: <20210301161048.294656001@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki commit e1e6bd2995ac0e1ad0c2a2d906a06f59ce2ed293 upstream. Property matching does not work for ACPI fwnodes if the value of the given property is not represented as a package in the _DSD package containing it. For example, the "compatible" property in the _DSD below Name (_DSD, Package () { ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), Package () { Package () {"compatible", "ethernet-phy-ieee802.3-c45"} } }) will not be found by fwnode_property_match_string(), because the ACPI code handling device properties does not regard the single value as a "list" in that case. Namely, fwnode_property_match_string() invoked to match a given string property value first calls fwnode_property_read_string_array() with the last two arguments equal to NULL and 0, respectively, in order to count the items in the value of the given property, with the assumption that this value may be an array. For ACPI fwnodes, that operation is carried out by acpi_node_prop_read() which calls acpi_data_prop_read() for this purpose. However, when the return (val) pointer is NULL, that function only looks for a property whose value is a package without checking the single-value case at all. To fix that, make acpi_data_prop_read() check the single-value case if its return pointer argument is NULL and modify acpi_data_prop_read_single() handling that case to attempt to read the value of the property if the return pointer is NULL and return 1 if that succeeds. Fixes: 3708184afc77 ("device property: Move FW type specific functionality to FW specific files") Reported-by: Calvin Johnson Cc: 4.13+ # 4.13+ Signed-off-by: Rafael J. Wysocki Reviewed-by: Sakari Ailus Reviewed-by: Mika Westerberg Reviewed-by: Andy Shevchenko Signed-off-by: Greg Kroah-Hartman --- drivers/acpi/property.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) --- a/drivers/acpi/property.c +++ b/drivers/acpi/property.c @@ -794,9 +794,6 @@ static int acpi_data_prop_read_single(co const union acpi_object *obj; int ret; - if (!val) - return -EINVAL; - if (proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64) { ret = acpi_data_get_property(data, propname, ACPI_TYPE_INTEGER, &obj); if (ret) @@ -806,28 +803,43 @@ static int acpi_data_prop_read_single(co case DEV_PROP_U8: if (obj->integer.value > U8_MAX) return -EOVERFLOW; - *(u8 *)val = obj->integer.value; + + if (val) + *(u8 *)val = obj->integer.value; + break; case DEV_PROP_U16: if (obj->integer.value > U16_MAX) return -EOVERFLOW; - *(u16 *)val = obj->integer.value; + + if (val) + *(u16 *)val = obj->integer.value; + break; case DEV_PROP_U32: if (obj->integer.value > U32_MAX) return -EOVERFLOW; - *(u32 *)val = obj->integer.value; + + if (val) + *(u32 *)val = obj->integer.value; + break; default: - *(u64 *)val = obj->integer.value; + if (val) + *(u64 *)val = obj->integer.value; + break; } + + if (!val) + return 1; } else if (proptype == DEV_PROP_STRING) { ret = acpi_data_get_property(data, propname, ACPI_TYPE_STRING, &obj); if (ret) return ret; - *(char **)val = obj->string.pointer; + if (val) + *(char **)val = obj->string.pointer; return 1; } else { @@ -841,7 +853,7 @@ int acpi_dev_prop_read_single(struct acp { int ret; - if (!adev) + if (!adev || !val) return -EINVAL; ret = acpi_data_prop_read_single(&adev->data, propname, proptype, val); @@ -935,10 +947,20 @@ static int acpi_data_prop_read(const str const union acpi_object *items; int ret; - if (val && nval == 1) { + if (nval == 1 || !val) { ret = acpi_data_prop_read_single(data, propname, proptype, val); - if (ret >= 0) + /* + * The overflow error means that the property is there and it is + * single-value, but its type does not match, so return. + */ + if (ret >= 0 || ret == -EOVERFLOW) return ret; + + /* + * Reading this property as a single-value one failed, but its + * value may still be represented as one-element array, so + * continue. + */ } ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);