Skip to contentSkip to conversation

core: ofnode: Have ofnode_read_u32_default return a u32

PATCH New Trent Piepho 2 participants 2 messages May 10, 2019 – May 22, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 core: ofnode: Have ofnode_read_u32_default return a u32

It was returning an int, which doesn't work if the u32 it is reading, or the default value, will overflow a signed int.

While it could be made to work, when using a C standard/compiler where casting negative signed values to unsigned has a defined behavior, combined with careful casting, it seems obvious one is meant to use ofnode_read_s32_default() with signed values.

---
 drivers/core/ofnode.c | 2 +-
 include/dm/ofnode.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/core/ofnode.c +1 -1
index cc0c031e0d..0185f83399 100644
@@ -39,7 +39,7 @@ int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
 	return 0;
 }
 
-int ofnode_read_u32_default(ofnode node, const char *propname, u32 def)
+u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def)
 {
 	assert(ofnode_valid(node));
 	ofnode_read_u32(node, propname, &def);
include/dm/ofnode.h +1 -1
index d206ee2caa..dcda22b31b 100644
@@ -224,7 +224,7 @@ static inline int ofnode_read_s32(ofnode node, const char *propname,
  * @def:	default value to return if the property has no value
  * @return property value, or @def if not found
  */
-int ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
+u32 ofnode_read_u32_default(ofnode ref, const char *propname, u32 def);
 
 /**
  * ofnode_read_s32_default() - Read a 32-bit integer from a property
Signature · 1 line
2.14.5
#1 lore raw

PATCH 1/1 core: ofnode: Have ofnode_read_u32_default return a u32

Quoted 9 lines · Trent Piepho

It was returning an int, which doesn't work if the u32 it is reading, or the default value, will overflow a signed int.

While it could be made to work, when using a C standard/compiler where casting negative signed values to unsigned has a defined behavior, combined with careful casting, it seems obvious one is meant to use ofnode_read_s32_default() with signed values.

Quoted 6 lines
---
 drivers/core/ofnode.c | 2 +-
 include/dm/ofnode.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!