From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Len Brown <lenb@kernel.org>,
Calvin Johnson <calvin.johnson@oss.nxp.com>
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 [thread overview]
Message-ID: <1946478.1QpZic6vku@kreacher> (raw)
In-Reply-To: <3881654.NPl3a4M0kB@kreacher>
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
> > <andriy.shevchenko@linux.intel.com> 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 <calvin.johnson@oss.nxp.com>
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > 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);
next prev parent reply other threads:[~2021-02-10 13:49 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-10 11:43 [PATCH v1 1/7] ACPI: property: Remove dead code Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 2/7] ACPI: property: Make acpi_node_prop_read() static Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 3/7] ACPI: property: Satisfy kernel doc validator (part 1) Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 4/7] ACPI: property: Satisfy kernel doc validator (part 2) Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 5/7] ACPI: property: Refactor acpi_data_prop_read_single() Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 6/7] ACPI: property: Allow to validate a single value Andy Shevchenko
2021-02-10 11:43 ` [PATCH v1 7/7] ACPI: property: Allow counting a single value as an array of 1 element Andy Shevchenko
2021-02-10 12:36 ` Rafael J. Wysocki
2021-02-10 13:31 ` Rafael J. Wysocki
2021-02-10 13:48 ` Rafael J. Wysocki [this message]
2021-02-10 14:48 ` Andy Shevchenko
2021-02-10 15:01 ` Rafael J. Wysocki
2021-02-10 15:41 ` Andy Shevchenko
2021-02-10 15:44 ` Rafael J. Wysocki
2021-02-11 15:42 ` Andy Shevchenko
2021-02-11 16:39 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1946478.1QpZic6vku@kreacher \
--to=rjw@rjwysocki.net \
--cc=andriy.shevchenko@linux.intel.com \
--cc=calvin.johnson@oss.nxp.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox