diff mbox

[4/9] v4 Add mutex for add/remove of memory blocks

Message ID 4C581C26.5080007@austin.ibm.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nathan Fontenot Aug. 3, 2010, 1:39 p.m. UTC
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 <nfont@austin.ibm.com>
---
 drivers/base/memory.c |    9 +++++++++
 1 file changed, 9 insertions(+)

Comments

KAMEZAWA Hiroyuki Aug. 5, 2010, 4:53 a.m. UTC | #1
On Tue, 03 Aug 2010 08:39:50 -0500
Nathan Fontenot <nfont@austin.ibm.com> wrote:

> 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 <nfont@austin.ibm.com>

Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

But a nitpick (see below)

> ---
>  drivers/base/memory.c |    9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> Index: linux-2.6/drivers/base/memory.c
> ===================================================================
> --- linux-2.6.orig/drivers/base/memory.c	2010-08-02 13:35:00.000000000 -0500
> +++ linux-2.6/drivers/base/memory.c	2010-08-02 13:45:34.000000000 -0500
> @@ -27,6 +27,8 @@
>  #include <asm/atomic.h>
>  #include <asm/uaccess.h>
>  
> +static struct mutex mem_sysfs_mutex;
> +

For static symbol of mutex, we usually do
	static DEFINE_MUTEX(mem_sysfs_mutex);

Then, extra calls of mutex_init() is not required.
Nathan Fontenot Aug. 9, 2010, 1:55 p.m. UTC | #2
On 08/04/2010 11:53 PM, KAMEZAWA Hiroyuki wrote:
> On Tue, 03 Aug 2010 08:39:50 -0500
> Nathan Fontenot <nfont@austin.ibm.com> wrote:
> 
>> 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 <nfont@austin.ibm.com>
> 
> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> 
> But a nitpick (see below)
> 
>> ---
>>  drivers/base/memory.c |    9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> Index: linux-2.6/drivers/base/memory.c
>> ===================================================================
>> --- linux-2.6.orig/drivers/base/memory.c	2010-08-02 13:35:00.000000000 -0500
>> +++ linux-2.6/drivers/base/memory.c	2010-08-02 13:45:34.000000000 -0500
>> @@ -27,6 +27,8 @@
>>  #include <asm/atomic.h>
>>  #include <asm/uaccess.h>
>>  
>> +static struct mutex mem_sysfs_mutex;
>> +
> 
> For static symbol of mutex, we usually do
> 	static DEFINE_MUTEX(mem_sysfs_mutex);
> 
> Then, extra calls of mutex_init() is not required.
> 

ok,  fixed in the next version of the patches.

-Nathan
diff mbox

Patch

Index: linux-2.6/drivers/base/memory.c
===================================================================
--- linux-2.6.orig/drivers/base/memory.c	2010-08-02 13:35:00.000000000 -0500
+++ linux-2.6/drivers/base/memory.c	2010-08-02 13:45:34.000000000 -0500
@@ -27,6 +27,8 @@ 
 #include <asm/atomic.h>
 #include <asm/uaccess.h>
 
+static struct 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;
 }
 
@@ -562,6 +569,8 @@  int __init memory_dev_init(void)
 	if (ret)
 		goto out;
 
+	mutex_init(&mem_sysfs_mutex);
+
 	/*
 	 * Create entries for memory sections that were found
 	 * during boot and have been initialized