@@ -370,6 +370,7 @@ static void udf_table_free_blocks(struct super_block *sb,
370
370
struct extent_position oepos , epos ;
371
371
int8_t etype ;
372
372
struct udf_inode_info * iinfo ;
373
+ int ret = 0 ;
373
374
374
375
mutex_lock (& sbi -> s_alloc_mutex );
375
376
iinfo = UDF_I (table );
@@ -383,8 +384,12 @@ static void udf_table_free_blocks(struct super_block *sb,
383
384
epos .block = oepos .block = iinfo -> i_location ;
384
385
epos .bh = oepos .bh = NULL ;
385
386
386
- while (count &&
387
- (etype = udf_next_aext (table , & epos , & eloc , & elen , 1 )) != -1 ) {
387
+ while (count ) {
388
+ ret = udf_next_aext (table , & epos , & eloc , & elen , & etype , 1 );
389
+ if (ret < 0 )
390
+ goto error_return ;
391
+ if (ret == 0 )
392
+ break ;
388
393
if (((eloc .logicalBlockNum +
389
394
(elen >> sb -> s_blocksize_bits )) == start )) {
390
395
if ((0x3FFFFFFF - elen ) <
@@ -459,11 +464,8 @@ static void udf_table_free_blocks(struct super_block *sb,
459
464
adsize = sizeof (struct short_ad );
460
465
else if (iinfo -> i_alloc_type == ICBTAG_FLAG_AD_LONG )
461
466
adsize = sizeof (struct long_ad );
462
- else {
463
- brelse (oepos .bh );
464
- brelse (epos .bh );
467
+ else
465
468
goto error_return ;
466
- }
467
469
468
470
if (epos .offset + (2 * adsize ) > sb -> s_blocksize ) {
469
471
/* Steal a block from the extent being free'd */
@@ -479,10 +481,10 @@ static void udf_table_free_blocks(struct super_block *sb,
479
481
__udf_add_aext (table , & epos , & eloc , elen , 1 );
480
482
}
481
483
484
+ error_return :
482
485
brelse (epos .bh );
483
486
brelse (oepos .bh );
484
487
485
- error_return :
486
488
mutex_unlock (& sbi -> s_alloc_mutex );
487
489
return ;
488
490
}
@@ -498,6 +500,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
498
500
struct extent_position epos ;
499
501
int8_t etype = -1 ;
500
502
struct udf_inode_info * iinfo ;
503
+ int ret = 0 ;
501
504
502
505
if (first_block >= sbi -> s_partmaps [partition ].s_partition_len )
503
506
return 0 ;
@@ -516,11 +519,14 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
516
519
epos .bh = NULL ;
517
520
eloc .logicalBlockNum = 0xFFFFFFFF ;
518
521
519
- while (first_block != eloc .logicalBlockNum &&
520
- (etype = udf_next_aext (table , & epos , & eloc , & elen , 1 )) != -1 ) {
522
+ while (first_block != eloc .logicalBlockNum ) {
523
+ ret = udf_next_aext (table , & epos , & eloc , & elen , & etype , 1 );
524
+ if (ret < 0 )
525
+ goto err_out ;
526
+ if (ret == 0 )
527
+ break ;
521
528
udf_debug ("eloc=%u, elen=%u, first_block=%u\n" ,
522
529
eloc .logicalBlockNum , elen , first_block );
523
- ; /* empty loop body */
524
530
}
525
531
526
532
if (first_block == eloc .logicalBlockNum ) {
@@ -539,6 +545,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
539
545
alloc_count = 0 ;
540
546
}
541
547
548
+ err_out :
542
549
brelse (epos .bh );
543
550
544
551
if (alloc_count )
@@ -560,6 +567,7 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb,
560
567
struct extent_position epos , goal_epos ;
561
568
int8_t etype ;
562
569
struct udf_inode_info * iinfo = UDF_I (table );
570
+ int ret = 0 ;
563
571
564
572
* err = - ENOSPC ;
565
573
@@ -583,8 +591,10 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb,
583
591
epos .block = iinfo -> i_location ;
584
592
epos .bh = goal_epos .bh = NULL ;
585
593
586
- while (spread &&
587
- (etype = udf_next_aext (table , & epos , & eloc , & elen , 1 )) != -1 ) {
594
+ while (spread ) {
595
+ ret = udf_next_aext (table , & epos , & eloc , & elen , & etype , 1 );
596
+ if (ret <= 0 )
597
+ break ;
588
598
if (goal >= eloc .logicalBlockNum ) {
589
599
if (goal < eloc .logicalBlockNum +
590
600
(elen >> sb -> s_blocksize_bits ))
@@ -612,9 +622,11 @@ static udf_pblk_t udf_table_new_block(struct super_block *sb,
612
622
613
623
brelse (epos .bh );
614
624
615
- if (spread == 0xFFFFFFFF ) {
625
+ if (ret < 0 || spread == 0xFFFFFFFF ) {
616
626
brelse (goal_epos .bh );
617
627
mutex_unlock (& sbi -> s_alloc_mutex );
628
+ if (ret < 0 )
629
+ * err = ret ;
618
630
return 0 ;
619
631
}
620
632
0 commit comments