From patchwork Tue May 4 00:14:45 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Chan X-Patchwork-Id: 96639 X-Patchwork-Delegate: khilman@deeprootsystems.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o440FaUp015310 for ; Tue, 4 May 2010 00:15:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933440Ab0EDAOx (ORCPT ); Mon, 3 May 2010 20:14:53 -0400 Received: from smtp-out.google.com ([74.125.121.35]:45554 "EHLO smtp-out.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932283Ab0EDAOv (ORCPT ); Mon, 3 May 2010 20:14:51 -0400 Received: from hpaq14.eem.corp.google.com (hpaq14.eem.corp.google.com [10.3.21.14]) by smtp-out.google.com with ESMTP id o440EmiL017155; Mon, 3 May 2010 17:14:48 -0700 Received: from mikechan.mtv.corp.google.com (mikechan.mtv.corp.google.com [172.18.102.252]) by hpaq14.eem.corp.google.com with ESMTP id o440EkmM013624; Mon, 3 May 2010 17:14:46 -0700 Received: by mikechan.mtv.corp.google.com (Postfix, from userid 18922) id CF7A522020; Mon, 3 May 2010 17:14:45 -0700 (PDT) From: Mike Chan Cc: khilman@deeprootsystems.com, linux-omap@vger.kernel.org, Mike Chan Subject: [PATCH] [ARM] omap-pm: resource: Protect static pool from concurrent get_user() calls Date: Mon, 3 May 2010 17:14:45 -0700 Message-Id: <1272932085-5664-1-git-send-email-mike@android.com> X-Mailer: git-send-email 1.7.0.1 X-System-Of-Record: true To: unlisted-recipients:; (no To-header on input) Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Tue, 04 May 2010 00:15:36 +0000 (UTC) diff --git a/arch/arm/plat-omap/resource.c b/arch/arm/plat-omap/resource.c index 0a7b79b..f769f7c 100644 --- a/arch/arm/plat-omap/resource.c +++ b/arch/arm/plat-omap/resource.c @@ -148,34 +148,39 @@ static struct users_list *get_user(void) int ind = 0; struct users_list *user; + /* + * When allocating from the static pool, we must lock resource mutex, + * to protect against concurrent get_user() calls. + */ + down(&res_mutex); /* See if something available in the static pool */ while (ind < MAX_USERS) { - if (usr_list[ind].usage == UNUSED) - break; - else - ind++; + if (usr_list[ind].usage == UNUSED) { + /* Pick from the static pool */ + user = &usr_list[ind]; + user->usage = STATIC_ALLOC; + up(&res_mutex); + return user; + } + ind++; } - if (ind < MAX_USERS) { - /* Pick from the static pool */ - user = &usr_list[ind]; - user->usage = STATIC_ALLOC; - } else { - /* By this time we hope slab is initialized */ - if (slab_is_available()) { - user = kmalloc(sizeof(struct users_list), GFP_KERNEL); - if (!user) { - printk(KERN_ERR "SRF:FATAL ERROR: kmalloc" - "failed\n"); - return ERR_PTR(-ENOMEM); - } - user->usage = DYNAMIC_ALLOC; - } else { - /* Dynamic alloc not available yet */ - printk(KERN_ERR "SRF: FATAL ERROR: users_list" - "initial POOL EMPTY before slab init\n"); + up(&res_mutex); + /* By this time we hope slab is initialized */ + if (slab_is_available()) { + user = kmalloc(sizeof(struct users_list), GFP_KERNEL); + if (!user) { + printk(KERN_ERR "SRF:FATAL ERROR: kmalloc" + "failed\n"); return ERR_PTR(-ENOMEM); } + user->usage = DYNAMIC_ALLOC; + } else { + /* Dynamic alloc not available yet */ + printk(KERN_ERR "SRF: FATAL ERROR: users_list" + "initial POOL EMPTY before slab init\n"); + return ERR_PTR(-ENOMEM); } + return user; } @@ -192,8 +197,12 @@ void free_user(struct users_list *user) if (user->usage == DYNAMIC_ALLOC) { kfree(user); } else { - user->usage = UNUSED; + /* + * It is not necesssary to lock when returning to the + * static pool. + */ user->dev = NULL; + user->usage = UNUSED; } }