diff mbox series

[U-Boot,006/126] dm: core: Correct bad cast in ofnode_get_addr_size_index()

Message ID 20190925145750.200592-7-sjg@chromium.org
State Accepted
Commit e18c41fca46a33bf76b4664796e3e132dc71c6cb
Delegated to: Bin Meng
Headers show
Series x86: Add initial support for apollolake | expand

Commit Message

Simon Glass Sept. 25, 2019, 2:55 p.m. UTC
At present this code passes an fdt_addr_t pointer as a u64 pointer which
is not save, since sizeof(fdt_addr_t) may be 4, e.g. with sandbox. Correct
this to avoid a stack corruption problem.

Fixes: e679d03b08 (core: ofnode: Add ofnode_get_addr_size_index)
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/core/ofnode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Bin Meng Oct. 3, 2019, 12:48 p.m. UTC | #1
On Wed, Sep 25, 2019 at 10:58 PM Simon Glass <sjg@chromium.org> wrote:
>
> At present this code passes an fdt_addr_t pointer as a u64 pointer which
> is not save, since sizeof(fdt_addr_t) may be 4, e.g. with sandbox. Correct

not safe

> this to avoid a stack corruption problem.
>
> Fixes: e679d03b08 (core: ofnode: Add ofnode_get_addr_size_index)
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  drivers/core/ofnode.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

I think this should go in v2019.10.

Tom, I will prepare a PR soon.

Regards,
Bin
Bin Meng Oct. 3, 2019, 1:14 p.m. UTC | #2
On Thu, Oct 3, 2019 at 8:48 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Wed, Sep 25, 2019 at 10:58 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > At present this code passes an fdt_addr_t pointer as a u64 pointer which
> > is not save, since sizeof(fdt_addr_t) may be 4, e.g. with sandbox. Correct
>
> not safe

Fixed this typo, and

>
> > this to avoid a stack corruption problem.
> >
> > Fixes: e679d03b08 (core: ofnode: Add ofnode_get_addr_size_index)
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >  drivers/core/ofnode.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
>
> I think this should go in v2019.10.
>
> Tom, I will prepare a PR soon.

applied to u-boot-x86, thanks!
diff mbox series

Patch

diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 5d47eccf1d1..297f0a0c7cc 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -261,12 +261,15 @@  fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
 
 	if (ofnode_is_np(node)) {
 		const __be32 *prop_val;
+		u64 size64;
 		uint flags;
 
-		prop_val = of_get_address(ofnode_to_np(node), index,
-					  (u64 *)size, &flags);
+		prop_val = of_get_address(ofnode_to_np(node), index, &size64,
+					  &flags);
 		if (!prop_val)
 			return FDT_ADDR_T_NONE;
+		if (size)
+			*size = size64;
 
 		ns = of_n_size_cells(ofnode_to_np(node));