]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
drivers: base: remove improper get/put in add_memory_section()
authorSeth Jennings <sjenning@linux.vnet.ibm.com>
Tue, 20 Aug 2013 17:13:02 +0000 (12:13 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Aug 2013 18:49:47 +0000 (11:49 -0700)
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>
drivers/base/memory.c

index a9e9c0902cce544c44b62048113b562b8adaab65..9438d541b5c3353532dc499ce56b2fc1ae57fd3c 100644 (file)
@@ -613,14 +613,12 @@ static int add_memory_section(struct mem_section *section,
                if (scn_nr >= (*mem_p)->start_section_nr &&
                    scn_nr <= (*mem_p)->end_section_nr) {
                        mem = *mem_p;
-                       get_device(&mem->dev);
                }
        }
 
-       if (mem) {
+       if (mem)
                mem->section_count++;
-               put_device(&mem->dev);
-       } else {
+       else {
                ret = init_memory_block(&mem, section, MEM_ONLINE);
                /* store memory_block pointer for next loop */
                if (!ret && mem_p)