diff mbox series

[U-Boot,1/3] fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()

Message ID 20191008002207.14396-1-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() | expand

Commit Message

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

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 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
> sucessfully if a matching region is found, even though no-one wants to

successfully

> work with the phandle.
>
> Fixes: c9222a08b3f7 ("fdtdec: Implement fdtdec_add_reserved_memory()")
> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
> ---
>  lib/fdtdec.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
> index 74525c84e7..17455c5506 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);

Can you please update the function comment to indicate that this can be NULL?

>                         return 0;
>                 }
>         }
> --
> 2.23.0
>

Regards,
Simon
diff mbox series

Patch

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 74525c84e7..17455c5506 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;
 		}
 	}