@@ -703,16 +703,19 @@ static int erofs_fc_get_tree(struct fs_context *fc)
703
703
GET_TREE_BDEV_QUIET_LOOKUP : 0 );
704
704
#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
705
705
if (ret == - ENOTBLK ) {
706
+ struct file * file ;
707
+
706
708
if (!fc -> source )
707
709
return invalf (fc , "No source specified" );
708
- sbi -> fdev = filp_open (fc -> source , O_RDONLY | O_LARGEFILE , 0 );
709
- if (IS_ERR (sbi -> fdev ))
710
- return PTR_ERR (sbi -> fdev );
710
+
711
+ file = filp_open (fc -> source , O_RDONLY | O_LARGEFILE , 0 );
712
+ if (IS_ERR (file ))
713
+ return PTR_ERR (file );
714
+ sbi -> fdev = file ;
711
715
712
716
if (S_ISREG (file_inode (sbi -> fdev )-> i_mode ) &&
713
717
sbi -> fdev -> f_mapping -> a_ops -> read_folio )
714
718
return get_tree_nodev (fc , erofs_fc_fill_super );
715
- fput (sbi -> fdev );
716
719
}
717
720
#endif
718
721
return ret ;
@@ -763,19 +766,24 @@ static void erofs_free_dev_context(struct erofs_dev_context *devs)
763
766
kfree (devs );
764
767
}
765
768
766
- static void erofs_fc_free (struct fs_context * fc )
769
+ static void erofs_sb_free (struct erofs_sb_info * sbi )
767
770
{
768
- struct erofs_sb_info * sbi = fc -> s_fs_info ;
769
-
770
- if (!sbi )
771
- return ;
772
-
773
771
erofs_free_dev_context (sbi -> devs );
774
772
kfree (sbi -> fsid );
775
773
kfree (sbi -> domain_id );
774
+ if (sbi -> fdev )
775
+ fput (sbi -> fdev );
776
776
kfree (sbi );
777
777
}
778
778
779
+ static void erofs_fc_free (struct fs_context * fc )
780
+ {
781
+ struct erofs_sb_info * sbi = fc -> s_fs_info ;
782
+
783
+ if (sbi ) /* free here if an error occurs before transferring to sb */
784
+ erofs_sb_free (sbi );
785
+ }
786
+
779
787
static const struct fs_context_operations erofs_context_ops = {
780
788
.parse_param = erofs_fc_parse_param ,
781
789
.get_tree = erofs_fc_get_tree ,
@@ -813,15 +821,9 @@ static void erofs_kill_sb(struct super_block *sb)
813
821
kill_anon_super (sb );
814
822
else
815
823
kill_block_super (sb );
816
-
817
- erofs_free_dev_context (sbi -> devs );
818
824
fs_put_dax (sbi -> dax_dev , NULL );
819
825
erofs_fscache_unregister_fs (sb );
820
- kfree (sbi -> fsid );
821
- kfree (sbi -> domain_id );
822
- if (sbi -> fdev )
823
- fput (sbi -> fdev );
824
- kfree (sbi );
826
+ erofs_sb_free (sbi );
825
827
sb -> s_fs_info = NULL ;
826
828
}
827
829
0 commit comments