device property: post merge fixes
Subsystems (4)
Andy Shevchenko
reviewerv3 cover device property: post merge fixes
Three fixes to device property API.
Patch 1 is a simple style fix to be folded into previous Andrew's patch to allow old gcc to build (see commit message for the details).
There is a crash in linux-next
BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 IP: [<ffffffff8145e8a6>] fwnode_property_present+0x16/0x30
Check for fwnode pointer before dereference (patch 2).
Patch 3 prevents to allocate buffers with 0 length (the result maybe surprising to someone).
Changelog v3:
- fix typo in Heikki's patch (patch 2)
- update commit message for patch 1 to explain what is the fixup for
Changelog v2:
- added patches 2 and 3
Andy Shevchenko (2):
device property: add spaces to PROPERTY_ENTRY_STRING macro device property: avoid allocations of 0 length
Heikki Krogerus (1):
device property: the secondary fwnode needs to depend on the primary
drivers/base/property.c | 14 ++++++++++---- include/linux/property.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
2.6.4
Andy Shevchenko
reviewerPATCH v3 1/3 device property: add spaces to PROPERTY_ENTRY_STRING macro
Just a style fix, no functional changes.
To be folded to Andrew's patch [1].
[1] http://comments.gmane.org/gmane.linux.kernel.commits.mm/97592
Or in linux next:
e39ece7 include-linux-propertyh-fix-build-issues-with-gcc-444-fix 40bb8a1 include/linux/property.h: fix build issues with gcc-4.4.4
--- include/linux/property.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/property.h +1 -1
@@ -230,7 +230,7 @@ struct property_entry { .name = _name_, \ .length = sizeof(_val_), \ .is_string = true, \ - { .value = {.str = _val_} }, \ + { .value = { .str = _val_ } }, \ }#define PROPERTY_ENTRY_BOOL (_name_) \
Signature · 1 line
2.6.4
Andy Shevchenko
reviewerPATCH v3 2/3 device property: the secondary fwnode needs to depend on the primary
In reply to Andy ShevchenkoFrom: Heikki Krogerus <[email protected]>
This fixes NULL pointer dereference when the primary fwnode handle does not exist, for example with PCI devices that do not have ACPI companion.
--- drivers/base/property.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/base/property.c +4 -4
@@ -218,7 +218,7 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname)bool ret; ret =__fwnode_property_present (fwnode, propname); -if (ret == false && fwnode->secondary) +if (ret == false && fwnode && fwnode->secondary) ret =__fwnode_property_present (fwnode->secondary, propname);return ret; }
@@ -423,7 +423,7 @@ EXPORT_SYMBOL_GPL(device_property_match_string);int _ret_; \ _ret_ =FWNODE_PROP_READ (_fwnode_, _propname_, _type_, _proptype_, \ _val_, _nval_); \ -if (_ret_ == -EINVAL && _fwnode_->secondary) \ +if (_ret_ == -EINVAL && _fwnode_ && _fwnode_->secondary) \ _ret_ =FWNODE_PROP_READ (_fwnode_->secondary, _propname_, _type_, \ _proptype_, _val_, _nval_); \ _ret_; \
@@ -593,7 +593,7 @@ int fwnode_property_read_string_array(struct fwnode_handle *fwnode,int ret; ret =__fwnode_property_read_string_array (fwnode, propname, val, nval); -if (ret == -EINVAL && fwnode->secondary) +if (ret == -EINVAL && fwnode && fwnode->secondary) ret =__fwnode_property_read_string_array (fwnode->secondary, propname, val, nval);return ret;
@@ -621,7 +621,7 @@ int fwnode_property_read_string(struct fwnode_handle *fwnode,int ret; ret =__fwnode_property_read_string (fwnode, propname, val); -if (ret == -EINVAL && fwnode->secondary) +if (ret == -EINVAL && fwnode && fwnode->secondary) ret =__fwnode_property_read_string (fwnode->secondary, propname, val);return ret;
Signature · 1 line
2.6.4
Andy Shevchenko
reviewerPATCH v3 3/3 device property: avoid allocations of 0 length
In reply to Andy ShevchenkoArrays can not have zero elements by definition of the unified device properties. If such property comes from outside we should not allow it to pass. Otherwise memory allocation on 0 length will return non-NULL value, which we currently don't check.
Prevent memory allocations of 0 length.
--- drivers/base/property.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/base/property.c +6 -0
@@ -653,6 +653,9 @@ int fwnode_property_match_string(struct fwnode_handle *fwnode,if (nval <0 )return nval; +if (nval ==0 ) +return -ENODATA ; + values =kcalloc (nval,sizeof (*values),GFP_KERNEL );if (!values)return -ENOMEM ;
@@ -718,6 +721,9 @@ static int pset_copy_entry(struct property_entry *dst,return -ENOMEM ;if (src->is_array) { +if (!src->length) +return -ENODATA ; +if (src->is_string) { nval = src->length /sizeof (const char *); dst->pointer.str = kcalloc(nval, sizeof(const char *),
Signature · 1 line
2.6.4