|
Kmods SIG |
9e3ffb |
From b0516833d8096c40ead3169c90d87392fb5f8f45 Mon Sep 17 00:00:00 2001
|
|
Kmods SIG |
9e3ffb |
From: Tetsuhiro Kohada <Kohada.Tetsuhiro@dc.MitsubishiElectric.co.jp>
|
|
Kmods SIG |
9e3ffb |
Date: Tue, 21 Apr 2020 10:58:58 +0900
|
|
Kmods SIG |
9e3ffb |
Subject: [Backport b0516833d809] exfat: Unify access to the boot sector
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
Unify access to boot sector via 'sbi->pbr_bh'.
|
|
Kmods SIG |
9e3ffb |
This fixes vol_flags inconsistency at read failed in fs_set_vol_flags(),
|
|
Kmods SIG |
9e3ffb |
and buffer_head leak in __exfat_fill_super().
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
Signed-off-by: Tetsuhiro Kohada <Kohada.Tetsuhiro@dc.MitsubishiElectric.co.jp>
|
|
Kmods SIG |
9e3ffb |
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
|
|
Kmods SIG |
9e3ffb |
---
|
|
Kmods SIG |
9e3ffb |
src/balloc.c | 3 ---
|
|
Kmods SIG |
9e3ffb |
src/super.c | 43 ++++++++++++++++---------------------------
|
|
Kmods SIG |
9e3ffb |
2 files changed, 16 insertions(+), 30 deletions(-)
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
diff --git a/src/balloc.c b/src/balloc.c
|
|
Kmods SIG |
9e3ffb |
index 6a04cc02565a1f3823ad9a109238bad9553a82f1..6774a5a6ded8290fb790bf70f04a1c6e3253cd7a 100644
|
|
Kmods SIG |
9e3ffb |
--- a/src/balloc.c
|
|
Kmods SIG |
9e3ffb |
+++ b/src/balloc.c
|
|
Kmods SIG |
9e3ffb |
@@ -91,7 +91,6 @@ static int exfat_allocate_bitmap(struct super_block *sb,
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
- sbi->pbr_bh = NULL;
|
|
Kmods SIG |
9e3ffb |
return 0;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
@@ -137,8 +136,6 @@ void exfat_free_bitmap(struct exfat_sb_info *sbi)
|
|
Kmods SIG |
9e3ffb |
{
|
|
Kmods SIG |
9e3ffb |
int i;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
- brelse(sbi->pbr_bh);
|
|
Kmods SIG |
9e3ffb |
-
|
|
Kmods SIG |
9e3ffb |
for (i = 0; i < sbi->map_sectors; i++)
|
|
Kmods SIG |
9e3ffb |
__brelse(sbi->vol_amap[i]);
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
diff --git a/src/super.c b/src/super.c
|
|
Kmods SIG |
9e3ffb |
index 86c87560602400ec2bc7587268bf025cc54e9ce7..6b63e5092628143ba5c8f3a5437eb3f5a1b68ea7 100644
|
|
Kmods SIG |
9e3ffb |
--- a/src/super.c
|
|
Kmods SIG |
9e3ffb |
+++ b/src/super.c
|
|
Kmods SIG |
9e3ffb |
@@ -49,6 +49,7 @@ static void exfat_put_super(struct super_block *sb)
|
|
Kmods SIG |
9e3ffb |
sync_blockdev(sb->s_bdev);
|
|
Kmods SIG |
9e3ffb |
exfat_set_vol_flags(sb, VOL_CLEAN);
|
|
Kmods SIG |
9e3ffb |
exfat_free_bitmap(sbi);
|
|
Kmods SIG |
9e3ffb |
+ brelse(sbi->pbr_bh);
|
|
Kmods SIG |
9e3ffb |
mutex_unlock(&sbi->s_lock);
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
call_rcu(&sbi->rcu, exfat_delayed_free);
|
|
Kmods SIG |
9e3ffb |
@@ -100,7 +101,7 @@ static int exfat_statfs(struct dentry *dentry, struct kstatfs *buf)
|
|
Kmods SIG |
9e3ffb |
int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flag)
|
|
Kmods SIG |
9e3ffb |
{
|
|
Kmods SIG |
9e3ffb |
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
9e3ffb |
- struct pbr64 *bpb;
|
|
Kmods SIG |
9e3ffb |
+ struct pbr64 *bpb = (struct pbr64 *)sbi->pbr_bh->b_data;
|
|
Kmods SIG |
9e3ffb |
bool sync = 0;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* flags are not changed */
|
|
Kmods SIG |
9e3ffb |
@@ -115,15 +116,6 @@ int exfat_set_vol_flags(struct super_block *sb, unsigned short new_flag)
|
|
Kmods SIG |
9e3ffb |
if (sb_rdonly(sb))
|
|
Kmods SIG |
9e3ffb |
return 0;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
- if (!sbi->pbr_bh) {
|
|
Kmods SIG |
9e3ffb |
- sbi->pbr_bh = sb_bread(sb, 0);
|
|
Kmods SIG |
9e3ffb |
- if (!sbi->pbr_bh) {
|
|
Kmods SIG |
9e3ffb |
- exfat_msg(sb, KERN_ERR, "failed to read boot sector");
|
|
Kmods SIG |
9e3ffb |
- return -ENOMEM;
|
|
Kmods SIG |
9e3ffb |
- }
|
|
Kmods SIG |
9e3ffb |
- }
|
|
Kmods SIG |
9e3ffb |
-
|
|
Kmods SIG |
9e3ffb |
- bpb = (struct pbr64 *)sbi->pbr_bh->b_data;
|
|
Kmods SIG |
9e3ffb |
bpb->bsx.vol_flags = cpu_to_le16(new_flag);
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
if (new_flag == VOL_DIRTY && !buffer_dirty(sbi->pbr_bh))
|
|
Kmods SIG |
9e3ffb |
@@ -355,10 +347,10 @@ static int exfat_read_root(struct inode *inode)
|
|
Kmods SIG |
9e3ffb |
return 0;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
-static struct pbr *exfat_read_pbr_with_logical_sector(struct super_block *sb,
|
|
Kmods SIG |
9e3ffb |
- struct buffer_head **prev_bh)
|
|
Kmods SIG |
9e3ffb |
+static struct pbr *exfat_read_pbr_with_logical_sector(struct super_block *sb)
|
|
Kmods SIG |
9e3ffb |
{
|
|
Kmods SIG |
9e3ffb |
- struct pbr *p_pbr = (struct pbr *) (*prev_bh)->b_data;
|
|
Kmods SIG |
9e3ffb |
+ struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
9e3ffb |
+ struct pbr *p_pbr = (struct pbr *) (sbi->pbr_bh)->b_data;
|
|
Kmods SIG |
9e3ffb |
unsigned short logical_sect = 0;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
logical_sect = 1 << p_pbr->bsx.f64.sect_size_bits;
|
|
Kmods SIG |
9e3ffb |
@@ -378,26 +370,23 @@ static struct pbr *exfat_read_pbr_with_logical_sector(struct super_block *sb,
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
if (logical_sect > sb->s_blocksize) {
|
|
Kmods SIG |
9e3ffb |
- struct buffer_head *bh = NULL;
|
|
Kmods SIG |
9e3ffb |
-
|
|
Kmods SIG |
9e3ffb |
- __brelse(*prev_bh);
|
|
Kmods SIG |
9e3ffb |
- *prev_bh = NULL;
|
|
Kmods SIG |
9e3ffb |
+ brelse(sbi->pbr_bh);
|
|
Kmods SIG |
9e3ffb |
+ sbi->pbr_bh = NULL;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
if (!sb_set_blocksize(sb, logical_sect)) {
|
|
Kmods SIG |
9e3ffb |
exfat_msg(sb, KERN_ERR,
|
|
Kmods SIG |
9e3ffb |
"unable to set blocksize %u", logical_sect);
|
|
Kmods SIG |
9e3ffb |
return NULL;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
- bh = sb_bread(sb, 0);
|
|
Kmods SIG |
9e3ffb |
- if (!bh) {
|
|
Kmods SIG |
9e3ffb |
+ sbi->pbr_bh = sb_bread(sb, 0);
|
|
Kmods SIG |
9e3ffb |
+ if (!sbi->pbr_bh) {
|
|
Kmods SIG |
9e3ffb |
exfat_msg(sb, KERN_ERR,
|
|
Kmods SIG |
9e3ffb |
"unable to read boot sector (logical sector size = %lu)",
|
|
Kmods SIG |
9e3ffb |
sb->s_blocksize);
|
|
Kmods SIG |
9e3ffb |
return NULL;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
- *prev_bh = bh;
|
|
Kmods SIG |
9e3ffb |
- p_pbr = (struct pbr *) bh->b_data;
|
|
Kmods SIG |
9e3ffb |
+ p_pbr = (struct pbr *)sbi->pbr_bh->b_data;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
return p_pbr;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
@@ -408,21 +397,20 @@ static int __exfat_fill_super(struct super_block *sb)
|
|
Kmods SIG |
9e3ffb |
int ret;
|
|
Kmods SIG |
9e3ffb |
struct pbr *p_pbr;
|
|
Kmods SIG |
9e3ffb |
struct pbr64 *p_bpb;
|
|
Kmods SIG |
9e3ffb |
- struct buffer_head *bh;
|
|
Kmods SIG |
9e3ffb |
struct exfat_sb_info *sbi = EXFAT_SB(sb);
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* set block size to read super block */
|
|
Kmods SIG |
9e3ffb |
sb_min_blocksize(sb, 512);
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* read boot sector */
|
|
Kmods SIG |
9e3ffb |
- bh = sb_bread(sb, 0);
|
|
Kmods SIG |
9e3ffb |
- if (!bh) {
|
|
Kmods SIG |
9e3ffb |
+ sbi->pbr_bh = sb_bread(sb, 0);
|
|
Kmods SIG |
9e3ffb |
+ if (!sbi->pbr_bh) {
|
|
Kmods SIG |
9e3ffb |
exfat_msg(sb, KERN_ERR, "unable to read boot sector");
|
|
Kmods SIG |
9e3ffb |
return -EIO;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* PRB is read */
|
|
Kmods SIG |
9e3ffb |
- p_pbr = (struct pbr *)bh->b_data;
|
|
Kmods SIG |
9e3ffb |
+ p_pbr = (struct pbr *)sbi->pbr_bh->b_data;
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* check the validity of PBR */
|
|
Kmods SIG |
9e3ffb |
if (le16_to_cpu((p_pbr->signature)) != PBR_SIGNATURE) {
|
|
Kmods SIG |
9e3ffb |
@@ -433,7 +421,7 @@ static int __exfat_fill_super(struct super_block *sb)
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
/* check logical sector size */
|
|
Kmods SIG |
9e3ffb |
- p_pbr = exfat_read_pbr_with_logical_sector(sb, &bh;;
|
|
Kmods SIG |
9e3ffb |
+ p_pbr = exfat_read_pbr_with_logical_sector(sb);
|
|
Kmods SIG |
9e3ffb |
if (!p_pbr) {
|
|
Kmods SIG |
9e3ffb |
ret = -EIO;
|
|
Kmods SIG |
9e3ffb |
goto free_bh;
|
|
Kmods SIG |
9e3ffb |
@@ -514,7 +502,7 @@ static int __exfat_fill_super(struct super_block *sb)
|
|
Kmods SIG |
9e3ffb |
free_upcase_table:
|
|
Kmods SIG |
9e3ffb |
exfat_free_upcase_table(sbi);
|
|
Kmods SIG |
9e3ffb |
free_bh:
|
|
Kmods SIG |
9e3ffb |
- brelse(bh);
|
|
Kmods SIG |
9e3ffb |
+ brelse(sbi->pbr_bh);
|
|
Kmods SIG |
9e3ffb |
return ret;
|
|
Kmods SIG |
9e3ffb |
}
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
@@ -606,6 +594,7 @@ static int exfat_fill_super(struct super_block *sb, struct fs_context *fc)
|
|
Kmods SIG |
9e3ffb |
free_table:
|
|
Kmods SIG |
9e3ffb |
exfat_free_upcase_table(sbi);
|
|
Kmods SIG |
9e3ffb |
exfat_free_bitmap(sbi);
|
|
Kmods SIG |
9e3ffb |
+ brelse(sbi->pbr_bh);
|
|
Kmods SIG |
9e3ffb |
|
|
Kmods SIG |
9e3ffb |
check_nls_io:
|
|
Kmods SIG |
9e3ffb |
unload_nls(sbi->nls_io);
|
|
Kmods SIG |
9e3ffb |
--
|
|
Kmods SIG |
9e3ffb |
2.31.1
|
|
Kmods SIG |
9e3ffb |
|