Skip to contentSkip to conversation

device property: post merge fixes

PATCH Superseded Andy Shevchenko 5 participants 15 messages Dec 23, 2015 – Jan 1, 2016

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Andy Shevchenko

author reviewer
#0 lore raw

v2 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.

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).

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
author reviewer
#1 lore raw

PATCH v2 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.

---
 include/linux/property.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/property.h +1 -1
index b8c4e42..b51fcd3 100644
@@ -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
#2 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

Quoted 3 lines · Andy Shevchenko

Just a style fix, no functional changes.

To be folded to Andrew's patch.

What patch?

Quoted 11 lines
---
 include/linux/property.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/property.h +0 -0
index b8c4e42..b51fcd3 100644

include/linux/property.h struct property_entry { · line 236

Quoted 8 lines
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_)		\

Thanks,
Rafael

author reviewer
#3 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko

Just a style fix, no functional changes.

To be folded to Andrew's patch.

What patch?

In linux-next from Andrew:

e39ece7 include-linux-propertyh-fix-build-issues-with-gcc-444-fix 40bb8a1 include/linux/property.h: fix build issues with gcc-4.4.4

Quoted 24 lines
Quoted 17 lines

---
 include/linux/property.h | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/property.h +1 -1
index b8c4e42..b51fcd3 100644
@@ -230,7 +230,7 @@ struct property_entry {
  	.name = _name_,					\
  	.length = sizeof(_val_),			\
  	.is_string = true,				\
-	{ .value = {.str = _val_} },			\
+	{ .value = { .str = _val_ } },			\
  }
Quoted 3 lines


 #define PROPERTY_ENTRY_BOOL(_name_) \

Thanks,
Rafael

Signature · 7 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#4 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Rafael J. Wysocki
Quoted 2 lines · Andy Shevchenko

Just a style fix, no functional changes.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

To be folded to Andrew's patch.

What patch?

In linux-next from Andrew:

e39ece7 include-linux-propertyh-fix-build-issues-with-gcc-444-fix 40bb8a1 include/linux/property.h: fix build issues with gcc-4.4.4

Any pointers to the original patch submission(s)?

Thanks,
Rafael

#5 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

Quoted 7 lines · On Wed, 30 Dec 2015 02:49:26 +0100 "Rafael J. Wysocki" <[email protected]>…
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko

Just a style fix, no functional changes.

To be folded to Andrew's patch.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

What patch?

In linux-next from Andrew:

e39ece7 include-linux-propertyh-fix-build-issues-with-gcc-444-fix 40bb8a1 include/linux/property.h: fix build issues with gcc-4.4.4

Any pointers to the original patch submission(s)?

I think it was discussed in some followup to something else, I forget.

This:

From: Andrew Morton <[email protected]>
Subject: include/linux/property.h: fix build issues with gcc-4.4.4

gcc-4.4.4 has problems with initialization of anonymous unions:

drivers/mfd/intel-lpss-acpi.c:30: error: unknown field 'value' specified in initializer

work around this by crafting the initializers in a manner which the compiler can handle.

Cc Kevin Fenzi <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Heikki Krogerus <[email protected]>

---

 include/linux/property.h |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
include/linux/property.h renamed from include/linux/property.h~include-linux-propertyh-fix-build-issues-with-gcc-444 +12 -4
diff -puN include/linux/property.h~include-linux-propertyh-fix-build-issues-with-gcc-444 include/linux/property.h
@@ -175,12 +175,19 @@ struct property_entry {
 	};
 };
 
