Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2938ffbd authored by Nathan Fontenot's avatar Nathan Fontenot Committed by Greg Kroah-Hartman
Browse files

Driver core: Add mutex for adding/removing memory blocks



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: default avatarNathan Fontenot <nfont@austin.ibm.com>
Reviewed-by: default avatarRobin Holt <holt@sgi.com>
Reviewed-By: default avatarKAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent e4619c85
Loading
Loading
Loading
Loading
+7 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,8 @@
#include <asm/atomic.h>
#include <asm/atomic.h>
#include <asm/uaccess.h>
#include <asm/uaccess.h>


static DEFINE_MUTEX(mem_sysfs_mutex);

#define MEMORY_CLASS_NAME	"memory"
#define MEMORY_CLASS_NAME	"memory"


static struct sysdev_class memory_sysdev_class = {
static struct sysdev_class memory_sysdev_class = {
@@ -484,6 +486,8 @@ static int add_memory_block(int nid, struct mem_section *section,
	if (!mem)
	if (!mem)
		return -ENOMEM;
		return -ENOMEM;


	mutex_lock(&mem_sysfs_mutex);

	mem->phys_index = __section_nr(section);
	mem->phys_index = __section_nr(section);
	mem->state = state;
	mem->state = state;
	mutex_init(&mem->state_mutex);
	mutex_init(&mem->state_mutex);
@@ -504,6 +508,7 @@ static int add_memory_block(int nid, struct mem_section *section,
			ret = register_mem_sect_under_node(mem, nid);
			ret = register_mem_sect_under_node(mem, nid);
	}
	}


	mutex_unlock(&mem_sysfs_mutex);
	return ret;
	return ret;
}
}


@@ -512,6 +517,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
{
{
	struct memory_block *mem;
	struct memory_block *mem;


	mutex_lock(&mem_sysfs_mutex);
	mem = find_memory_block(section);
	mem = find_memory_block(section);
	unregister_mem_sect_under_nodes(mem);
	unregister_mem_sect_under_nodes(mem);
	mem_remove_simple_file(mem, phys_index);
	mem_remove_simple_file(mem, phys_index);
@@ -520,6 +526,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
	mem_remove_simple_file(mem, removable);
	mem_remove_simple_file(mem, removable);
	unregister_memory(mem, section);
	unregister_memory(mem, section);


	mutex_unlock(&mem_sysfs_mutex);
	return 0;
	return 0;
}
}