Skip to content

Commit 37171e3

Browse files
Seth Jenningsgregkh
authored andcommitted
drivers: base: remove improper get/put in add_memory_section()
The path through add_memory_section() when the memory block already exists uses flawed refcounting logic. A get_device() is done on a memory block using a pointer that might not be valid as we dropped our previous reference and didn't obtain a new reference in the proper way. Lets stop pretending and just remove the get/put. The mem_sysfs_mutex, which we hold over the entire init loop now, will prevent the memory blocks from disappearing from under us. Signed-off-by: Seth Jennings <sjenning@linux.vnet.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 37a7bd6 commit 37171e3

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/base/memory.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,12 @@ static int add_memory_section(struct mem_section *section,
613613
if (scn_nr >= (*mem_p)->start_section_nr &&
614614
scn_nr <= (*mem_p)->end_section_nr) {
615615
mem = *mem_p;
616-
get_device(&mem->dev);
617616
}
618617
}
619618

620-
if (mem) {
619+
if (mem)
621620
mem->section_count++;
622-
put_device(&mem->dev);
623-
} else {
621+
else {
624622
ret = init_memory_block(&mem, section, MEM_ONLINE);
625623
/* store memory_block pointer for next loop */
626624
if (!ret && mem_p)

0 commit comments

Comments
 (0)