This fixes a memory-corrupting bug: not only does it cause the warning,but as a result of dropping the refcount to zero, it causes thepcmcia_socket0 device structure to be freed while it still hasreferences, causing slab caches corruption. A fatal oops quicklyfollows this warning - often even just a 'dmesg' following the warningcauses the kernel to oops.

While testing suspend/resume on an ARM device with PCMCIA support, and aCF card inserted, I found that after five suspend and resumes, thekernel would complain, and shortly die after with slab corruption.

WARNING: at include/linux/kref.h:41 kobject_get+0x28/0x50()

As the message doesn't give a clue about which kobject, and the built-indebugging in drivers/base/power/main.c happens too late, this was addedright before each get_device():

As can be seen, the original function called pcmcia_get_socket() andpcmcia_put_socket() around the guts, whereas the replacement codecalls pcmcia_put_socket() only in one path. This creates an imbalancein the refcounting.

Testing with pcmcia_put_socket() put removed shows that the bug is gone: