From patchwork Wed Jul 23 12:55:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 372925 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A1EB214019E for ; Wed, 23 Jul 2014 23:00:15 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BF0484B605; Wed, 23 Jul 2014 14:59:12 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kZjFgpRjKhEy; Wed, 23 Jul 2014 14:59:12 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 093B6A75A5; Wed, 23 Jul 2014 14:56:47 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C8F4EA7479 for ; Wed, 23 Jul 2014 14:56:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AnA8Qqb4qBEL for ; Wed, 23 Jul 2014 14:56:17 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ie0-f201.google.com (mail-ie0-f201.google.com [209.85.223.201]) by theia.denx.de (Postfix) with ESMTPS id 419C2A755E for ; Wed, 23 Jul 2014 14:55:56 +0200 (CEST) Received: by mail-ie0-f201.google.com with SMTP id tr6so319785ieb.2 for ; Wed, 23 Jul 2014 05:55:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ESGeI/syTRpvz4btmciCqLWUfVM7fZv9AaTovCHBRHE=; b=GVjZECqWfi5c359zn1oj4fE2nGsNKQSiIVgna1U8s8q1XQiNGyzOn7EVCjAslI69iF La9N9W50Xrr39bhRMfyqy7+DdSYRoXnygNyoI9iGeo+oBxG3CVj/faxQQlj2Qa6IdzTL 3QrjyVKkGA3mDWmqY2Lmg4Uw3BSQGsl0b7I8h4UWtkf6G9zUKkR1IEsxCItFG4xA/mY7 vumw36Xt9lviSFdy8VJin4p4OtePczbREudkfXPt4ndxKG5etCtwJ7292keNx/KTNbZR Qq2CcsMuqNwNz0Rkzrfk/LjZXCA90DOjY9BrT8hyieYuOl2VAbVKiHgDzfCauJBcwvOd 9Xkw== X-Gm-Message-State: ALoCoQnQP+a3IZBzfSeQz/fXRqbO6E8YIJEMN04ZL5qk8bw+MZQ8H4T2pJGjxCw1ojSaHK86xS0b X-Received: by 10.50.73.168 with SMTP id m8mr5335028igv.7.1406120155037; Wed, 23 Jul 2014 05:55:55 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id o69si391107yhp.6.2014.07.23.05.55.55 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jul 2014 05:55:55 -0700 (PDT) Received: from kaki.bld.corp.google.com (kaki.bld.corp.google.com [172.29.216.32]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id DE8F75A4417; Wed, 23 Jul 2014 05:55:54 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 9B7EB22047D; Wed, 23 Jul 2014 06:55:54 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 23 Jul 2014 06:55:15 -0600 Message-Id: <1406120124-9373-21-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.0.0.526.g5318336 In-Reply-To: <1406120124-9373-1-git-send-email-sjg@chromium.org> References: <1406120124-9373-1-git-send-email-sjg@chromium.org> Subject: [U-Boot] [PATCH v3 20/29] dm: Avoid accessing uclasses before they are ready X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Don't allow access to uclasses before they have been initialised. Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None doc/driver-model/README.txt | 3 ++- drivers/core/uclass.c | 2 ++ test/dm/core.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) 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);