amd64_edac: fix driver instance freeing
authorBorislav Petkov <borislav.petkov@amd.com>
Mon, 21 Dec 2009 14:15:59 +0000 (15:15 +0100)
committerBorislav Petkov <borislav.petkov@amd.com>
Thu, 24 Dec 2009 10:07:07 +0000 (11:07 +0100)
Fix use-after-free errors by pushing all memory-freeing calls to the end
of amd64_remove_one_instance().

Reported-by: Darren Jenkins <darrenrjenkins@gmail.com>
LKML-Reference: <1261370306.11354.52.camel@ICE-BOX>
Signed-off-by: Borislav Petkov <borislav.petkov@amd.com>
drivers/edac/amd64_edac.c

index 784cc5a1ebc3aa4515e605ad38567f229c773ca9..fb0d36b474115dac260cc063874bac54c45db9df 100644 (file)
@@ -2929,16 +2929,15 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
 
        amd64_free_mc_sibling_devices(pvt);
 
-       kfree(pvt);
-       mci->pvt_info = NULL;
-
-       mci_lookup[pvt->mc_node_id] = NULL;
-
        /* unregister from EDAC MCE */
        amd_report_gart_errors(false);
        amd_unregister_ecc_decoder(amd64_decode_bus_error);
 
        /* Free the EDAC CORE resources */
+       mci->pvt_info = NULL;
+       mci_lookup[pvt->mc_node_id] = NULL;
+
+       kfree(pvt);
        edac_mc_free(mci);
 }