]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: Avoid accessing uclasses before they are ready
authorSimon Glass <sjg@chromium.org>
Wed, 23 Jul 2014 12:55:15 +0000 (06:55 -0600)
committerSimon Glass <sjg@chromium.org>
Wed, 23 Jul 2014 13:07:26 +0000 (14:07 +0100)
Don't allow access to uclasses before they have been initialised.

Signed-off-by: Simon Glass <sjg@chromium.org>
doc/driver-model/README.txt
drivers/core/uclass.c
test/dm/core.c

index 346cf08429ac8f71c3fbc22ded8f717e52582e46..672497d4822d63db88e5162ca914bbb3b1067668 100644 (file)
@@ -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
 
 
index a27f3d50275277e4ab29fa0a33837d2645ce3033..61ca17e564a25dff143da7c26b8d886dab90de04 100644 (file)
@@ -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
index 24e0b6b898dbb7c1aed601b2ce5bf6a601a57909..b0cfb42c85fc692a5d5ffb0ef11d22d5f5bcea90 100644 (file)
@@ -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);