summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2014-07-23 06:55:15 -0600
committerSimon Glass <sjg@chromium.org>2014-07-23 14:07:26 +0100
commitc910e2e2da49036496a5b8b34425043675218d51 (patch)
tree29d2a8d0ec37379167cd6e5659ef26ef6fa18b3e
parentf4cdead24a1a0c39c29c04e107c2f98ba61c5da8 (diff)
downloadu-boot-imx-c910e2e2da49036496a5b8b34425043675218d51.zip
u-boot-imx-c910e2e2da49036496a5b8b34425043675218d51.tar.gz
u-boot-imx-c910e2e2da49036496a5b8b34425043675218d51.tar.bz2
dm: Avoid accessing uclasses before they are ready
Don't allow access to uclasses before they have been initialised. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--doc/driver-model/README.txt3
-rw-r--r--drivers/core/uclass.c2
-rw-r--r--test/dm/core.c14
3 files changed, 18 insertions, 1 deletions
diff --git a/doc/driver-model/README.txt b/doc/driver-model/README.txt
index 346cf08..672497d 100644
--- a/doc/driver-model/README.txt
+++ b/doc/driver-model/README.txt
@@ -95,7 +95,7 @@ are provided in test/dm. To run them, try:
You should see something like this:
<...U-Boot banner...>
- Running 16 driver model tests
+ Running 17 driver model tests
Test: dm_test_autobind
Test: dm_test_autoprobe
Test: dm_test_children
@@ -116,6 +116,7 @@ You should see something like this:
Test: dm_test_pre_reloc
Test: dm_test_remove
Test: dm_test_uclass
+ Test: dm_test_uclass_before_ready
Failures: 0
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index a27f3d5..61ca17e 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -23,6 +23,8 @@ struct uclass *uclass_find(enum uclass_id key)
{
struct uclass *uc;
+ if (!gd->dm_root)
+ return NULL;
/*
* TODO(sjg@chromium.org): Optimise this, perhaps moving the found
* node to the start of the list, or creating a linear array mapping
diff --git a/test/dm/core.c b/test/dm/core.c
index 24e0b6b..b0cfb42 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -570,3 +570,17 @@ static int dm_test_pre_reloc(struct dm_test_state *dms)
return 0;
}
DM_TEST(dm_test_pre_reloc, 0);
+
+static int dm_test_uclass_before_ready(struct dm_test_state *dms)
+{
+ struct uclass *uc;
+
+ ut_assertok(uclass_get(UCLASS_TEST, &uc));
+
+ memset(gd, '\0', sizeof(*gd));
+ ut_asserteq_ptr(NULL, uclass_find(UCLASS_TEST));
+
+ return 0;
+}
+
+DM_TEST(dm_test_uclass_before_ready, 0);