diff options
author | Theodore Ts'o <tytso@mit.edu> | 2010-07-27 11:56:08 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2010-07-27 11:56:08 -0400 |
commit | f613dfcb3345dacb8cf99b7bb359acc1c18a1157 (patch) | |
tree | a2e437f59acbd87d0d2a63c7bd20b016a844f5cb /fs/ext4/super.c | |
parent | cc937db74bd5fe75f4cfebbfc4a04c1da10f0695 (diff) |
ext4: check to make make sure bd_dev is set before dereferencing it
There are some drivers which may not set bdev->bd_dev. So make sure
it is non-NULL before dereferencing it.
Google-Bug-Id: 1773557
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/super.c')
-rw-r--r-- | fs/ext4/super.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index c1036bc8a539..e046eba24782 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -2304,6 +2304,8 @@ static ssize_t session_write_kbytes_show(struct ext4_attr *a, | |||
2304 | { | 2304 | { |
2305 | struct super_block *sb = sbi->s_buddy_cache->i_sb; | 2305 | struct super_block *sb = sbi->s_buddy_cache->i_sb; |
2306 | 2306 | ||
2307 | if (!sb->s_bdev->bd_part) | ||
2308 | return snprintf(buf, PAGE_SIZE, "0\n"); | ||
2307 | return snprintf(buf, PAGE_SIZE, "%lu\n", | 2309 | return snprintf(buf, PAGE_SIZE, "%lu\n", |
2308 | (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - | 2310 | (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - |
2309 | sbi->s_sectors_written_start) >> 1); | 2311 | sbi->s_sectors_written_start) >> 1); |
@@ -2314,6 +2316,8 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a, | |||
2314 | { | 2316 | { |
2315 | struct super_block *sb = sbi->s_buddy_cache->i_sb; | 2317 | struct super_block *sb = sbi->s_buddy_cache->i_sb; |
2316 | 2318 | ||
2319 | if (!sb->s_bdev->bd_part) | ||
2320 | return snprintf(buf, PAGE_SIZE, "0\n"); | ||
2317 | return snprintf(buf, PAGE_SIZE, "%llu\n", | 2321 | return snprintf(buf, PAGE_SIZE, "%llu\n", |
2318 | (unsigned long long)(sbi->s_kbytes_written + | 2322 | (unsigned long long)(sbi->s_kbytes_written + |
2319 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - | 2323 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - |
@@ -2575,8 +2579,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
2575 | sbi->s_resgid = EXT4_DEF_RESGID; | 2579 | sbi->s_resgid = EXT4_DEF_RESGID; |
2576 | sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; | 2580 | sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; |
2577 | sbi->s_sb_block = sb_block; | 2581 | sbi->s_sb_block = sb_block; |
2578 | sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part, | 2582 | if (sb->s_bdev->bd_part) |
2579 | sectors[1]); | 2583 | sbi->s_sectors_written_start = |
2584 | part_stat_read(sb->s_bdev->bd_part, sectors[1]); | ||
2580 | 2585 | ||
2581 | unlock_kernel(); | 2586 | unlock_kernel(); |
2582 | 2587 | ||
@@ -3492,10 +3497,14 @@ static int ext4_commit_super(struct super_block *sb, int sync) | |||
3492 | */ | 3497 | */ |
3493 | if (!(sb->s_flags & MS_RDONLY)) | 3498 | if (!(sb->s_flags & MS_RDONLY)) |
3494 | es->s_wtime = cpu_to_le32(get_seconds()); | 3499 | es->s_wtime = cpu_to_le32(get_seconds()); |
3495 | es->s_kbytes_written = | 3500 | if (sb->s_bdev->bd_part) |
3496 | cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + | 3501 | es->s_kbytes_written = |
3502 | cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + | ||
3497 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - | 3503 | ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - |
3498 | EXT4_SB(sb)->s_sectors_written_start) >> 1)); | 3504 | EXT4_SB(sb)->s_sectors_written_start) >> 1)); |
3505 | else | ||
3506 | es->s_kbytes_written = | ||
3507 | cpu_to_le64(EXT4_SB(sb)->s_kbytes_written); | ||
3499 | ext4_free_blocks_count_set(es, percpu_counter_sum_positive( | 3508 | ext4_free_blocks_count_set(es, percpu_counter_sum_positive( |
3500 | &EXT4_SB(sb)->s_freeblocks_counter)); | 3509 | &EXT4_SB(sb)->s_freeblocks_counter)); |
3501 | es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( | 3510 | es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( |