@@ -252,6 +252,63 @@ static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
252252 return 0 ;
253253}
254254
255+ static void udf_sb_free_bitmap (struct udf_bitmap * bitmap )
256+ {
257+ int i ;
258+ int nr_groups = bitmap -> s_nr_groups ;
259+ int size = sizeof (struct udf_bitmap ) + (sizeof (struct buffer_head * ) *
260+ nr_groups );
261+
262+ for (i = 0 ; i < nr_groups ; i ++ )
263+ if (bitmap -> s_block_bitmap [i ])
264+ brelse (bitmap -> s_block_bitmap [i ]);
265+
266+ if (size <= PAGE_SIZE )
267+ kfree (bitmap );
268+ else
269+ vfree (bitmap );
270+ }
271+
272+ static void udf_free_partition (struct udf_part_map * map )
273+ {
274+ int i ;
275+ struct udf_meta_data * mdata ;
276+
277+ if (map -> s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE )
278+ iput (map -> s_uspace .s_table );
279+ if (map -> s_partition_flags & UDF_PART_FLAG_FREED_TABLE )
280+ iput (map -> s_fspace .s_table );
281+ if (map -> s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP )
282+ udf_sb_free_bitmap (map -> s_uspace .s_bitmap );
283+ if (map -> s_partition_flags & UDF_PART_FLAG_FREED_BITMAP )
284+ udf_sb_free_bitmap (map -> s_fspace .s_bitmap );
285+ if (map -> s_partition_type == UDF_SPARABLE_MAP15 )
286+ for (i = 0 ; i < 4 ; i ++ )
287+ brelse (map -> s_type_specific .s_sparing .s_spar_map [i ]);
288+ else if (map -> s_partition_type == UDF_METADATA_MAP25 ) {
289+ mdata = & map -> s_type_specific .s_metadata ;
290+ iput (mdata -> s_metadata_fe );
291+ mdata -> s_metadata_fe = NULL ;
292+
293+ iput (mdata -> s_mirror_fe );
294+ mdata -> s_mirror_fe = NULL ;
295+
296+ iput (mdata -> s_bitmap_fe );
297+ mdata -> s_bitmap_fe = NULL ;
298+ }
299+ }
300+
301+ static void udf_sb_free_partitions (struct super_block * sb )
302+ {
303+ struct udf_sb_info * sbi = UDF_SB (sb );
304+ int i ;
305+
306+ for (i = 0 ; i < sbi -> s_partitions ; i ++ )
307+ udf_free_partition (& sbi -> s_partmaps [i ]);
308+ kfree (sbi -> s_partmaps );
309+ sbi -> s_partmaps = NULL ;
310+ }
311+
255312static int udf_show_options (struct seq_file * seq , struct dentry * root )
256313{
257314 struct super_block * sb = root -> d_sb ;
@@ -1283,7 +1340,7 @@ static int udf_load_logicalvol(struct super_block *sb, sector_t block,
12831340 BUG_ON (ident != TAG_IDENT_LVD );
12841341 lvd = (struct logicalVolDesc * )bh -> b_data ;
12851342 table_len = le32_to_cpu (lvd -> mapTableLength );
1286- if (sizeof ( * lvd ) + table_len > sb -> s_blocksize ) {
1343+ if (table_len > sb -> s_blocksize - sizeof ( * lvd ) ) {
12871344 udf_err (sb , "error loading logical volume descriptor: "
12881345 "Partition table too long (%u > %lu)\n" , table_len ,
12891346 sb -> s_blocksize - sizeof (* lvd ));
@@ -1596,7 +1653,11 @@ static int udf_load_sequence(struct super_block *sb, struct buffer_head *bh,
15961653 /* responsible for finding the PartitionDesc(s) */
15971654 if (!udf_process_sequence (sb , main_s , main_e , fileset ))
15981655 return 1 ;
1599- return !udf_process_sequence (sb , reserve_s , reserve_e , fileset );
1656+ udf_sb_free_partitions (sb );
1657+ if (!udf_process_sequence (sb , reserve_s , reserve_e , fileset ))
1658+ return 1 ;
1659+ udf_sb_free_partitions (sb );
1660+ return 0 ;
16001661}
16011662
16021663/*
@@ -1861,55 +1922,8 @@ u64 lvid_get_unique_id(struct super_block *sb)
18611922 return ret ;
18621923}
18631924
1864- static void udf_sb_free_bitmap (struct udf_bitmap * bitmap )
1865- {
1866- int i ;
1867- int nr_groups = bitmap -> s_nr_groups ;
1868- int size = sizeof (struct udf_bitmap ) + (sizeof (struct buffer_head * ) *
1869- nr_groups );
1870-
1871- for (i = 0 ; i < nr_groups ; i ++ )
1872- if (bitmap -> s_block_bitmap [i ])
1873- brelse (bitmap -> s_block_bitmap [i ]);
1874-
1875- if (size <= PAGE_SIZE )
1876- kfree (bitmap );
1877- else
1878- vfree (bitmap );
1879- }
1880-
1881- static void udf_free_partition (struct udf_part_map * map )
1882- {
1883- int i ;
1884- struct udf_meta_data * mdata ;
1885-
1886- if (map -> s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE )
1887- iput (map -> s_uspace .s_table );
1888- if (map -> s_partition_flags & UDF_PART_FLAG_FREED_TABLE )
1889- iput (map -> s_fspace .s_table );
1890- if (map -> s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP )
1891- udf_sb_free_bitmap (map -> s_uspace .s_bitmap );
1892- if (map -> s_partition_flags & UDF_PART_FLAG_FREED_BITMAP )
1893- udf_sb_free_bitmap (map -> s_fspace .s_bitmap );
1894- if (map -> s_partition_type == UDF_SPARABLE_MAP15 )
1895- for (i = 0 ; i < 4 ; i ++ )
1896- brelse (map -> s_type_specific .s_sparing .s_spar_map [i ]);
1897- else if (map -> s_partition_type == UDF_METADATA_MAP25 ) {
1898- mdata = & map -> s_type_specific .s_metadata ;
1899- iput (mdata -> s_metadata_fe );
1900- mdata -> s_metadata_fe = NULL ;
1901-
1902- iput (mdata -> s_mirror_fe );
1903- mdata -> s_mirror_fe = NULL ;
1904-
1905- iput (mdata -> s_bitmap_fe );
1906- mdata -> s_bitmap_fe = NULL ;
1907- }
1908- }
1909-
19101925static int udf_fill_super (struct super_block * sb , void * options , int silent )
19111926{
1912- int i ;
19131927 int ret ;
19141928 struct inode * inode = NULL ;
19151929 struct udf_options uopt ;
@@ -1974,7 +1988,6 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
19741988 sb -> s_op = & udf_sb_ops ;
19751989 sb -> s_export_op = & udf_export_ops ;
19761990
1977- sb -> s_dirt = 0 ;
19781991 sb -> s_magic = UDF_SUPER_MAGIC ;
19791992 sb -> s_time_gran = 1000 ;
19801993
@@ -2072,18 +2085,14 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
20722085error_out :
20732086 if (sbi -> s_vat_inode )
20742087 iput (sbi -> s_vat_inode );
2075- if (sbi -> s_partitions )
2076- for (i = 0 ; i < sbi -> s_partitions ; i ++ )
2077- udf_free_partition (& sbi -> s_partmaps [i ]);
20782088#ifdef CONFIG_UDF_NLS
20792089 if (UDF_QUERY_FLAG (sb , UDF_FLAG_NLS_MAP ))
20802090 unload_nls (sbi -> s_nls_map );
20812091#endif
20822092 if (!(sb -> s_flags & MS_RDONLY ))
20832093 udf_close_lvid (sb );
20842094 brelse (sbi -> s_lvid_bh );
2085-
2086- kfree (sbi -> s_partmaps );
2095+ udf_sb_free_partitions (sb );
20872096 kfree (sbi );
20882097 sb -> s_fs_info = NULL ;
20892098
@@ -2096,10 +2105,6 @@ void _udf_err(struct super_block *sb, const char *function,
20962105 struct va_format vaf ;
20972106 va_list args ;
20982107
2099- /* mark sb error */
2100- if (!(sb -> s_flags & MS_RDONLY ))
2101- sb -> s_dirt = 1 ;
2102-
21032108 va_start (args , fmt );
21042109
21052110 vaf .fmt = fmt ;
@@ -2128,24 +2133,20 @@ void _udf_warn(struct super_block *sb, const char *function,
21282133
21292134static void udf_put_super (struct super_block * sb )
21302135{
2131- int i ;
21322136 struct udf_sb_info * sbi ;
21332137
21342138 sbi = UDF_SB (sb );
21352139
21362140 if (sbi -> s_vat_inode )
21372141 iput (sbi -> s_vat_inode );
2138- if (sbi -> s_partitions )
2139- for (i = 0 ; i < sbi -> s_partitions ; i ++ )
2140- udf_free_partition (& sbi -> s_partmaps [i ]);
21412142#ifdef CONFIG_UDF_NLS
21422143 if (UDF_QUERY_FLAG (sb , UDF_FLAG_NLS_MAP ))
21432144 unload_nls (sbi -> s_nls_map );
21442145#endif
21452146 if (!(sb -> s_flags & MS_RDONLY ))
21462147 udf_close_lvid (sb );
21472148 brelse (sbi -> s_lvid_bh );
2148- kfree ( sbi -> s_partmaps );
2149+ udf_sb_free_partitions ( sb );
21492150 kfree (sb -> s_fs_info );
21502151 sb -> s_fs_info = NULL ;
21512152}
@@ -2161,7 +2162,6 @@ static int udf_sync_fs(struct super_block *sb, int wait)
21612162 * the buffer for IO
21622163 */
21632164 mark_buffer_dirty (sbi -> s_lvid_bh );
2164- sb -> s_dirt = 0 ;
21652165 sbi -> s_lvid_dirty = 0 ;
21662166 }
21672167 mutex_unlock (& sbi -> s_alloc_mutex );
0 commit comments