diff mbox series

[U-Boot,v3,2/4] fdtdec: only create phandle if caller wants it in fdtdec_add_reserved_memory()

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

Commit Message

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

The phandlep pointer returning the phandle to the caller is optional
and if it is not set when calling fdtdec_add_reserved_memory() it is
highly likely that the caller is not interested in a phandle to the
created reserved-memory area and really just wants that area added.

So just don't create a phandle in that case.

Signed-off-by: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
---
changes in v2:
- update function comment

 include/fdtdec.h |  2 +-
 lib/fdtdec.c     | 16 +++++++++-------
 2 files changed, 10 insertions(+), 8 deletions(-)

Comments

Heiko Stuebner Nov. 8, 2019, 2:51 p.m. UTC | #1
Am Mittwoch, 23. Oktober 2019, 16:46:39 CET schrieb Heiko Stuebner:
> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
> 
> The phandlep pointer returning the phandle to the caller is optional
> and if it is not set when calling fdtdec_add_reserved_memory() it is
> highly likely that the caller is not interested in a phandle to the
> created reserved-memory area and really just wants that area added.
> 
> So just don't create a phandle in that case.
> 
> 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:42 p.m. UTC | #2
Am Mittwoch, 23. Oktober 2019, 16:46:39 CET schrieb Heiko Stuebner:
> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
>
> The phandlep pointer returning the phandle to the caller is optional
> and if it is not set when calling fdtdec_add_reserved_memory() it is
> highly likely that the caller is not interested in a phandle to the
> created reserved-memory area and really just wants that area added.
>
> So just don't create a phandle in that case.
>
> 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!
Simon Glass Nov. 14, 2019, 1:43 p.m. UTC | #3
Am Mittwoch, 23. Oktober 2019, 16:46:39 CET schrieb Heiko Stuebner:
> From: Heiko Stuebner <heiko.stuebner@theobroma-systems.com>
>
> The phandlep pointer returning the phandle to the caller is optional
> and if it is not set when calling fdtdec_add_reserved_memory() it is
> highly likely that the caller is not interested in a phandle to the
> created reserved-memory area and really just wants that area added.
>
> So just don't create a phandle in that case.
>
> 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!
Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/include/fdtdec.h b/include/fdtdec.h
index 54509a25ad..fe8e7770ec 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -1078,7 +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
+ *			can be NULL if no phandle should be added
  * @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 d7c3684145..c841aafa2a 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1393,13 +1393,15 @@  int fdtdec_add_reserved_memory(void *blob, const char *basename,
 	if (node < 0)
 		return node;
 
-	err = fdt_generate_phandle(blob, &phandle);
-	if (err < 0)
-		return err;
-
-	err = fdtdec_set_phandle(blob, node, phandle);
-	if (err < 0)
-		return err;
+	if (phandlep) {
+		err = fdt_generate_phandle(blob, &phandle);
+		if (err < 0)
+			return err;
+
+		err = fdtdec_set_phandle(blob, node, phandle);
+		if (err < 0)
+			return err;
+	}
 
 	/* store one or two address cells */
 	if (na > 1)