+/*
+ * Note: the below four initializers for the anonymous union are carefully
+ * crafted to avoid gcc-4.4.4's problems with initialization of anon unions
+ * and structs.
+ */
+
 #define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _val_)	\
 {								\
 	.name = _name_,						\
 	.length = ARRAY_SIZE(_val_) * sizeof(_type_),		\
 	.is_array = true,					\
-	.pointer._type_##_data = _val_,				\
+	.is_string = false,					\
+	{ .pointer = _type_##_data = _val_ } },			\
 }
 
 #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_)			\
@@ -198,14 +205,15 @@ struct property_entry {
 	.length = ARRAY_SIZE(_val_) * sizeof(const char *),	\
 	.is_array = true,					\
 	.is_string = true,					\
-	.pointer.str = _val_,					\
+	{ .pointer = { .str = _val_ } },			\
 }
 
 #define PROPERTY_ENTRY_INTEGER(_name_, _type_, _val_)	\
 {							\
 	.name = _name_,					\
 	.length = sizeof(_type_),			\
-	.value._type_##_data = _val_,			\
+	.is_string = false,				\
+	{ .value = { ._type_##_data = _val_ } },	\
 }
 
 #define PROPERTY_ENTRY_U8(_name_, _val_)		\
@@ -222,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_)		\

_

#6 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

Quoted 16 lines · Andrew Morton
Quoted 14 lines · On Wed, 30 Dec 2015 02:49:26 +0100 "Rafael J. Wysocki" <[email protected]>…
Quoted 12 lines · Andy Shevchenko
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko

Just a style fix, no functional changes.

To be folded to Andrew's patch.

What patch?

In linux-next from Andrew:

e39ece7 include-linux-propertyh-fix-build-issues-with-gcc-444-fix 40bb8a1 include/linux/property.h: fix build issues with gcc-4.4.4

Quoted 8 lines
Quoted 1 line

Any pointers to the original patch submission(s)?

I think it was discussed in some followup to something else, I forget.

This:

From: Andrew Morton <[email protected]>
Subject: include/linux/property.h: fix build issues with gcc-4.4.4

OK, thanks!

I'll apply it to my tree if you don't mind with the Andy's [1/3] on top so we have all of that in one place.

Thanks,
Rafael

#7 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Andrew Morton
Quoted 7 lines · On Wed, 30 Dec 2015 02:49:26 +0100 "Rafael J. Wysocki" <[email protected]>…
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko

Just a style fix, no functional changes.

To be folded to Andrew's patch.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

What patch?

In linux-next from Andrew:

e39ece7 include-linux-propertyh-fix-build-issues-with-gcc-444-fix 40bb8a1 include/linux/property.h: fix build issues with gcc-4.4.4

Any pointers to the original patch submission(s)?

I think it was discussed in some followup to something else, I forget.

This:

Quoted 7 lines
Quoted 2 lines

From: Andrew Morton <[email protected]>
Subject: include/linux/property.h: fix build issues with gcc-4.4.4

OK, thanks!

I'll apply it to my tree if you don't mind with the Andy's [1/3] on top so we have all of that in one place.

Be aware that there are actually _two_ patches from Andrew and _one_ from me to be all folded together.
I think there is no need to have 3 of them.

Quoted 9 lines

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

In reply to Rafael J. Wysocki
Quoted 2 lines · On Wed, 30 Dec 2015 03:06:23 +0100 "Rafael J. Wysocki" <[email protected]>…

I'll apply it to my tree if you don't mind with the Andy's [1/3] on top so we have all of that in one place.

That version needed a fix. Here's the one to apply:

From: Andrew Morton <[email protected]>
Subject: include/linux/property.h: fix build issues with gcc-4.4.4

gcc-4.4.4 has problems with initialization of anonymous unions:

drivers/mfd/intel-lpss-acpi.c:30: error: unknown field 'value' specified in initializer

work around this by crafting the initializers in a manner which the compiler can handle.

Cc Kevin Fenzi <[email protected]>
Cc Mika Westerberg <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Rafael J. Wysocki <[email protected]>
Cc Heikki Krogerus <[email protected]>

---

 include/linux/property.h |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
include/linux/property.h renamed from include/linux/property.h~include-linux-propertyh-fix-build-issues-with-gcc-444 +12 -4
diff -puN include/linux/property.h~include-linux-propertyh-fix-build-issues-with-gcc-444 include/linux/property.h
@@ -175,12 +175,19 @@ struct property_entry {
 	};
 };
 
+/*
+ * Note: the below four initializers for the anonymous union are carefully
+ * crafted to avoid gcc-4.4.4's problems with initialization of anon unions
+ * and structs.
+ */
+
 #define PROPERTY_ENTRY_INTEGER_ARRAY(_name_, _type_, _val_)	\
 {								\
 	.name = _name_,						\
 	.length = ARRAY_SIZE(_val_) * sizeof(_type_),		\
 	.is_array = true,					\
-	.pointer._type_##_data = _val_,				\
+	.is_string = false,					\
+	{ .pointer = { _type_##_data = _val_ } },		\
 }
 
 #define PROPERTY_ENTRY_U8_ARRAY(_name_, _val_)			\
@@ -198,14 +205,15 @@ struct property_entry {
 	.length = ARRAY_SIZE(_val_) * sizeof(const char *),	\
 	.is_array = true,					\
 	.is_string = true,					\
-	.pointer.str = _val_,					\
+	{ .pointer = { .str = _val_ } },			\
 }
 
 #define PROPERTY_ENTRY_INTEGER(_name_, _type_, _val_)	\
 {							\
 	.name = _name_,					\
 	.length = sizeof(_type_),			\
-	.value._type_##_data = _val_,			\
+	.is_string = false,				\
+	{ .value = { ._type_##_data = _val_ } },	\
 }
 
 #define PROPERTY_ENTRY_U8(_name_, _val_)		\
@@ -222,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_)		\

_

#9 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

Quoted 6 lines · Andrew Morton
Quoted 2 lines · On Wed, 30 Dec 2015 03:06:23 +0100 "Rafael J. Wysocki" <[email protected]>…

I'll apply it to my tree if you don't mind with the Andy's [1/3] on top so we have all of that in one place.

That version needed a fix. Here's the one to apply:

OK, thanks!

#10 lore raw

Re: [PATCH v2 1/3] device property: add spaces to PROPERTY_ENTRY_STRING macro

In reply to Rafael J. Wysocki
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Andy Shevchenko

Just a style fix, no functional changes.

To be folded to Andrew's patch.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

What patch?

In linux-next from Andrew:

e39ece7 include-linux-propertyh-fix-build-issues-with-gcc-444-fix 40bb8a1 include/linux/property.h: fix build issues with gcc-4.4.4

Any pointers to the original patch submission(s)?

Yes, I found one [1] and added to v3 of this patch [2]

[1] http://comments.gmane.org/gmane.linux.kernel.commits.mm/97592
[2] http://www.spinics.net/lists/kernel/msg2151801.html

Quoted 9 lines

Thanks,
Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author reviewer
#11 lore raw

PATCH v2 2/3 device property: the secondary fwnode needs to depend on the primary

In reply to Andy Shevchenko

From: 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
index 0b22c8a..6c04d18 100644
@@ -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
#12 lore raw

Re: [PATCH v2 2/3] device property: the secondary fwnode needs to depend on the primary

Hi Andy,

Found a bug from my code..

Quoted 14 lines
drivers/base/property.c +1 -1
index 0b22c8a..6c04d18 100644
@@ -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;
 }

drivers/base/property.c EXPORT_SYMBOL_GPL(device_property_match_string); · line 426

Quoted 5 lines
drivers/base/property.c +1 -1
@@ -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)				\

This should be .._fwnode_ && _fwnode_->secondary)

drivers/base/property.c EXPORT_SYMBOL_GPL(device_property_match_string); · line 429

Quoted 3 lines
drivers/base/property.c +0 -0
 		_ret_ = FWNODE_PROP_READ(_fwnode_->secondary, _propname_, _type_,	\
 				_proptype_, _val_, _nval_);				\
 	_ret_;										\

Cheers,

Signature · 1 line
heikki
author reviewer
#13 lore raw

Re: [PATCH v2 2/3] device property: the secondary fwnode needs to depend on the primary

Quoted 25 lines · Heikki Krogerus

Hi Andy,

Found a bug from my code..

Quoted 21 lines
drivers/base/property.c +0 -0
index 0b22c8a..6c04d18 100644
@@ -218,7 +218,7 @@ bool fwnode_property_present(struct
 fwnode_handle *fwnode, const char *propname)
  	bool ret;


  ret = __fwnode_property_present(fwnode, propname);

drivers/base/property.c +1 -1
-	if (ret == false && fwnode->secondary)
+	if (ret == false && fwnode && fwnode->secondary)

  ret = __fwnode_property_present(fwnode->secondary, propname);
  return ret;
 }

