[U-Boot,v3,1/4] fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()
diff mbox series

Message ID 20191023144641.5710-1-heiko@sntech.de
State Accepted
Delegated to: Simon Glass
Headers show
Series
  • [U-Boot,v3,1/4] fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()
Related show

Commit Message

Heiko Stuebner Oct. 23, 2019, 2:46 p.m. UTC
From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>

The change adding fdtdec_add_reserved_memory() already protected the added
phandle against the phandlep being NULL - making the phandlep var optional.

But in the early code checking for an already existing carveout this check
was not done and thus the phandle assignment could run into trouble,
so add a check there as well, which makes the function still return
successfully if a matching region is found, even though no-one wants to
work with the phandle.

Fixes: c9222a08b3f7 ("fdtdec: Implement fdtdec_add_reserved_memory()")
Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
---
changes in v2:
- add comment about phandlep allowed to be NULL

 include/fdtdec.h | 1 +
 lib/fdtdec.c     | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Heiko Stuebner Nov. 8, 2019, 2:50 p.m. UTC | #1
Am Mittwoch, 23. Oktober 2019, 16:46:38 CET schrieb Heiko Stuebner:
> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> 
> The change adding fdtdec_add_reserved_memory() already protected the added
> phandle against the phandlep being NULL - making the phandlep var optional.
> 
> But in the early code checking for an already existing carveout this check
> was not done and thus the phandle assignment could run into trouble,
> so add a check there as well, which makes the function still return
> successfully if a matching region is found, even though no-one wants to
> work with the phandle.
> 
> Fixes: c9222a08b3f7 ("fdtdec: Implement fdtdec_add_reserved_memory()")
> Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>

this patch already received in v2 a
Reviewed-by: Simon Glass <sjg@chromium.org>
Simon Glass Nov. 14, 2019, 1:43 p.m. UTC | #2
Am Mittwoch, 23. Oktober 2019, 16:46:38 CET schrieb Heiko Stuebner:
> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
>
> The change adding fdtdec_add_reserved_memory() already protected the added
> phandle against the phandlep being NULL - making the phandlep var optional.
>
> But in the early code checking for an already existing carveout this check
> was not done and thus the phandle assignment could run into trouble,
> so add a check there as well, which makes the function still return
> successfully if a matching region is found, even though no-one wants to
> work with the phandle.
>
> Fixes: c9222a08b3f7 ("fdtdec: Implement fdtdec_add_reserved_memory()")
> Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>

this patch already received in v2 a
Reviewed-by: Simon Glass <sjg@chromium.org>





Applied to u-boot-dm, thanks!

Patch
diff mbox series

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 635f53083b..54509a25ad 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -1078,6 +1078,7 @@  static inline int fdtdec_set_phandle(void *blob, int node, uint32_t phandle)
  * @param basename	base name of the node to create
  * @param carveout	information about the carveout region
  * @param phandlep	return location for the phandle of the carveout region
+ *			can be NULL
  * @return 0 on success or a negative error code on failure
  */
 int fdtdec_add_reserved_memory(void *blob, const char *basename,
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 74430c8b2f..d7c3684145 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1363,7 +1363,8 @@  int fdtdec_add_reserved_memory(void *blob, const char *basename,
 		}
 
 		if (addr == carveout->start && (addr + size) == carveout->end) {
-			*phandlep = fdt_get_phandle(blob, node);
+			if (phandlep)
+				*phandlep = fdt_get_phandle(blob, node);
 			return 0;
 		}
 	}