kvfree(sbi->ckpt);
 
-       sb->s_fs_info = NULL;
        if (sbi->s_chksum_driver)
                crypto_free_shash(sbi->s_chksum_driver);
        kfree(sbi->raw_super);
 
-       destroy_device_list(sbi);
        f2fs_destroy_page_array_cache(sbi);
        f2fs_destroy_xattr_caches(sbi);
        mempool_destroy(sbi->write_io_dummy);
 #if IS_ENABLED(CONFIG_UNICODE)
        utf8_unload(sb->s_encoding);
 #endif
-       kfree(sbi);
 }
 
 int f2fs_sync_fs(struct super_block *sb, int sync)
 
 static void kill_f2fs_super(struct super_block *sb)
 {
-       if (sb->s_root) {
-               struct f2fs_sb_info *sbi = F2FS_SB(sb);
+       struct f2fs_sb_info *sbi = F2FS_SB(sb);
 
+       if (sb->s_root) {
                set_sbi_flag(sbi, SBI_IS_CLOSE);
                f2fs_stop_gc_thread(sbi);
                f2fs_stop_discard_thread(sbi);
                        sb->s_flags &= ~SB_RDONLY;
        }
        kill_block_super(sb);
+       /* Release block devices last, after fscrypt_destroy_keyring(). */
+       if (sbi) {
+               destroy_device_list(sbi);
+               kfree(sbi);
+               sb->s_fs_info = NULL;
+       }
 }
 
 static struct file_system_type f2fs_fs_type = {