From 8b0c471773819c8201dc0b0123e1580639ee1570 Mon Sep 17 00:00:00 2001
From: Tetsuhiro Kohada <kohada.t2@gmail.com>
Date: Wed, 24 Jun 2020 09:54:54 +0900
Subject: [Backport 8b0c47177381] exfat: add error check when updating
dir-entries
Add error check when synchronously updating dir-entries.
Suggested-by: Sungjong Seo <sj1557.seo@samsung.com>
Signed-off-by: Tetsuhiro Kohada <kohada.t2@gmail.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
---
src/dir.c | 3 ++-
src/exfat_fs.h | 2 +-
src/file.c | 5 ++++-
src/inode.c | 9 +++++----
4 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/src/dir.c b/src/dir.c
index 542f1a5ab56fd60a2498f4437c85875cb07e9ef2..573659bfbc5542f20d1181e95ef292f341aab0d6 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -604,7 +604,7 @@ void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es)
es->modified = true;
}
-void exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
+int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
{
int i, err = 0;
@@ -617,6 +617,7 @@ void exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync)
else
brelse(es->bh[i]);
kfree(es);
+ return err;
}
static int exfat_walk_fat_chain(struct super_block *sb,
diff --git a/src/exfat_fs.h b/src/exfat_fs.h
index af0f526eece7bd05caa6a1b7fae28701776df5ed..cb51d6e831990f13413267f4fa0a04c3a6176380 100644
--- a/src/exfat_fs.h
+++ b/src/exfat_fs.h
@@ -460,7 +460,7 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es,
int num);
struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb,
struct exfat_chain *p_dir, int entry, unsigned int type);
-void exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
+int exfat_free_dentry_set(struct exfat_entry_set_cache *es, int sync);
int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir);
/* inode.c */
diff --git a/src/file.c b/src/file.c
index a6a063830edcb68944e55fe7308dee1312463b15..6bdabfd4b13426a1965a0e90598a3f5a2821bbe9 100644
--- a/src/file.c
+++ b/src/file.c
@@ -154,6 +154,7 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
struct timespec64 ts;
struct exfat_dentry *ep, *ep2;
struct exfat_entry_set_cache *es;
+ int err;
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry,
ES_ALL_ENTRIES);
@@ -188,7 +189,9 @@ int __exfat_truncate(struct inode *inode, loff_t new_size)
}
exfat_update_dir_chksum_with_entry_set(es);
- exfat_free_dentry_set(es, inode_needs_sync(inode));
+ err = exfat_free_dentry_set(es, inode_needs_sync(inode));
+ if (err)
+ return err;
}
/* cut off from the FAT chain */
diff --git a/src/inode.c b/src/inode.c
index cf9ca6c4d046eed63e8658d7216e2fedbd89cf22..f0160a7892a815cf22a0e495db104a9ebea35615 100644
--- a/src/inode.c
+++ b/src/inode.c
@@ -77,8 +77,7 @@ static int __exfat_write_inode(struct inode *inode, int sync)
ep2->dentry.stream.size = ep2->dentry.stream.valid_size;
exfat_update_dir_chksum_with_entry_set(es);
- exfat_free_dentry_set(es, sync);
- return 0;
+ return exfat_free_dentry_set(es, sync);
}
int exfat_write_inode(struct inode *inode, struct writeback_control *wbc)
@@ -222,6 +221,7 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
if (ei->dir.dir != DIR_DELETED && modified) {
struct exfat_dentry *ep;
struct exfat_entry_set_cache *es;
+ int err;
es = exfat_get_dentry_set(sb, &(ei->dir), ei->entry,
ES_ALL_ENTRIES);
@@ -240,8 +240,9 @@ static int exfat_map_cluster(struct inode *inode, unsigned int clu_offset,
ep->dentry.stream.valid_size;
exfat_update_dir_chksum_with_entry_set(es);
- exfat_free_dentry_set(es, inode_needs_sync(inode));
-
+ err = exfat_free_dentry_set(es, inode_needs_sync(inode));
+ if (err)
+ return err;
} /* end of if != DIR_DELETED */
inode->i_blocks +=
--
2.31.1