ubi: Put MTD device after it is not used
[sfrench/cifs-2.6.git] / drivers / mtd / ubi / build.c
index a4e3454133a47eacdcc61034c11b6c98d831e9c8..09170b707339e57be9833cbc9b25fca6d738c424 100644 (file)
@@ -1101,10 +1101,10 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
        ubi_wl_close(ubi);
        ubi_free_internal_volumes(ubi);
        vfree(ubi->vtbl);
-       put_mtd_device(ubi->mtd);
        vfree(ubi->peb_buf);
        vfree(ubi->fm_buf);
        ubi_msg(ubi, "mtd%d is detached", ubi->mtd->index);
+       put_mtd_device(ubi->mtd);
        put_device(&ubi->dev);
        return 0;
 }