device properties: Fix return codes for __acpi_node_get_property_reference
PATCH 1/1 device properties: Fix return codes for __acpi_node_get_property_reference
Fix more return codes for device property: Align return codes of __acpi_node_get_property_reference. In particular what was missed previously:
-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number of entries in a package, now -ENOENT.
---
Hi Rafael,
Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of _acpi_node_get_property_reference") did not fully fix the issue.
drivers/acpi/property.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/acpi/property.c +15 -5
@@ -592,8 +592,16 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ; ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); -if (ret) -return ret; +switch (ret) { +case -EINVAL : +return -ENOENT ; +case -EPROTO : +return -EINVAL ; +default : +if (ret) +return ret; +break ; + }/* * The simplest case is when the value is a single reference. Just
@@ -605,7 +613,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, ret =acpi_bus_get_device (obj->reference.handle, &device);if (ret) -return ret; +return ret == -ENODEV ? -EINVAL : ret; args->adev = device; args->nargs =0 ;
@@ -621,8 +629,10 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,* The index argument is then used to determine which reference * the caller wants (along with the arguments). */ -if (obj->type !=ACPI_TYPE_PACKAGE || index >= obj->package.count) -return -EPROTO ; +if (obj->type !=ACPI_TYPE_PACKAGE ) +return -EINVAL ; +if (index >= obj->package.count) +return -ENOENT ; element = obj->package.elements; end = element + obj->package.count;
Signature · 1 line
2.11.0
Quoted 12 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>
Quoted 6 lines
---
Hi Rafael,Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.
OK, thanks for letting me know, but why didn't it?
Quoted 13 lines
drivers/acpi/property.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/acpi/property.c +0
-2@@ -592,8 +592,16 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ; ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); -if (ret) -return ret;
drivers/acpi/property.c int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 604
Quoted 10 lines
drivers/acpi/property.c +10
-0+switch (ret) { +case -EINVAL : +return -ENOENT ; +case -EPROTO : +return -EINVAL ; +default : +if (ret) +return ret; +break ; + }
To be clear, I'm not going to apply anything like the above.
Quoted 26 lines
drivers/acpi/property.c +5
-3/* * The simplest case is when the value is a single reference. Just @@ -605,7 +613,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, ret =acpi_bus_get_device (obj->reference.handle, &device);if (ret) -return ret; +return ret == -ENODEV ? -EINVAL : ret; args->adev = device; args->nargs =0 ;@@ -621,8 +629,10 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,* The index argument is then used to determine which reference * the caller wants (along with the arguments). */ -if (obj->type !=ACPI_TYPE_PACKAGE || index >= obj->package.count) -return -EPROTO ; +if (obj->type !=ACPI_TYPE_PACKAGE ) +return -EINVAL ; +if (index >= obj->package.count) +return -ENOENT ; element = obj->package.elements; end = element + obj->package.count;
Hi Rafael,
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>---
Hi Rafael,
Quoted 5 lines
Quoted 3 lines
Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.OK, thanks for letting me know, but why didn't it?
My testing appears to have been more limited than I thought, Hyungwoo later on found this out. (Reported-by: Hyungwoo... would be appropriate, I'll add that the next time.)
Quoted 11 lines
Quoted 11 lines
drivers/acpi/property.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/acpi/property.c +0
-0@@ -592,8 +592,16 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ;
Quoted 15 lines
drivers/acpi/property.c int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 604
Quoted 13 lines
drivers/acpi/property.c +10
-2ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); -if (ret) -return ret; +switch (ret) { +case -EINVAL : +return -ENOENT ; +case -EPROTO : +return -EINVAL ; +default : +if (ret) +return ret; +break ; + }To be clear, I'm not going to apply anything like the above.
On exactly what grounds? You don't like the combination of switch and if, or because of the return values themselves? Or something else?
Quoted 29 lines
Quoted 27 lines
drivers/acpi/property.c +5
-3/* * The simplest case is when the value is a single reference. Just @@ -605,7 +613,7 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, ret =acpi_bus_get_device (obj->reference.handle, &device);if (ret) -return ret; +return ret == -ENODEV ? -EINVAL : ret; args->adev = device; args->nargs =0 ;@@ -621,8 +629,10 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,* The index argument is then used to determine which reference * the caller wants (along with the arguments). */ -if (obj->type !=ACPI_TYPE_PACKAGE || index >= obj->package.count) -return -EPROTO ; +if (obj->type !=ACPI_TYPE_PACKAGE ) +return -EINVAL ; +if (index >= obj->package.count) +return -ENOENT ; element = obj->package.elements; end = element + obj->package.count;
Signature · 4 lines
Regards, Sakari Ailus [email protected]
Quoted 56 lines · CEST Sakari Ailus
Hi Rafael,
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>---
Hi Rafael,Quoted 5 lines
Quoted 3 lines
Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.OK, thanks for letting me know, but why didn't it?
My testing appears to have been more limited than I thought, Hyungwoo later on found this out. (Reported-by: Hyungwoo... would be appropriate, I'll add that the next time.)
Quoted 11 lines
Quoted 11 lines
drivers/acpi/property.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/acpi/property.c +0
-0@@ -592,8 +592,16 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ;Quoted 15 lines
drivers/acpi/property.c int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 604
Quoted 13 lines
drivers/acpi/property.c +10
-2ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); -if (ret) -return ret; +switch (ret) { +case -EINVAL : +return -ENOENT ; +case -EPROTO : +return -EINVAL ; +default : +if (ret) +return ret; +break ; + }To be clear, I'm not going to apply anything like the above.
Quoted 2 lines
On exactly what grounds? You don't like the combination of switch and if, or because of the return values themselves? Or something else?
I just don't like changing error codes into different ones on the fly like this. It always indicates some bad design somewhere and this particular piece of code just goes over the top with that IMO.
Thanks,
Rafael
Rafael J. Wysocki
maintainerQuoted 25 lines · Sakari Ailus
Hi Rafael,
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>---
Hi Rafael,Quoted 5 lines
Quoted 3 lines
Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.OK, thanks for letting me know, but why didn't it?
Quoted 3 lines
My testing appears to have been more limited than I thought, Hyungwoo later on found this out. (Reported-by: Hyungwoo... would be appropriate, I'll add that the next time.)
Well, you're not saying what exactly still doesn't work with the previous patch applied which really is what I was asking about.
Thanks,
Rafael
Hi Rafael,
Quoted 57 lines · Rafael J. Wysocki
Quoted 56 lines · CEST Sakari Ailus
Hi Rafael,
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>---
Hi Rafael,Quoted 5 lines
Quoted 3 lines
Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.OK, thanks for letting me know, but why didn't it?
My testing appears to have been more limited than I thought, Hyungwoo later on found this out. (Reported-by: Hyungwoo... would be appropriate, I'll add that the next time.)
Quoted 26 lines
Quoted 14 lines
drivers/acpi/property.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/acpi/property.c +0
-2@@ -592,8 +592,16 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ; ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); -if (ret) -return ret;drivers/acpi/property.c int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 604
Quoted 10 lines
drivers/acpi/property.c +10
-0+switch (ret) { +case -EINVAL : +return -ENOENT ; +case -EPROTO : +return -EINVAL ; +default : +if (ret) +return ret; +break ; + }To be clear, I'm not going to apply anything like the above.
Quoted 6 lines
Quoted 2 lines
On exactly what grounds? You don't like the combination of switch and if, or because of the return values themselves? Or something else?
I just don't like changing error codes into different ones on the fly like this. It always indicates some bad design somewhere and this particular piece of code just goes over the top with that IMO.
acpi_data_get_property() is used in quite a few places and the error codes it returns are more or less used as such elsewhere.
The ACPI and OF frameworks tend to use slightly different error codes to signal various error conditions. In this case, the OF archetype of fwnode_property_get_reference_args(), of_parse_phandle_with_args(), also uses different error codes than the rest of the OF framework. We decided to align the error codes with the OF framework, as has been done with the rest of the functions. Therefore the error codes returned by ACPI functions need to be converted to what is expected to be seen on the device property API (or OF API).
My original proposal was to switch between the conventions in the ACPI fwnode callback acpi_fwnode_get_reference_args() but based on the review comments I made the changes to __acpi_node_get_property_reference() instead. Which is where we're now.
fwnode_property_get_reference_args() (as does of_parse_phandle_with_args()) returns -ENOENT on
- no reference found at given index (but entry exists),
- no index exists in property or
- the property does not exist.
Originally __acpi_node_get_property_reference() used -ENOENT, -ENODATA and -EINVAL respectively. Consequenty -EINVAL returned by acpi_data_get_property(), called by __acpi_node_get_property_reference() needs to be turned to -ENOENT instead. Likewise -EPROTO changes to -EINVAL, as fwnode_property_get_reference_args() isn't expected to return -EPROTO.
Signature · 4 lines
Regards, Sakari Ailus [email protected]
Rafael J. Wysocki
maintainerQuoted 91 lines · Sakari Ailus
Hi Rafael,
Quoted 57 lines · Rafael J. Wysocki
Quoted 56 lines · CEST Sakari Ailus
Hi Rafael,
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>---
Hi Rafael,Quoted 5 lines
Quoted 3 lines
Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.OK, thanks for letting me know, but why didn't it?
My testing appears to have been more limited than I thought, Hyungwoo later on found this out. (Reported-by: Hyungwoo... would be appropriate, I'll add that the next time.)
Quoted 26 lines
Quoted 14 lines
drivers/acpi/property.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/acpi/property.c +0
-2@@ -592,8 +592,16 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ; ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); -if (ret) -return ret;drivers/acpi/property.c int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 604
Quoted 10 lines
drivers/acpi/property.c +10
-0+switch (ret) { +case -EINVAL : +return -ENOENT ; +case -EPROTO : +return -EINVAL ; +default : +if (ret) +return ret; +break ; + }To be clear, I'm not going to apply anything like the above.
Quoted 6 lines
Quoted 2 lines
On exactly what grounds? You don't like the combination of switch and if, or because of the return values themselves? Or something else?
I just don't like changing error codes into different ones on the fly like this. It always indicates some bad design somewhere and this particular piece of code just goes over the top with that IMO.
acpi_data_get_property()is used in quite a few places and the error codes it returns are more or less used as such elsewhere.The ACPI and OF frameworks tend to use slightly different error codes to signal various error conditions. In this case, the OF archetype of
fwnode_property_get_reference_args(),of_parse_phandle_with_args(), also uses different error codes than the rest of the OF framework. We decided to align the error codes with the OF framework, as has been done with the rest of the functions. Therefore the error codes returned by ACPI functions need to be converted to what is expected to be seen on the device property API (or OF API).My original proposal was to switch between the conventions in the ACPI fwnode callback
acpi_fwnode_get_reference_args()but based on the review comments I made the changes to__acpi_node_get_property_reference()instead. Which is where we're now.
fwnode_property_get_reference_args()(as doesof_parse_phandle_with_args()) returns-ENOENTon- no reference found at given index (but entry exists),
- no index exists in property or
Quoted 7 lines
- the property does not exist.
Originally
__acpi_node_get_property_reference()used-ENOENT,-ENODATAand-EINVALrespectively. Consequenty-EINVALreturned byacpi_data_get_property(), called by__acpi_node_get_property_reference()needs to be turned to-ENOENTinstead. Likewise-EPROTOchanges to-EINVAL, asfwnode_property_get_reference_args()isn't expected to return-EPROTO.
Can we just return -EINVAL (or whatever generic error) on all errors from acpi_data_get_property() and avoid this super-ugliness, please?
Or if some caller really cares, you can do
if (ret)
return ret == -EINVAL ? -ENOENT : -EINVAL;
which at least is one line of code instead of several.
Thanks,
Rafael
Hi Rafael,
Quoted 95 lines · Rafael J. Wysocki
Quoted 93 lines · Sakari Ailus
Hi Rafael,
Quoted 57 lines · Rafael J. Wysocki
Quoted 56 lines · CEST Sakari Ailus
Hi Rafael,
Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>---
Hi Rafael,Quoted 5 lines
Quoted 3 lines
Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.OK, thanks for letting me know, but why didn't it?
My testing appears to have been more limited than I thought, Hyungwoo later on found this out. (Reported-by: Hyungwoo... would be appropriate, I'll add that the next time.)
Quoted 26 lines
Quoted 14 lines
drivers/acpi/property.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)drivers/acpi/property.c +0
-2@@ -592,8 +592,16 @@ int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode,return -ENOENT ; ret =acpi_data_get_property (data, propname,ACPI_TYPE_ANY , &obj); -if (ret) -return ret;drivers/acpi/property.c int __acpi_node_get_property_reference(const struct fwnode_handle *fwnode, · line 604
Quoted 10 lines
drivers/acpi/property.c +10
-0+switch (ret) { +case -EINVAL : +return -ENOENT ; +case -EPROTO : +return -EINVAL ; +default : +if (ret) +return ret; +break ; + }To be clear, I'm not going to apply anything like the above.
Quoted 6 lines
Quoted 2 lines
On exactly what grounds? You don't like the combination of switch and if, or because of the return values themselves? Or something else?
I just don't like changing error codes into different ones on the fly like this. It always indicates some bad design somewhere and this particular piece of code just goes over the top with that IMO.
acpi_data_get_property()is used in quite a few places and the error codes it returns are more or less used as such elsewhere.The ACPI and OF frameworks tend to use slightly different error codes to signal various error conditions. In this case, the OF archetype of
fwnode_property_get_reference_args(),of_parse_phandle_with_args(), also uses different error codes than the rest of the OF framework. We decided to align the error codes with the OF framework, as has been done with the rest of the functions. Therefore the error codes returned by ACPI functions need to be converted to what is expected to be seen on the device property API (or OF API).My original proposal was to switch between the conventions in the ACPI fwnode callback
acpi_fwnode_get_reference_args()but based on the review comments I made the changes to__acpi_node_get_property_reference()instead. Which is where we're now.
fwnode_property_get_reference_args()(as doesof_parse_phandle_with_args()) returns-ENOENTon- no reference found at given index (but entry exists),
- no index exists in property or
- the property does not exist.
Quoted 8 lines
Quoted 5 lines
Originally
__acpi_node_get_property_reference()used-ENOENT,-ENODATAand-EINVALrespectively. Consequenty-EINVALreturned byacpi_data_get_property(), called by__acpi_node_get_property_reference()needs to be turned to-ENOENTinstead. Likewise-EPROTOchanges to-EINVAL, asfwnode_property_get_reference_args()isn't expected to return-EPROTO.Can we just return
-EINVAL(or whatever generic error) on all errors fromacpi_data_get_property()and avoid this super-ugliness, please?
acpi_data_get_property() is used by a number of functions and those functions have well defined error codes for various conditions. In particular, these conditions are more finely separated for use in other fwnode_property_read_*() functions than they are for fwnode_property_get_reference_args(). So we can't change what acpi_data_get_property() returns without breaking the rest.
If you want it to be clean, then the best option to implement it is in the fwnode property framework which uses OF-like error codes, not ACPI-like.
Quoted 7 lines
Or if some caller really cares, you can do
if (ret)
return ret == -EINVAL ? -ENOENT : -EINVAL;which at least is one line of code instead of several.
Ah, acpi_data_get_property() only returns the two. Yes, I can change the implementation to that. I'll submit v2.
Signature · 4 lines
Kind regards, Sakari Ailus [email protected]
Quoted 27 lines · Rafael J. Wysocki
Quoted 25 lines · Sakari Ailus
Hi Rafael,
Quoted 21 lines · Rafael J. Wysocki
Quoted 12 lines · CEST Sakari Ailus
Fix more return codes for device property: Align return codes of
__acpi_node_get_property_reference. In particular what was missed previously:(quoted diff) +0
-3-EPROTO could be returned in certain cases, now -EINVAL; -EINVAL was returned if the property was not found, now -ENOENT; -EINVAL was returned also if the index was higher than the number ofentries in a package, now
-ENOENT.Fixes ("device property: Align return codes of __acpi_node_get_property_reference")Signed-off-by Sakari Ailus <[email protected]>Tested-by Hyungwoo Yang <[email protected]>Quoted 6 lines
---
Hi Rafael,Unfortunately the patch I posted the previous time to remedy the issue ("device property: Align return codes of
_acpi_node_get_property_reference") did not fully fix the issue.OK, thanks for letting me know, but why didn't it?
Quoted 6 lines
Quoted 3 lines
My testing appears to have been more limited than I thought, Hyungwoo later on found this out. (Reported-by: Hyungwoo... would be appropriate, I'll add that the next time.)
Well, you're not saying what exactly still doesn't work with the previous patch applied which really is what I was asking about.
Hmm. The subject says it but I'll add it to the commit message as well.
Signature · 2 lines
Sakari Ailus [email protected]