Commit 086336a22508affb7567bf6d383642554eda5a56

Authored by Heiko Stuebner
Committed by Simon Glass
1 parent 1dd49f577b

fdtdec: protect against another NULL phandlep in fdtdec_add_reserved_memory()

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>

Showing 2 changed files with 3 additions and 1 deletions Side-by-side Diff

... ... @@ -1061,6 +1061,7 @@
1061 1061 * @param basename base name of the node to create
1062 1062 * @param carveout information about the carveout region
1063 1063 * @param phandlep return location for the phandle of the carveout region
  1064 + * can be NULL
1064 1065 * @return 0 on success or a negative error code on failure
1065 1066 */
1066 1067 int fdtdec_add_reserved_memory(void *blob, const char *basename,
... ... @@ -1309,7 +1309,8 @@
1309 1309 }
1310 1310  
1311 1311 if (addr == carveout->start && (addr + size) == carveout->end) {
1312   - *phandlep = fdt_get_phandle(blob, node);
  1312 + if (phandlep)
  1313 + *phandlep = fdt_get_phandle(blob, node);
1313 1314 return 0;
1314 1315 }
1315 1316 }