All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] core: ofnode: Have ofnode_read_u32_default return a u32
@ 2019-05-10 17:48 Trent Piepho
  2019-05-22 13:21 ` Simon Glass
  0 siblings, 1 reply; 2+ messages in thread
From: Trent Piepho @ 2019-05-10 17:48 UTC (permalink / raw)
  To: u-boot

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.

Cc: Simon Glass <sjg@chromium.org>
Signed-off-by: Trent Piepho <tpiepho@impinj.com>
---
 drivers/core/ofnode.c | 2 +-
 include/dm/ofnode.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index cc0c031e0d..0185f83399 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -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);
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index d206ee2caa..dcda22b31b 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -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
-- 
2.14.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [U-Boot] [PATCH] core: ofnode: Have ofnode_read_u32_default return a u32
  2019-05-10 17:48 [U-Boot] [PATCH] core: ofnode: Have ofnode_read_u32_default return a u32 Trent Piepho
@ 2019-05-22 13:21 ` Simon Glass
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Glass @ 2019-05-22 13:21 UTC (permalink / raw)
  To: u-boot

On Fri, 10 May 2019 at 11:48, Trent Piepho <tpiepho@impinj.com> wrote:
>
> 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.
>
> Cc: Simon Glass <sjg@chromium.org>
> Signed-off-by: Trent Piepho <tpiepho@impinj.com>
> ---
>  drivers/core/ofnode.c | 2 +-
>  include/dm/ofnode.h   | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)

Applied to u-boot-dm, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-22 13:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-10 17:48 [U-Boot] [PATCH] core: ofnode: Have ofnode_read_u32_default return a u32 Trent Piepho
2019-05-22 13:21 ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.