Skip to content

Commit d5c514b

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: fix the newly allocated clusters are not freed in error handling
In error handling 'free_cluster', before num_alloc clusters allocated, p_chain->size will not updated and always 0, thus the newly allocated clusters are not freed. Signed-off-by: Yuezhang Mo <[email protected]> Reviewed-by: Andy Wu <[email protected]> Reviewed-by: Sungjong Seo <[email protected]> Signed-off-by: Namjae Jeon <[email protected]>
1 parent 3ce937c commit d5c514b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

fs/exfat/fatent.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
307307
struct exfat_chain *p_chain, bool sync_bmap)
308308
{
309309
int ret = -ENOSPC;
310-
unsigned int num_clusters = 0, total_cnt;
310+
unsigned int total_cnt;
311311
unsigned int hint_clu, new_clu, last_clu = EXFAT_EOF_CLUSTER;
312312
struct super_block *sb = inode->i_sb;
313313
struct exfat_sb_info *sbi = EXFAT_SB(sb);
@@ -358,7 +358,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
358358
if (new_clu != hint_clu &&
359359
p_chain->flags == ALLOC_NO_FAT_CHAIN) {
360360
if (exfat_chain_cont_cluster(sb, p_chain->dir,
361-
num_clusters)) {
361+
p_chain->size)) {
362362
ret = -EIO;
363363
goto free_cluster;
364364
}
@@ -371,8 +371,6 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
371371
goto free_cluster;
372372
}
373373

374-
num_clusters++;
375-
376374
/* update FAT table */
377375
if (p_chain->flags == ALLOC_FAT_CHAIN) {
378376
if (exfat_ent_set(sb, new_clu, EXFAT_EOF_CLUSTER)) {
@@ -389,13 +387,14 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
389387
goto free_cluster;
390388
}
391389
}
390+
p_chain->size++;
391+
392392
last_clu = new_clu;
393393

394-
if (--num_alloc == 0) {
394+
if (p_chain->size == num_alloc) {
395395
sbi->clu_srch_ptr = hint_clu;
396-
sbi->used_clusters += num_clusters;
396+
sbi->used_clusters += num_alloc;
397397

398-
p_chain->size += num_clusters;
399398
mutex_unlock(&sbi->bitmap_lock);
400399
return 0;
401400
}
@@ -406,7 +405,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
406405

407406
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
408407
if (exfat_chain_cont_cluster(sb, p_chain->dir,
409-
num_clusters)) {
408+
p_chain->size)) {
410409
ret = -EIO;
411410
goto free_cluster;
412411
}
@@ -415,8 +414,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,
415414
}
416415
}
417416
free_cluster:
418-
if (num_clusters)
419-
__exfat_free_cluster(inode, p_chain);
417+
__exfat_free_cluster(inode, p_chain);
420418
unlock:
421419
mutex_unlock(&sbi->bitmap_lock);
422420
return ret;

0 commit comments

Comments
 (0)