[PATCH 09/36] driver core: register_memory/unregister_memory clean ups and bugfix

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Greg Kroah-Hartman
Date: Sunday, April 20, 2008 - 3:45 am

From: Badari Pulavarty <pbadari@us.ibm.com>

register_memory()/unregister_memory() never gets called with
"root". unregister_memory() is accessing kobject_name of
the object just freed up. Since no one uses the code,
lets take the code out. And also, make register_memory() static.

Another bug fix - before calling unregister_memory()
remove_memory_block() gets a ref on kobject. unregister_memory()
need to drop that ref before calling sysdev_unregister().

Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/base/memory.c |   22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index 1f3801a..7891f7c 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -62,8 +62,8 @@ void unregister_memory_notifier(struct notifier_block *nb)
 /*
  * register_memory - Setup a sysfs device for a memory block
  */
-int register_memory(struct memory_block *memory, struct mem_section *section,
-		struct node *root)
+static
+int register_memory(struct memory_block *memory, struct mem_section *section)
 {
 	int error;
 
@@ -71,26 +71,18 @@ int register_memory(struct memory_block *memory, struct mem_section *section,
 	memory->sysdev.id = __section_nr(section);
 
 	error = sysdev_register(&memory->sysdev);
-
-	if (root && !error)
-		error = sysfs_create_link(&root->sysdev.kobj,
-					  &memory->sysdev.kobj,
-					  kobject_name(&memory->sysdev.kobj));
-
 	return error;
 }
 
 static void
-unregister_memory(struct memory_block *memory, struct mem_section *section,
-		struct node *root)
+unregister_memory(struct memory_block *memory, struct mem_section *section)
 {
 	BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
 	BUG_ON(memory->sysdev.id != __section_nr(section));
 
+	/* drop the ref. we got in remove_memory_block() */
+	kobject_put(&memory->sysdev.kobj);
 	sysdev_unregister(&memory->sysdev);
-	if (root)
-		sysfs_remove_link(&root->sysdev.kobj,
-				  kobject_name(&memory->sysdev.kobj));
 }
 
 /*
@@ -345,7 +337,7 @@ static int add_memory_block(unsigned long node_id, struct mem_section *section,
 	mutex_init(&mem->state_mutex);
 	mem->phys_device = phys_device;
 
-	ret = register_memory(mem, section, NULL);
+	ret = register_memory(mem, section);
 	if (!ret)
 		ret = mem_create_simple_file(mem, phys_index);
 	if (!ret)
@@ -396,7 +388,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
 	mem_remove_simple_file(mem, phys_index);
 	mem_remove_simple_file(mem, state);
 	mem_remove_simple_file(mem, phys_device);
-	unregister_memory(mem, section, NULL);
+	unregister_memory(mem, section);
 
 	return 0;
 }
-- 
1.5.4.5

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 01/36] kobject: catch kobjects that are not initialized, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 02/36] uio: Kconfig improvements, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 03/36] uio: mark pci_device_id hilscher_pci_ids[] _ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 04/36] UIO: arch/arm/Kconfig: Make UIO available on ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 05/36] UIO: Remove needless PCI_DEVICE_ID definitio ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 06/36] UIO: Implement a UIO interface for the SMX C ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 07/36] UIO: hold a reference to the device's owner ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 08/36] driver core: memory: semaphore to mutex, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 09/36] driver core: register_memory/unregister_memo ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 10/36] driver core: Convert debug functions declare ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 11/36] sysfs: small header file cleanup for SYSFS=n, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 12/36] firmware: move firmware_class from Documenta ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 13/36] firmware: clean up samples for coding style ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 14/36] PNP: add all PNP card device id's as individ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 15/36] power_state: remove it from driver core, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 16/36] driver core: cpu: fix section mismatch in cp ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 17/36] sysdev: detect multiple driver registrations, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 19/36] PM: Handle device registrations during suspe ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 20/36] Driver core: Call device_pm_add() after bus_ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 21/36] PM: Fix misuse of wakeup flag accessors in s ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 22/36] PM: Make wakeup flags available whenever CON ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 23/36] PM: Convert wakeup flag accessors to inline ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 24/36] Driver core: make device_is_registered() wor ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 25/36] SYSFS: Explicitly include required header fi ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 26/36] Kobject: Replace list_for_each() with list_f ..., Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 27/36] PM: Remove legacy PM (fix), Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 28/36] Firmware: add iSCSI iBFT Support, Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 29/36] PM: Remove destroy_suspended_device(), Greg Kroah-Hartman, (Sun Apr 20, 3:45 am)
[PATCH 30/36] sysfs: refill attribute buffer when reading ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 31/36] driver core: replace remaining __FUNCTION__ ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 32/36] memstick: convert struct class_device to str ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 33/36] IB: convert struct class_device to struct device, Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 35/36] DRM: remove unused dev_class, Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)
[PATCH 36/36] SCSI: convert struct class_device to struct ..., Greg Kroah-Hartman, (Sun Apr 20, 3:46 am)