Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754044Ab0HISiy (ORCPT ); Mon, 9 Aug 2010 14:38:54 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:56429 "EHLO e8.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752606Ab0HISix (ORCPT ); Mon, 9 Aug 2010 14:38:53 -0400 Message-ID: <4C604B36.4070603@austin.ibm.com> Date: Mon, 09 Aug 2010 13:38:46 -0500 From: Nathan Fontenot User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@ozlabs.org CC: KAMEZAWA Hiroyuki , Dave Hansen , Greg KH Subject: [PATCH 4/8] v5 Add mutex for add/remove of memory blocks References: <4C60407C.2080608@austin.ibm.com> In-Reply-To: <4C60407C.2080608@austin.ibm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1795 Lines: 63 Add a new mutex for use in adding and removing of memory blocks. This is needed to avoid any race conditions in which the same memory block could be added and removed at the same time. Signed-off-by: Nathan Fontenot --- drivers/base/memory.c | 7 +++++++ 1 file changed, 7 insertions(+) Index: linux-2.6/drivers/base/memory.c =================================================================== --- linux-2.6.orig/drivers/base/memory.c 2010-08-09 07:49:04.000000000 -0500 +++ linux-2.6/drivers/base/memory.c 2010-08-09 07:50:20.000000000 -0500 @@ -27,6 +27,8 @@ #include #include +static DEFINE_MUTEX(mem_sysfs_mutex); + #define MEMORY_CLASS_NAME "memory" static struct sysdev_class memory_sysdev_class = { @@ -485,6 +487,8 @@ static int add_memory_block(int nid, str if (!mem) return -ENOMEM; + mutex_lock(&mem_sysfs_mutex); + mem->start_phys_index = __section_nr(section); mem->state = state; atomic_inc(&mem->section_count); @@ -508,6 +512,7 @@ static int add_memory_block(int nid, str ret = register_mem_sect_under_node(mem, nid); } + mutex_unlock(&mem_sysfs_mutex); return ret; } @@ -516,6 +521,7 @@ int remove_memory_block(unsigned long no { struct memory_block *mem; + mutex_lock(&mem_sysfs_mutex); mem = find_memory_block(section); if (atomic_dec_and_test(&mem->section_count)) { @@ -528,6 +534,7 @@ int remove_memory_block(unsigned long no unregister_memory(mem, section); } + mutex_unlock(&mem_sysfs_mutex); return 0; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/