Commit 14a61442 authored by Eric Sesterhenn's avatar Eric Sesterhenn Committed by Adrian Bunk

BUG_ON conversion for fs/reiserfs

This patch converts several if () BUG(); construct to BUG_ON();
which occupies less space, uses unlikely and is safer when
BUG() is disabled. S_ISREG() has no side effects, so the
conversion is safe.
Signed-off-by: default avatarEric Sesterhenn <snakebyte@gmx.de>
Signed-off-by: default avatarAdrian Bunk <bunk@stusta.de>
parent 8d8f3cbe
...@@ -38,8 +38,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp) ...@@ -38,8 +38,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp)
int err; int err;
int jbegin_failure = 0; int jbegin_failure = 0;
if (!S_ISREG(inode->i_mode)) BUG_ON(!S_ISREG(inode->i_mode));
BUG();
/* fast out for when nothing needs to be done */ /* fast out for when nothing needs to be done */
if ((atomic_read(&inode->i_count) > 1 || if ((atomic_read(&inode->i_count) > 1 ||
...@@ -125,8 +124,7 @@ static int reiserfs_sync_file(struct file *p_s_filp, ...@@ -125,8 +124,7 @@ static int reiserfs_sync_file(struct file *p_s_filp,
int n_err; int n_err;
int barrier_done; int barrier_done;
if (!S_ISREG(p_s_inode->i_mode)) BUG_ON(!S_ISREG(p_s_inode->i_mode));
BUG();
n_err = sync_mapping_buffers(p_s_inode->i_mapping); n_err = sync_mapping_buffers(p_s_inode->i_mapping);
reiserfs_write_lock(p_s_inode->i_sb); reiserfs_write_lock(p_s_inode->i_sb);
barrier_done = reiserfs_commit_for_inode(p_s_inode); barrier_done = reiserfs_commit_for_inode(p_s_inode);
......
...@@ -75,8 +75,7 @@ static int sd_create_vi(struct virtual_node *vn, ...@@ -75,8 +75,7 @@ static int sd_create_vi(struct virtual_node *vn,
static int sd_check_left(struct virtual_item *vi, int free, static int sd_check_left(struct virtual_item *vi, int free,
int start_skip, int end_skip) int start_skip, int end_skip)
{ {
if (start_skip || end_skip) BUG_ON(start_skip || end_skip);
BUG();
return -1; return -1;
} }
...@@ -87,8 +86,7 @@ static int sd_check_right(struct virtual_item *vi, int free) ...@@ -87,8 +86,7 @@ static int sd_check_right(struct virtual_item *vi, int free)
static int sd_part_size(struct virtual_item *vi, int first, int count) static int sd_part_size(struct virtual_item *vi, int first, int count)
{ {
if (count) BUG_ON(count);
BUG();
return 0; return 0;
} }
...@@ -476,8 +474,7 @@ static int direntry_create_vi(struct virtual_node *vn, ...@@ -476,8 +474,7 @@ static int direntry_create_vi(struct virtual_node *vn,
vi->vi_index = TYPE_DIRENTRY; vi->vi_index = TYPE_DIRENTRY;
if (!(vi->vi_ih) || !vi->vi_item) BUG_ON(!(vi->vi_ih) || !vi->vi_item);
BUG();
dir_u->flags = 0; dir_u->flags = 0;
if (le_ih_k_offset(vi->vi_ih) == DOT_OFFSET) if (le_ih_k_offset(vi->vi_ih) == DOT_OFFSET)
...@@ -575,8 +572,7 @@ static int direntry_check_right(struct virtual_item *vi, int free) ...@@ -575,8 +572,7 @@ static int direntry_check_right(struct virtual_item *vi, int free)
free -= dir_u->entry_sizes[i]; free -= dir_u->entry_sizes[i];
entries++; entries++;
} }
if (entries == dir_u->entry_count) BUG_ON(entries == dir_u->entry_count);
BUG();
/* "." and ".." can not be separated from each other */ /* "." and ".." can not be separated from each other */
if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM) if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)
......
...@@ -718,8 +718,7 @@ static int add_to_chunk(struct buffer_chunk *chunk, struct buffer_head *bh, ...@@ -718,8 +718,7 @@ static int add_to_chunk(struct buffer_chunk *chunk, struct buffer_head *bh,
spinlock_t * lock, void (fn) (struct buffer_chunk *)) spinlock_t * lock, void (fn) (struct buffer_chunk *))
{ {
int ret = 0; int ret = 0;
if (chunk->nr >= CHUNK_SIZE) BUG_ON(chunk->nr >= CHUNK_SIZE);
BUG();
chunk->bh[chunk->nr++] = bh; chunk->bh[chunk->nr++] = bh;
if (chunk->nr >= CHUNK_SIZE) { if (chunk->nr >= CHUNK_SIZE) {
ret = 1; ret = 1;
...@@ -788,8 +787,7 @@ static inline int __add_jh(struct reiserfs_journal *j, struct buffer_head *bh, ...@@ -788,8 +787,7 @@ static inline int __add_jh(struct reiserfs_journal *j, struct buffer_head *bh,
/* buffer must be locked for __add_jh, should be able to have /* buffer must be locked for __add_jh, should be able to have
* two adds at the same time * two adds at the same time
*/ */
if (bh->b_private) BUG_ON(bh->b_private);
BUG();
jh->bh = bh; jh->bh = bh;
bh->b_private = jh; bh->b_private = jh;
} }
...@@ -2967,8 +2965,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th, ...@@ -2967,8 +2965,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
int retval; int retval;
reiserfs_check_lock_depth(p_s_sb, "journal_begin"); reiserfs_check_lock_depth(p_s_sb, "journal_begin");
if (nblocks > journal->j_trans_max) BUG_ON(nblocks > journal->j_trans_max);
BUG();
PROC_INFO_INC(p_s_sb, journal.journal_being); PROC_INFO_INC(p_s_sb, journal.journal_being);
/* set here for journal_join */ /* set here for journal_join */
...@@ -3084,9 +3081,8 @@ struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct ...@@ -3084,9 +3081,8 @@ struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
if (reiserfs_transaction_running(s)) { if (reiserfs_transaction_running(s)) {
th = current->journal_info; th = current->journal_info;
th->t_refcount++; th->t_refcount++;
if (th->t_refcount < 2) { BUG_ON(th->t_refcount < 2);
BUG();
}
return th; return th;
} }
th = kmalloc(sizeof(struct reiserfs_transaction_handle), GFP_NOFS); th = kmalloc(sizeof(struct reiserfs_transaction_handle), GFP_NOFS);
...@@ -3126,9 +3122,7 @@ static int journal_join(struct reiserfs_transaction_handle *th, ...@@ -3126,9 +3122,7 @@ static int journal_join(struct reiserfs_transaction_handle *th,
** pointer ** pointer
*/ */
th->t_handle_save = cur_th; th->t_handle_save = cur_th;
if (cur_th && cur_th->t_refcount > 1) { BUG_ON(cur_th && cur_th->t_refcount > 1);
BUG();
}
return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_JOIN); return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_JOIN);
} }
...@@ -3141,9 +3135,7 @@ int journal_join_abort(struct reiserfs_transaction_handle *th, ...@@ -3141,9 +3135,7 @@ int journal_join_abort(struct reiserfs_transaction_handle *th,
** pointer ** pointer
*/ */
th->t_handle_save = cur_th; th->t_handle_save = cur_th;
if (cur_th && cur_th->t_refcount > 1) { BUG_ON(cur_th && cur_th->t_refcount > 1);
BUG();
}
return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_ABORT); return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_ABORT);
} }
...@@ -3178,8 +3170,7 @@ int journal_begin(struct reiserfs_transaction_handle *th, ...@@ -3178,8 +3170,7 @@ int journal_begin(struct reiserfs_transaction_handle *th,
current->journal_info = th; current->journal_info = th;
} }
ret = do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_REG); ret = do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_REG);
if (current->journal_info != th) BUG_ON(current->journal_info != th);
BUG();
/* I guess this boils down to being the reciprocal of clm-2100 above. /* I guess this boils down to being the reciprocal of clm-2100 above.
* If do_journal_begin_r fails, we need to put it back, since journal_end * If do_journal_begin_r fails, we need to put it back, since journal_end
...@@ -3324,8 +3315,7 @@ int journal_end(struct reiserfs_transaction_handle *th, ...@@ -3324,8 +3315,7 @@ int journal_end(struct reiserfs_transaction_handle *th,
/* we aren't allowed to close a nested transaction on a different /* we aren't allowed to close a nested transaction on a different
** filesystem from the one in the task struct ** filesystem from the one in the task struct
*/ */
if (cur_th->t_super != th->t_super) BUG_ON(cur_th->t_super != th->t_super);
BUG();
if (th != cur_th) { if (th != cur_th) {
memcpy(current->journal_info, th, sizeof(*th)); memcpy(current->journal_info, th, sizeof(*th));
...@@ -3444,9 +3434,7 @@ int journal_end_sync(struct reiserfs_transaction_handle *th, ...@@ -3444,9 +3434,7 @@ int journal_end_sync(struct reiserfs_transaction_handle *th,
BUG_ON(!th->t_trans_id); BUG_ON(!th->t_trans_id);
/* you can sync while nested, very, very bad */ /* you can sync while nested, very, very bad */
if (th->t_refcount > 1) { BUG_ON(th->t_refcount > 1);
BUG();
}
if (journal->j_len == 0) { if (journal->j_len == 0) {
reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb),
1); 1);
...@@ -3556,9 +3544,8 @@ static int check_journal_end(struct reiserfs_transaction_handle *th, ...@@ -3556,9 +3544,8 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
** will be dealt with by next transaction that actually writes something, but should be taken ** will be dealt with by next transaction that actually writes something, but should be taken
** care of in this trans ** care of in this trans
*/ */
if (journal->j_len == 0) { BUG_ON(journal->j_len == 0);
BUG();
}
/* if wcount > 0, and we are called to with flush or commit_now, /* if wcount > 0, and we are called to with flush or commit_now,
** we wait on j_join_wait. We will wake up when the last writer has ** we wait on j_join_wait. We will wake up when the last writer has
** finished the transaction, and started it on its way to the disk. ** finished the transaction, and started it on its way to the disk.
...@@ -3592,9 +3579,8 @@ static int check_journal_end(struct reiserfs_transaction_handle *th, ...@@ -3592,9 +3579,8 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
unlock_journal(p_s_sb); unlock_journal(p_s_sb);
} }
} }
if (journal->j_trans_id == trans_id) { BUG_ON(journal->j_trans_id == trans_id);
BUG();
}
if (commit_now if (commit_now
&& journal_list_still_alive(p_s_sb, trans_id) && journal_list_still_alive(p_s_sb, trans_id)
&& wait_on_commit) { && wait_on_commit) {
...@@ -4074,9 +4060,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th, ...@@ -4074,9 +4060,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
set_commit_trans_len(commit, journal->j_len); set_commit_trans_len(commit, journal->j_len);
/* special check in case all buffers in the journal were marked for not logging */ /* special check in case all buffers in the journal were marked for not logging */
if (journal->j_len == 0) { BUG_ON(journal->j_len == 0);
BUG();
}
/* we're about to dirty all the log blocks, mark the description block /* we're about to dirty all the log blocks, mark the description block
* dirty now too. Don't mark the commit block dirty until all the * dirty now too. Don't mark the commit block dirty until all the
...@@ -4173,8 +4157,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th, ...@@ -4173,8 +4157,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
journal, jl, &jl->j_tail_bh_list); journal, jl, &jl->j_tail_bh_list);
lock_kernel(); lock_kernel();
} }
if (!list_empty(&jl->j_tail_bh_list)) BUG_ON(!list_empty(&jl->j_tail_bh_list));
BUG();
up(&jl->j_commit_lock); up(&jl->j_commit_lock);
/* honor the flush wishes from the caller, simple commits can /* honor the flush wishes from the caller, simple commits can
......
...@@ -67,8 +67,7 @@ inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de) ...@@ -67,8 +67,7 @@ inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
{ {
struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num; struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
if (de->de_entry_num >= ih_entry_count(de->de_ih)) BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
BUG();
de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num); de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num);
de->de_namelen = de->de_entrylen - (de_with_sd(deh) ? SD_SIZE : 0); de->de_namelen = de->de_entrylen - (de_with_sd(deh) ? SD_SIZE : 0);
...@@ -80,8 +79,7 @@ inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de) ...@@ -80,8 +79,7 @@ inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
// what entry points to // what entry points to
static inline void set_de_object_key(struct reiserfs_dir_entry *de) static inline void set_de_object_key(struct reiserfs_dir_entry *de)
{ {
if (de->de_entry_num >= ih_entry_count(de->de_ih)) BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
BUG();
de->de_dir_id = deh_dir_id(&(de->de_deh[de->de_entry_num])); de->de_dir_id = deh_dir_id(&(de->de_deh[de->de_entry_num]));
de->de_objectid = deh_objectid(&(de->de_deh[de->de_entry_num])); de->de_objectid = deh_objectid(&(de->de_deh[de->de_entry_num]));
} }
...@@ -90,8 +88,7 @@ static inline void store_de_entry_key(struct reiserfs_dir_entry *de) ...@@ -90,8 +88,7 @@ static inline void store_de_entry_key(struct reiserfs_dir_entry *de)
{ {
struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num; struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
if (de->de_entry_num >= ih_entry_count(de->de_ih)) BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
BUG();
/* store key of the found entry */ /* store key of the found entry */
de->de_entry_key.version = KEY_FORMAT_3_5; de->de_entry_key.version = KEY_FORMAT_3_5;
......
...@@ -1476,9 +1476,7 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, ...@@ -1476,9 +1476,7 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
int n_block_size = p_s_sb->s_blocksize; int n_block_size = p_s_sb->s_blocksize;
int cut_bytes; int cut_bytes;
BUG_ON(!th->t_trans_id); BUG_ON(!th->t_trans_id);
BUG_ON(n_new_file_size != p_s_inode->i_size);
if (n_new_file_size != p_s_inode->i_size)
BUG();
/* the page being sent in could be NULL if there was an i/o error /* the page being sent in could be NULL if there was an i/o error
** reading in the last block. The user will hit problems trying to ** reading in the last block. The user will hit problems trying to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment