Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2835297pxb; Fri, 12 Feb 2021 02:35:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJy6st6KNurv+MkKI98ztDlq6G8JOmmZJ5Ga4KM4mfchUMHA40JpUZ1CAjwI2k9i+CP30Lw/ X-Received: by 2002:a17:906:d18e:: with SMTP id c14mr2391194ejz.302.1613126117850; Fri, 12 Feb 2021 02:35:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613126117; cv=none; d=google.com; s=arc-20160816; b=MQVE9LYf2WOpOdidzedjRL4RAlx073Dg9aR61zWT1pJ5OCllVXrgNgRCGFzqole5Fm aBj18Mh2ursIOnjs/JEsciGWfRrvv/73oPxnPSxNc1YJ+KxZcrb70aTkw+wSgch4094C 0WPdGgRgSRdgptmW8dB0Qqz9T3c7+GOx9bLr//X78xyelUezdO5m41RDG1UuZng6R4gE FuSPV+jf9xIxa6yrLUk1KkBAxvRUfKI/1Xgz4f757OcY1yNXnhA0Ei9tSbWbYsMCGN2I 44tOemN0SQPAodDTdJIXdkyaxr1cIu8xG6hG8mzprRxRBL+kqYRVYrWq3bgV4BZgckUz otEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=o9dAUOBZjmdb6T0VH5l94nMITgbmdt7nNoxMyC8kV5I=; b=ZFcCm2kDLcqvbIO6oPbP3ymKOsBqD1ZMLLkJc+bG5jczQWvY4rplLEPGYFF1aSgOYM S6XXplmAiLzI8iPn+EMR7PqGrOGAGzj0BGlR/aVYdIKf0QmBKcA1jWczqvIfF85LVYKv MbLB8z2igjgtM9lbIECc5FW6lLVD8a761NRm+45o7TUuBQ26UyLJCZAQaT2dpv835V6g sP7mN6dja/KkH4zZ6WZQDa34ruidr9XTUqZre4ydgFWvIb5Hs6zxg9i12ATe4uGPxNra x6tVykxMBLgqrXJ0s9dDqBzA34+UmXdG6OPK57pLcwdWjr8HvOgwMKEG+QI1IvPgsKhq BuIA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b20si5704936edw.412.2021.02.12.02.34.51; Fri, 12 Feb 2021 02:35:17 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230264AbhBLKeL (ORCPT + 99 others); Fri, 12 Feb 2021 05:34:11 -0500 Received: from mga12.intel.com ([192.55.52.136]:16940 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbhBLKeH (ORCPT ); Fri, 12 Feb 2021 05:34:07 -0500 IronPort-SDR: xoXangnJxijt8I7Ce0KeEYR8eIEzTQVBG9106/qWYgiNo1sk7SmM1Ux/yp92nEX+RDLTE7LGKY PxeZLspnzlVQ== X-IronPort-AV: E=McAfee;i="6000,8403,9892"; a="161536065" X-IronPort-AV: E=Sophos;i="5.81,173,1610438400"; d="scan'208";a="161536065" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2021 02:32:14 -0800 IronPort-SDR: ewelfyhW1zzOTth4TCnY+JHw59DhCjb1xEffkvMCuOvqUF4S+UU523beNBTBomQS3FWZ50Imiy rE89pDatRUaQ== X-IronPort-AV: E=Sophos;i="5.81,173,1610438400"; d="scan'208";a="376305422" Received: from smile.fi.intel.com (HELO smile) ([10.237.68.40]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2021 02:32:12 -0800 Received: from andy by smile with local (Exim 4.94) (envelope-from ) id 1lAVk9-004SQ5-Nj; Fri, 12 Feb 2021 12:32:09 +0200 Date: Fri, 12 Feb 2021 12:32:09 +0200 From: Andy Shevchenko To: "Rafael J. Wysocki" Cc: Linux ACPI , Mika Westerberg , LKML , Calvin Johnson , Sakari Ailus Subject: Re: [PATCH] ACPI: property: Fix fwnode string properties matching Message-ID: References: <5831274.1ZjA0VymzF@kreacher> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5831274.1ZjA0VymzF@kreacher> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 11, 2021 at 07:30:01PM +0100, Rafael J. Wysocki wrote: > From: Rafael J. Wysocki > > 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 > regardless of the return pointer value 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. Thanks, fine with me. Reviewed-by: Andy Shevchenko I'll rebase the rest I have on to of this. > 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 > --- > drivers/acpi/property.c | 44 +++++++++++++++++++++++++++++++++----------- > 1 file changed, 33 insertions(+), 11 deletions(-) > > Index: linux-pm/drivers/acpi/property.c > =================================================================== > --- linux-pm.orig/drivers/acpi/property.c > +++ linux-pm/drivers/acpi/property.c > @@ -787,9 +787,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) > @@ -799,28 +796,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 { > @@ -834,7 +846,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); > @@ -928,10 +940,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); > > > -- With Best Regards, Andy Shevchenko