[U-Boot,2/3] fdtdec: only create phandle if caller wants it in fdtdec_add_reserved_memory()
diff mbox series

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

Commit Message

Heiko Stuebner Oct. 8, 2019, 12:22 a.m. UTC
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@sntech.de>
---
 lib/fdtdec.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

Comments

Simon Glass Oct. 22, 2019, 12:16 a.m. UTC | #1
Hi Heiko,

On Mon, 7 Oct 2019 at 18:22, Heiko Stuebner <heiko@sntech.de> wrote:
>
> 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.

Update function comment?

>
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> ---
>  lib/fdtdec.c | 16 +++++++++-------
>  1 file changed, 9 insertions(+), 7 deletions(-)

Regards,
Simon

Patch
diff mbox series

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 17455c5506..39e87e89c9 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)