forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 958e46acc8e900e8569dd467c1af9b8d2d019394
kernel/fs/udf/balloc.c
....@@ -175,8 +175,8 @@
175175 {
176176 struct udf_sb_info *sbi = UDF_SB(sb);
177177 int alloc_count = 0;
178
- int bit, block, block_group, group_start;
179
- int nr_groups, bitmap_nr;
178
+ int bit, block, block_group;
179
+ int bitmap_nr;
180180 struct buffer_head *bh;
181181 __u32 part_len;
182182
....@@ -189,10 +189,8 @@
189189 block_count = part_len - first_block;
190190
191191 do {
192
- nr_groups = udf_compute_nr_groups(sb, partition);
193192 block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
194193 block_group = block >> (sb->s_blocksize_bits + 3);
195
- group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
196194
197195 bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
198196 if (bitmap_nr < 0)
....@@ -326,6 +324,17 @@
326324 got_block:
327325 newblock = bit + (block_group << (sb->s_blocksize_bits + 3)) -
328326 (sizeof(struct spaceBitmapDesc) << 3);
327
+
328
+ if (newblock >= sbi->s_partmaps[partition].s_partition_len) {
329
+ /*
330
+ * Ran off the end of the bitmap, and bits following are
331
+ * non-compliant (not all zero)
332
+ */
333
+ udf_err(sb, "bitmap for partition %d corrupted (block %u marked"
334
+ " as free, partition length is %u)\n", partition,
335
+ newblock, sbi->s_partmaps[partition].s_partition_len);
336
+ goto error_return;
337
+ }
329338
330339 if (!udf_clear_bit(bit, bh->b_data)) {
331340 udf_debug("bit already cleared for block %d\n", bit);
....@@ -555,7 +564,7 @@
555564 udf_pblk_t newblock = 0;
556565 uint32_t adsize;
557566 uint32_t elen, goal_elen = 0;
558
- struct kernel_lb_addr eloc, uninitialized_var(goal_eloc);
567
+ struct kernel_lb_addr eloc, goal_eloc;
559568 struct extent_position epos, goal_epos;
560569 int8_t etype;
561570 struct udf_inode_info *iinfo = UDF_I(table);
....@@ -652,12 +661,6 @@
652661 } else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
653662 udf_table_free_blocks(sb, map->s_uspace.s_table,
654663 bloc, offset, count);
655
- } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
656
- udf_bitmap_free_blocks(sb, map->s_fspace.s_bitmap,
657
- bloc, offset, count);
658
- } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
659
- udf_table_free_blocks(sb, map->s_fspace.s_table,
660
- bloc, offset, count);
661664 }
662665
663666 if (inode) {
....@@ -684,16 +687,6 @@
684687 map->s_uspace.s_table,
685688 partition, first_block,
686689 block_count);
687
- else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
688
- allocated = udf_bitmap_prealloc_blocks(sb,
689
- map->s_fspace.s_bitmap,
690
- partition, first_block,
691
- block_count);
692
- else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
693
- allocated = udf_table_prealloc_blocks(sb,
694
- map->s_fspace.s_table,
695
- partition, first_block,
696
- block_count);
697690 else
698691 return 0;
699692
....@@ -716,14 +709,6 @@
716709 else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
717710 block = udf_table_new_block(sb,
718711 map->s_uspace.s_table,
719
- partition, goal, err);
720
- else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
721
- block = udf_bitmap_new_block(sb,
722
- map->s_fspace.s_bitmap,
723
- partition, goal, err);
724
- else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
725
- block = udf_table_new_block(sb,
726
- map->s_fspace.s_table,
727712 partition, goal, err);
728713 else {
729714 *err = -EIO;