Since commit 7a623c039 ("edac: rewrite the sysfs code to use structdevice") edac_mc_alloc() no longer initializes embedded kobjects instruct mem_ctl_info. Therefore edac_mc_free() can no longer simplydecrement a kobject reference count to free the allocated memoryunless the memory controller driver module had also callededac_mc_add_mc().

Now edac_mc_free() will check if the newly embedded struct devicehas been registered with sysfs before using either the standarddevice release functions or freeing the data structures itself withlogic pulled out of the error path of edac_mc_alloc().