diff mbox

[U-Boot] dm: core: Fix Handling global_data moving in SPL

Message ID 20170210134104.15996-1-lokeshvutla@ti.com
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Lokesh Vutla Feb. 10, 2017, 1:41 p.m. UTC
commit 2f11cd9121658 ("dm: core: Handle global_data moving in SPL")
handles relocation of GD in SPL if spl_init() is called before
board_init_r(). But it is not necessary that spl_init() is not
always called before board_init_r(). So, uclass_root.next might
not be initialized and accessing uclass_root.next->prev gives
an abort. Update the uclass_root only if it is available.

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
---
- I encountered this problem when trying to enable SPL_DM on AM43xx
  devices.
 drivers/core/root.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Simon Glass Feb. 10, 2017, 6:38 p.m. UTC | #1
Hi Lokesh,

On 10 February 2017 at 06:41, Lokesh Vutla <lokeshvutla@ti.com> wrote:
> commit 2f11cd9121658 ("dm: core: Handle global_data moving in SPL")
> handles relocation of GD in SPL if spl_init() is called before
> board_init_r(). But it is not necessary that spl_init() is not
> always called before board_init_r(). So, uclass_root.next might

Can you reword to drop the double negative?

> not be initialized and accessing uclass_root.next->prev gives
> an abort. Update the uclass_root only if it is available.
>
> Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>

Reviewed-by: Simon Glass <sjg@chromium.org>

> ---
> - I encountered this problem when trying to enable SPL_DM on AM43xx
>   devices.


Eek - good spotting!

>  drivers/core/root.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/core/root.c b/drivers/core/root.c
> index 9edfc1efb6..8d570f3f78 100644
> --- a/drivers/core/root.c
> +++ b/drivers/core/root.c
> @@ -44,8 +44,10 @@ struct udevice *dm_root(void)
>  void dm_fixup_for_gd_move(struct global_data *new_gd)
>  {
>         /* The sentinel node has moved, so update things that point to it */
> -       new_gd->uclass_root.next->prev = &new_gd->uclass_root;
> -       new_gd->uclass_root.prev->next = &new_gd->uclass_root;
> +       if (new_gd->uclass_root.next)
> +               new_gd->uclass_root.next->prev = &new_gd->uclass_root;
> +       if (new_gd->uclass_root.prev)
> +               new_gd->uclass_root.prev->next = &new_gd->uclass_root;

Can you use

 if (gd->dm_root) {... }

We will never see prev without next, so what you have is confusing.

>  }
>
>  fdt_addr_t dm_get_translation_offset(void)
> --
> 2.11.0
>

Regards,
Simon
diff mbox

Patch

diff --git a/drivers/core/root.c b/drivers/core/root.c
index 9edfc1efb6..8d570f3f78 100644
--- a/drivers/core/root.c
+++ b/drivers/core/root.c
@@ -44,8 +44,10 @@  struct udevice *dm_root(void)
 void dm_fixup_for_gd_move(struct global_data *new_gd)
 {
 	/* The sentinel node has moved, so update things that point to it */
-	new_gd->uclass_root.next->prev = &new_gd->uclass_root;
-	new_gd->uclass_root.prev->next = &new_gd->uclass_root;
+	if (new_gd->uclass_root.next)
+		new_gd->uclass_root.next->prev = &new_gd->uclass_root;
+	if (new_gd->uclass_root.prev)
+		new_gd->uclass_root.prev->next = &new_gd->uclass_root;
 }
 
 fdt_addr_t dm_get_translation_offset(void)