Errors reported by Coverity in ext3.
Begin forwarded message:
Date: Thu, 1 Dec 2005 08:54:18 -0800
From: "Jayachandran C." <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Errors reported by Coverity in ext3.
[Re-sending to the ext3 list, with minor edits]
I'm in the process of fixing errors generated by the Coverity tool on the Linux kernel, and I would like your comment on a set of problems reported in ext3.
The main issue reported is not checking the return code of ext3_journal_get_write_access() in various places. I would like to know if there should be error handling in these cases. The places where the return value is not checked are(in the current kernel version):
fs/ext3/inode.c ext3_clear_blocks 1829 fs/ext3/namei.c ext3_append 63 fs/ext3/namei.c ext3_delete_entry 1585 fs/ext3/namei.c ext3_mkdir 1745 fs/ext3/namei.c ext3_rename 2273 fs/ext3/namei.c ext3_rename 2328
I have attached the full text of errors reported by Coverity on kernel version 2.6.13, for reference.
---
1. Error reported in ext3/namei.c
---
CID: 3549
Checker: CHECKED_RETURN
File: fs/ext3/namei.c
Function: ext3_rename
Description: Return value of "__ext3_journal_get_write_access" is not checked
2260 } else {
2261 BUFFER_TRACE(new_bh, "get write access");
Event check_return: Called function "__ext3_journal_get_write_access"
whose return value should be checked (checked 32 out of 39 times)
Event unchecked_value: Return value of
"__ext3_journal_get_write_access" is not checked Also see events:
2262 ext3_journal_get_write_access(handle, new_bh);
---
2. Error reported in ext3/inode.c
---
CID: 3548
Checker: CHECKED_RETURN
File: fs/ext3/inode.c
Function: ext3_clear_blocks
Description: Return value of "__ext3_journal_get_write_access" is not checked
1816 if (bh) {
1817 BUFFER_TRACE(bh, "retaking write access");
Event check_return: Called function "__ext3_journal_get_write_access"
whose return value should be checked (checked 32 out of 39 times)
Event unchecked_value: Return value of
"__ext3_journal_get_write_access" is not checked Also see events:
1818 ext3_journal_get_write_access(handle, bh);
1819 }
---
3. Error reported in ext3/namei.c
---
CID: 3547
Checker: CHECKED_RETURN
File: fs/ext3/namei.c
Function: ext3_delete_entry
Description: Return value of "__ext3_journal_get_write_access" is not checked
1573 if (de == de_del) {
1574 BUFFER_TRACE(bh, "get_write_access");
Event check_return: Called function "__ext3_journal_get_write_access"
whose return value should be checked (checked 32 out of 39 times)
Event unchecked_value: Return value of "__ext3_journal_get_write_access"
is not checked Also see events:
1575 ext3_journal_get_write_access(handle, bh);
1576 if (pde)
4. Error reported in ext3/namei.c
---
CID: 3546
Checker: CHECKED_RETURN
File: fs/ext3/namei.c
Function: ext3_append
Description: Return value of "__ext3_journal_get_write_access" is not checked
58 if ((bh = ext3_bread(handle, inode, *block, 1, err))) {
59 inode->i_size += inode->i_sb->s_blocksize;
60 EXT3_I(inode)->i_disksize = inode->i_size;
Event check_return: Called function "__ext3_journal_get_write_access"
whose return value should be checked (checked 32 out of 39 times)
Event unchecked_value: Return value of "__ext3_journal_get_write_access"
is not checked Also see events:
61 ext3_journal_get_write_access(handle,bh);
62 }
63 return bh;
---
5. Error reported in ext3/balloc.c
---
CID: 3545
Checker: CHECKED_RETURN
File: fs/ext3/balloc.c
Function: ext3_free_blocks_sb
Description: Return value of "test_and_set_bit" is not checked
439 BUFFER_TRACE(bitmap_bh, "set in b_committed_data"); 440 J_ASSERT_BH(bitmap_bh, 441 bh2jh(bitmap_bh)->b_committed_data != NULL);
Event check_return: Called function "test_and_set_bit" whose return
value should be checked (checked 83 out of 95 times)
Event unchecked_value: Return value of "test_and_set_bit" is not checked
442 ext3_set_bit_atomic(sb_bgl_lock(sbi, block_group), bit + i,
443 bh2jh(bitmap_bh)->b_committed_data);
--
Thanks,
-
C. Jayachandran [email protected]
Quoted 11 lines · Andrew Morton
2. Error reported in
ext3/inode.c
---
CID: 3548
Checker:CHECKED_RETURN
File:fs/ext3/inode.c
Function:ext3_clear_blocks
Description: Return value of "__ext3_journal_get_write_access" is not checked1816 if (bh) {
1817BUFFER_TRACE(bh, "retaking write access");
Quoted 8 lines
Event
check_return: Called function "__ext3_journal_get_write_access"
whose return value should be checked (checked 32 out of 39 times)
Eventunchecked_value: Return value of
"__ext3_journal_get_write_access" is not checked Also see events:1818
ext3_journal_get_write_access(handle, bh);
1819 }
---
Here is a patch we have locally for this one (though against a 2.6.9-RHEL4 kernel, likely usable in mainline with minor tweaks).
- ext3-check-jbd-errors-2.6.9.patch ---------------------------------------
include/linux/ext3_fs.h +1 -0
@@ -826,6 +826,7 @@ extern void ext3_put_super (struct superextern void ext3_write_super (struct super_block *);extern void ext3_write_super_lockfs (struct super_block *);extern void ext3_unlockfs (struct super_block *); +extern void ext3_commit_super (struct super_block *,struct ext3_super_block *,int );extern int ext3_remount (struct super_block *,int *,char *);extern int ext3_statfs (struct super_block *,struct kstatfs *);
fs/ext3/super.c +2 -2
@@ -43,7 +43,7 @@ static int ext3_load_journal(struct supe unsigned long journal_devnum);static int ext3_create_journal (struct super_block *,struct ext3_super_block *,int ); -static void ext3_commit_super (struct super_block * sb, +void ext3_commit_super (struct super_block * sb,struct ext3_super_block * es,int sync); static void ext3_mark_recovery_complete(struct super_block * sb,
@@ -1991,7 +1991,7 @@ static int ext3_create_journal(struct sureturn 0 ; } -static void ext3_commit_super (struct super_block * sb, +void ext3_commit_super (struct super_block * sb,struct ext3_super_block * es,int sync) {
fs/ext3/namei.c +4 -2
@@ -1599,7 +1599,7 @@ static int ext3_delete_entry (handle_t * struct buffer_head * bh) {struct ext3_dir_entry_2 * de, * pde; -int i; +int i, err; i =0 ; pde =NULL ;
@@ -1609,7 +1609,9 @@ static int ext3_delete_entry (handle_t *return -EIO ;if (de == de_del) {BUFFER_TRACE (bh,"get_write_access" ); -ext3_journal_get_write_access (handle, bh); + err =ext3_journal_get_write_access (handle, bh); +if (err) +return err;if (pde) pde->rec_len = cpu_to_le16(le16_to_cpu(pde->rec_len) +
fs/ext3/inode.c +11 -1
@@ -1807,8 +1812,18 @@ ext3_clear_blocks(handle_t *handle, struext3_mark_inode_dirty (handle, inode);ext3_journal_test_restart (handle, inode);if (bh) { +int err;BUFFER_TRACE (bh,"retaking write access" ); -ext3_journal_get_write_access (handle, bh); + err =ext3_journal_get_write_access (handle, bh); +if (err) { +struct super_block *sb = inode->i_sb; +struct ext3_super_block *es =EXT3_SB (sb)->s_es; +printk (KERN_CRIT "EXT3-fs: can't continue truncate\n" ); +EXT3_SB (sb)->s_mount_state |=EXT3_ERROR_FS ; + es->s_state |=cpu_to_le16 (EXT3_ERROR_FS ); +ext3_commit_super (sb, es,1 ); +return ; + } } }
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.