From patchwork Thu Sep 17 23:32:11 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Chan X-Patchwork-Id: 48424 X-Patchwork-Delegate: khilman@deeprootsystems.com Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8HNWII4005102 for ; Thu, 17 Sep 2009 23:32:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753560AbZIQXcN (ORCPT ); Thu, 17 Sep 2009 19:32:13 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753483AbZIQXcN (ORCPT ); Thu, 17 Sep 2009 19:32:13 -0400 Received: from smtp-out.google.com ([216.239.33.17]:7329 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753239AbZIQXcN (ORCPT ); Thu, 17 Sep 2009 19:32:13 -0400 Received: from spaceape13.eur.corp.google.com (spaceape13.eur.corp.google.com [172.28.16.147]) by smtp-out.google.com with ESMTP id n8HNWF8q030383; Fri, 18 Sep 2009 00:32:15 +0100 Received: from localhost (cheetara.mtv.corp.google.com [172.18.103.81]) by spaceape13.eur.corp.google.com with ESMTP id n8HNWC6r010602; Thu, 17 Sep 2009 16:32:12 -0700 Received: by localhost (Postfix, from userid 18922) id E0DF7504EA8; Thu, 17 Sep 2009 16:32:11 -0700 (PDT) From: Mike Chan To: linux-omap@vger.kernel.org Cc: khilman@deeprootsystems.com, Mike Chan Subject: [PATCH] omap: resource: Fix race in register_resource() Date: Thu, 17 Sep 2009 16:32:11 -0700 Message-Id: <1253230331-701-1-git-send-email-mike@android.com> X-Mailer: git-send-email 1.5.4.5 X-System-Of-Record: true Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org Checking if the resource is already registered and adding to the list must be atomic or bad things can happen. Signed-off-by: Mike Chan --- arch/arm/plat-omap/resource.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm/plat-omap/resource.c b/arch/arm/plat-omap/resource.c index 111020a..4631912 100644 --- a/arch/arm/plat-omap/resource.c +++ b/arch/arm/plat-omap/resource.c @@ -255,6 +255,7 @@ int resource_refresh(void) */ int resource_register(struct shared_resource *resp) { + int ret = 0; if (!resp) return -EINVAL; @@ -262,12 +263,13 @@ int resource_register(struct shared_resource *resp) return -EINVAL; /* Verify that the resource is not already registered */ - if (resource_lookup(resp->name)) - return -EEXIST; + down(&res_mutex); + if (_resource_lookup(resp->name)) + ret = -EEXIST; + goto out; INIT_LIST_HEAD(&resp->users_list); - down(&res_mutex); /* Add the resource to the resource list */ list_add(&resp->node, &res_list); @@ -275,10 +277,11 @@ int resource_register(struct shared_resource *resp) if (resp->ops->init) resp->ops->init(resp); - up(&res_mutex); pr_debug("resource: registered %s\n", resp->name); - return 0; +out: + up(&res_mutex); + return ret; } EXPORT_SYMBOL(resource_register);