Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1317594pxb; Wed, 10 Feb 2021 05:51:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJzEN6lyDOL3k9kXZ0dA+zYwFzGeKJPjcPseTOpFrOM1MgEYsUNAIeudftQG5n/MBbk0J94T X-Received: by 2002:a05:6402:151:: with SMTP id s17mr3093730edu.107.1612965097082; Wed, 10 Feb 2021 05:51:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612965097; cv=none; d=google.com; s=arc-20160816; b=A6aWRA/cgDhZfAp6WxJ7gJxFZT/1mY+JK+6mZf6kPExIHWsWl6EJsGJLiRx6QgZt+r FVH3CvPErV3soAKm7AKfH0pGHzLZAKodeWVlzClNTmduvrl7bgu5i1EhmdAagLILFtdM RPjDzcVA04fe/KV9OMfxo1ocgA8B9HgAfWdloubo2hT7qyX4ZHKnorQuMby4KAiNiASL WxeF1t9nhwkaE+tGm6muIeCMpuYaiIyKisagGt57NR2mW89vP0XqV88y5lkGHZYHLXY+ Rl341qmP8LDEsVq8i7I3sSwTwipz0y8Eusp5txEFT8L1zWrqs8CZCn3sWhWNau72sO5y nhCg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qc8qL9esgIJxHsZRBBv9moj3uqw4YvHmR+ZemkpnRHs=; b=B6Gg0X3WE3E9vRAz4NaSQKNCg2lEGPDr5Z3ZNp38/JayGSbuzZQ0UVRtUERMJCIrao dE3x2AsTvj3LBWZyvLDYtraKrqnKFKfbjIRkcaZpKF5TZMsODFS5zXKnxbddLtWJh/qb T7lAwFHDn2olL4wf/iZSM3Pbxr2tbw8UDHQLAxQGMWZCf1K6pHk9OuV/lR+vtyhRPHTK 6X5X42Tv28WryqWf6QQ3xv6DDhJQJ+UPYSCTWLNbBm3mx2HJAFUTuWpXV5hBx8eiuVVg ahsL+ljFydGQ3FvrX0KdeEsdVz/3EIg0ROLbAh/8PwjBKpHiqYmpHFGHi6Y41GMM0O9a Dwtg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h5si1263348ejg.296.2021.02.10.05.51.12; Wed, 10 Feb 2021 05:51:37 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230192AbhBJNs4 (ORCPT + 99 others); Wed, 10 Feb 2021 08:48:56 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:45646 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbhBJNsz (ORCPT ); Wed, 10 Feb 2021 08:48:55 -0500 Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_smtp) via UNIX with SMTP (IdeaSmtpServer 0.83.537) id e014fdd4acc97cd0; Wed, 10 Feb 2021 14:48:11 +0100 Received: from kreacher.localnet (89-64-80-225.dynamic.chello.pl [89.64.80.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 9CB136608F8; Wed, 10 Feb 2021 14:48:10 +0100 (CET) From: "Rafael J. Wysocki" To: Andy Shevchenko Cc: "Rafael J. Wysocki" , ACPI Devel Maling List , Linux Kernel Mailing List , Len Brown , Calvin Johnson Subject: Re: [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element Date: Wed, 10 Feb 2021 14:48:09 +0100 Message-ID: <1946478.1QpZic6vku@kreacher> In-Reply-To: <3881654.NPl3a4M0kB@kreacher> References: <20210210114320.3478-1-andriy.shevchenko@linux.intel.com> <3881654.NPl3a4M0kB@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrtddtgddtudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttddvnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepgfelheffhfetffelhfelteejffetteetgfetkeejvdfhfeeftdeufeevgeevieevnecukfhppeekledrieegrdektddrvddvheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekledrieegrdektddrvddvhedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvghnsgeskhgvrhhnvghl rdhorhhgpdhrtghpthhtoheptggrlhhvihhnrdhjohhhnhhsohhnsehoshhsrdhngihprdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, February 10, 2021 2:31:48 PM CET Rafael J. Wysocki wrote: > On Wednesday, February 10, 2021 1:36:00 PM CET Rafael J. Wysocki wrote: > > On Wed, Feb 10, 2021 at 12:51 PM Andy Shevchenko > > wrote: > > > > > > We allow to read the single value as a first element in the array. > > > Unfortunately the counting doesn't work in this case and we can't > > > call fwnode_property_count_*() API without getting an error. > > > > It would be good to mention what the symptom of the issue is here. > > > > > Modify acpi_data_prop_read() to always try the single value read > > > and thus allow counting the single value as an array of 1 element. > > > > > > Reported-by: Calvin Johnson > > > Signed-off-by: Andy Shevchenko > > > > This is a bug fix, so it should go in before the cleanups in this series IMO. > > > > Also it looks like stable@vger material. > > > > > --- > > > drivers/acpi/property.c | 6 ++++-- > > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > > > diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c > > > index 236316ee0e25..d6100585fceb 100644 > > > --- a/drivers/acpi/property.c > > > +++ b/drivers/acpi/property.c > > > @@ -913,12 +913,14 @@ static int acpi_data_prop_read(const struct acpi_device_data *data, > > > const union acpi_object *items; > > > int ret; > > > > > > - if (val && nval == 1) { > > > + /* Try to read as a single value first */ > > > + if (!val || nval == 1) { > > > ret = acpi_data_prop_read_single(data, propname, proptype, val); > > > > This returns -EINVAL if val is NULL. > > > > > if (ret >= 0) > > > - return ret; > > > + return val ? ret : 1; > > > > So val cannot be NULL here. > > > > > } > > > > > > + /* It's not the single value, get an array instead */ > > > ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj); > > > if (ret) > > > return ret; > > > -- > > > > To me, acpi_fwnode_property_read_string_array() needs to special-case > > val == NULL and nval == 0. > > Well, scratch this. > > Something like the patch below (untested) should be sufficient to address this > if I'm not mistaken. Well, I am mistaken -> > > --- > drivers/acpi/property.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) > > Index: linux-pm/drivers/acpi/property.c > =================================================================== > --- linux-pm.orig/drivers/acpi/property.c > +++ linux-pm/drivers/acpi/property.c > @@ -787,14 +787,14 @@ 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) > return ret; > > + if (!val) > + return 1; > + > switch (proptype) { > case DEV_PROP_U8: > if (obj->integer.value > U8_MAX) > @@ -820,7 +820,8 @@ static int acpi_data_prop_read_single(co > if (ret) > return ret; > > - *(char **)val = obj->string.pointer; > + if (val) > + *(char **)val = obj->string.pointer; > > return 1; > } else { > @@ -928,10 +929,16 @@ static int acpi_data_prop_read(const str > const union acpi_object *items; > int ret; > > - if (val && nval == 1) { > + if (nval == 1) { -> because this would miss the nval == 0 case. So appended again with this fixed. --- drivers/acpi/property.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) Index: linux-pm/drivers/acpi/property.c =================================================================== --- linux-pm.orig/drivers/acpi/property.c +++ linux-pm/drivers/acpi/property.c @@ -787,14 +787,14 @@ 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) return ret; + if (!val) + return 1; + switch (proptype) { case DEV_PROP_U8: if (obj->integer.value > U8_MAX) @@ -820,7 +820,8 @@ static int acpi_data_prop_read_single(co if (ret) return ret; - *(char **)val = obj->string.pointer; + if (val) + *(char **)val = obj->string.pointer; return 1; } else { @@ -928,10 +929,16 @@ static int acpi_data_prop_read(const str const union acpi_object *items; int ret; - if (val && nval == 1) { + if (nval <= 1) { ret = acpi_data_prop_read_single(data, propname, proptype, val); if (ret >= 0) 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);