drivers/base/property.c +0 -0
@@ -423,7 +423,7 @@
 EXPORT_SYMBOL_GPL(device_property_match_string);
  	int _ret_;							
 		\
  	_ret_ = FWNODE_PROP_READ(_fwnode_, _propname_, _type_,
 _proptype_,		\
Quoted 8 lines
Quoted 6 lines
drivers/base/property.c +0 -1
  				 _val_, _nval_);			
 		\
-	if (_ret_ == -EINVAL && _fwnode_->secondary)		
			\
drivers/base/property.c +1 -0
+	if (_ret_ == -EINVAL && fwnode && _fwnode_->secondary)	
			\

This should be .._fwnode_ && _fwnode_->secondary)

Yeah, we compiled it correctly due to fwnode presents in all occurrences of this macro.

I will fix and resend a new version.

Quoted 11 lines
Quoted 7 lines

  _ret_ = FWNODE_PROP_READ(_fwnode_->secondary,
_propname_, _type_, \

 				_proptype_, _val_, _nval_);	
			\
 	_ret_;							
			\

Cheers,

Signature · 7 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author reviewer
#14 lore raw

PATCH v2 3/3 device property: avoid allocations of 0 length

In reply to Andy Shevchenko

Arrays 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
index 6c04d18..7e2061b 100644
@@ -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