]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()
authorHeiko Stuebner <heiko.stuebner@theobroma-systems.com>
Wed, 23 Oct 2019 14:46:38 +0000 (16:46 +0200)
committerSimon Glass <sjg@chromium.org>
Thu, 14 Nov 2019 13:09:34 +0000 (07:09 -0600)
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
include/fdtdec.h
lib/fdtdec.c

index f1e58f9732dbf1de5957781b28bc8da97b92cfec..e150975b276470f41314d10a49f24a6b0ab75411 100644 (file)
@@ -1061,6 +1061,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,
index 125d9dbf26395c2262b338c6bb7d77d0e7a08bcb..38a0cff25ee7de70e0af4dc42f1ade08580ec101 100644 (file)
@@ -1309,7 +1309,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;
                }
        }