Skip to content

Commit 14a6144

Browse files
SesterhennEricAdrianBunk
authored andcommitted
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: Eric Sesterhenn <snakebyte@gmx.de> Signed-off-by: Adrian Bunk <bunk@stusta.de>
1 parent 8d8f3cb commit 14a6144

5 files changed

Lines changed: 26 additions & 54 deletions

File tree

‎fs/reiserfs/file.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp)
3838
int err;
3939
int jbegin_failure = 0;
4040

41-
if (!S_ISREG(inode->i_mode))
42-
BUG();
41+
BUG_ON(!S_ISREG(inode->i_mode));
4342

4443
/* fast out for when nothing needs to be done */
4544
if ((atomic_read(&inode->i_count) > 1 ||
@@ -125,8 +124,7 @@ static int reiserfs_sync_file(struct file *p_s_filp,
125124
int n_err;
126125
int barrier_done;
127126

128-
if (!S_ISREG(p_s_inode->i_mode))
129-
BUG();
127+
BUG_ON(!S_ISREG(p_s_inode->i_mode));
130128
n_err = sync_mapping_buffers(p_s_inode->i_mapping);
131129
reiserfs_write_lock(p_s_inode->i_sb);
132130
barrier_done = reiserfs_commit_for_inode(p_s_inode);

‎fs/reiserfs/item_ops.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ static int sd_create_vi(struct virtual_node *vn,
7575
static int sd_check_left(struct virtual_item *vi, int free,
7676
int start_skip, int end_skip)
7777
{
78-
if (start_skip || end_skip)
79-
BUG();
78+
BUG_ON(start_skip || end_skip);
8079
return -1;
8180
}
8281

@@ -87,8 +86,7 @@ static int sd_check_right(struct virtual_item *vi, int free)
8786

8887
static int sd_part_size(struct virtual_item *vi, int first, int count)
8988
{
90-
if (count)
91-
BUG();
89+
BUG_ON(count);
9290
return 0;
9391
}
9492

@@ -476,8 +474,7 @@ static int direntry_create_vi(struct virtual_node *vn,
476474

477475
vi->vi_index = TYPE_DIRENTRY;
478476

479-
if (!(vi->vi_ih) || !vi->vi_item)
480-
BUG();
477+
BUG_ON(!(vi->vi_ih) || !vi->vi_item);
481478

482479
dir_u->flags = 0;
483480
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)
575572
free -= dir_u->entry_sizes[i];
576573
entries++;
577574
}
578-
if (entries == dir_u->entry_count)
579-
BUG();
575+
BUG_ON(entries == dir_u->entry_count);
580576

581577
/* "." and ".." can not be separated from each other */
582578
if ((dir_u->flags & DIRENTRY_VI_FIRST_DIRENTRY_ITEM)

‎fs/reiserfs/journal.c‎

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,7 @@ static int add_to_chunk(struct buffer_chunk *chunk, struct buffer_head *bh,
718718
spinlock_t * lock, void (fn) (struct buffer_chunk *))
719719
{
720720
int ret = 0;
721-
if (chunk->nr >= CHUNK_SIZE)
722-
BUG();
721+
BUG_ON(chunk->nr >= CHUNK_SIZE);
723722
chunk->bh[chunk->nr++] = bh;
724723
if (chunk->nr >= CHUNK_SIZE) {
725724
ret = 1;
@@ -788,8 +787,7 @@ static inline int __add_jh(struct reiserfs_journal *j, struct buffer_head *bh,
788787
/* buffer must be locked for __add_jh, should be able to have
789788
* two adds at the same time
790789
*/
791-
if (bh->b_private)
792-
BUG();
790+
BUG_ON(bh->b_private);
793791
jh->bh = bh;
794792
bh->b_private = jh;
795793
}
@@ -2967,8 +2965,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
29672965
int retval;
29682966

29692967
reiserfs_check_lock_depth(p_s_sb, "journal_begin");
2970-
if (nblocks > journal->j_trans_max)
2971-
BUG();
2968+
BUG_ON(nblocks > journal->j_trans_max);
29722969

29732970
PROC_INFO_INC(p_s_sb, journal.journal_being);
29742971
/* set here for journal_join */
@@ -3084,9 +3081,8 @@ struct reiserfs_transaction_handle *reiserfs_persistent_transaction(struct
30843081
if (reiserfs_transaction_running(s)) {
30853082
th = current->journal_info;
30863083
th->t_refcount++;
3087-
if (th->t_refcount < 2) {
3088-
BUG();
3089-
}
3084+
BUG_ON(th->t_refcount < 2);
3085+
30903086
return th;
30913087
}
30923088
th = kmalloc(sizeof(struct reiserfs_transaction_handle), GFP_NOFS);
@@ -3126,9 +3122,7 @@ static int journal_join(struct reiserfs_transaction_handle *th,
31263122
** pointer
31273123
*/
31283124
th->t_handle_save = cur_th;
3129-
if (cur_th && cur_th->t_refcount > 1) {
3130-
BUG();
3131-
}
3125+
BUG_ON(cur_th && cur_th->t_refcount > 1);
31323126
return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_JOIN);
31333127
}
31343128

@@ -3141,9 +3135,7 @@ int journal_join_abort(struct reiserfs_transaction_handle *th,
31413135
** pointer
31423136
*/
31433137
th->t_handle_save = cur_th;
3144-
if (cur_th && cur_th->t_refcount > 1) {
3145-
BUG();
3146-
}
3138+
BUG_ON(cur_th && cur_th->t_refcount > 1);
31473139
return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_ABORT);
31483140
}
31493141

@@ -3178,8 +3170,7 @@ int journal_begin(struct reiserfs_transaction_handle *th,
31783170
current->journal_info = th;
31793171
}
31803172
ret = do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_REG);
3181-
if (current->journal_info != th)
3182-
BUG();
3173+
BUG_ON(current->journal_info != th);
31833174

31843175
/* I guess this boils down to being the reciprocal of clm-2100 above.
31853176
* 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,
33243315
/* we aren't allowed to close a nested transaction on a different
33253316
** filesystem from the one in the task struct
33263317
*/
3327-
if (cur_th->t_super != th->t_super)
3328-
BUG();
3318+
BUG_ON(cur_th->t_super != th->t_super);
33293319

33303320
if (th != cur_th) {
33313321
memcpy(current->journal_info, th, sizeof(*th));
@@ -3444,9 +3434,7 @@ int journal_end_sync(struct reiserfs_transaction_handle *th,
34443434

34453435
BUG_ON(!th->t_trans_id);
34463436
/* you can sync while nested, very, very bad */
3447-
if (th->t_refcount > 1) {
3448-
BUG();
3449-
}
3437+
BUG_ON(th->t_refcount > 1);
34503438
if (journal->j_len == 0) {
34513439
reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb),
34523440
1);
@@ -3556,9 +3544,8 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
35563544
** will be dealt with by next transaction that actually writes something, but should be taken
35573545
** care of in this trans
35583546
*/
3559-
if (journal->j_len == 0) {
3560-
BUG();
3561-
}
3547+
BUG_ON(journal->j_len == 0);
3548+
35623549
/* if wcount > 0, and we are called to with flush or commit_now,
35633550
** we wait on j_join_wait. We will wake up when the last writer has
35643551
** 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,
35923579
unlock_journal(p_s_sb);
35933580
}
35943581
}
3595-
if (journal->j_trans_id == trans_id) {
3596-
BUG();
3597-
}
3582+
BUG_ON(journal->j_trans_id == trans_id);
3583+
35983584
if (commit_now
35993585
&& journal_list_still_alive(p_s_sb, trans_id)
36003586
&& wait_on_commit) {
@@ -4074,9 +4060,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
40744060
set_commit_trans_len(commit, journal->j_len);
40754061

40764062
/* special check in case all buffers in the journal were marked for not logging */
4077-
if (journal->j_len == 0) {
4078-
BUG();
4079-
}
4063+
BUG_ON(journal->j_len == 0);
40804064

40814065
/* we're about to dirty all the log blocks, mark the description block
40824066
* 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,
41734157
journal, jl, &jl->j_tail_bh_list);
41744158
lock_kernel();
41754159
}
4176-
if (!list_empty(&jl->j_tail_bh_list))
4177-
BUG();
4160+
BUG_ON(!list_empty(&jl->j_tail_bh_list));
41784161
up(&jl->j_commit_lock);
41794162

41804163
/* honor the flush wishes from the caller, simple commits can

‎fs/reiserfs/namei.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ inline void set_de_name_and_namelen(struct reiserfs_dir_entry *de)
6767
{
6868
struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
6969

70-
if (de->de_entry_num >= ih_entry_count(de->de_ih))
71-
BUG();
70+
BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
7271

7372
de->de_entrylen = entry_length(de->de_bh, de->de_ih, de->de_entry_num);
7473
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)
8079
// what entry points to
8180
static inline void set_de_object_key(struct reiserfs_dir_entry *de)
8281
{
83-
if (de->de_entry_num >= ih_entry_count(de->de_ih))
84-
BUG();
82+
BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
8583
de->de_dir_id = deh_dir_id(&(de->de_deh[de->de_entry_num]));
8684
de->de_objectid = deh_objectid(&(de->de_deh[de->de_entry_num]));
8785
}
@@ -90,8 +88,7 @@ static inline void store_de_entry_key(struct reiserfs_dir_entry *de)
9088
{
9189
struct reiserfs_de_head *deh = de->de_deh + de->de_entry_num;
9290

93-
if (de->de_entry_num >= ih_entry_count(de->de_ih))
94-
BUG();
91+
BUG_ON(de->de_entry_num >= ih_entry_count(de->de_ih));
9592

9693
/* store key of the found entry */
9794
de->de_entry_key.version = KEY_FORMAT_3_5;

‎fs/reiserfs/stree.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,7 @@ static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
14761476
int n_block_size = p_s_sb->s_blocksize;
14771477
int cut_bytes;
14781478
BUG_ON(!th->t_trans_id);
1479-
1480-
if (n_new_file_size != p_s_inode->i_size)
1481-
BUG();
1479+
BUG_ON(n_new_file_size != p_s_inode->i_size);
14821480

14831481
/* the page being sent in could be NULL if there was an i/o error
14841482
** reading in the last block. The user will hit problems trying to

0 commit comments

Comments
 (0)