Skip to content

Commit 3ee3039

Browse files
committed
udf: Reduce repeated dereferences
Replace repeated dereferences like dir->i_sb by storing superblock pointer in a variable and using that. Signed-off-by: Jan Kara <jack@suse.cz>
1 parent e237ec3 commit 3ee3039

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

‎fs/udf/dir.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
5757
sector_t offset;
5858
int i, num, ret = 0;
5959
struct extent_position epos = { NULL, 0, {0, 0} };
60+
struct super_block *sb = dir->i_sb;
6061

6162
if (ctx->pos == 0) {
6263
if (!dir_emit_dot(file, ctx))
@@ -76,16 +77,16 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
7677
if (nf_pos == 0)
7778
nf_pos = udf_ext0_offset(dir);
7879

79-
fibh.soffset = fibh.eoffset = nf_pos & (dir->i_sb->s_blocksize - 1);
80+
fibh.soffset = fibh.eoffset = nf_pos & (sb->s_blocksize - 1);
8081
if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
81-
if (inode_bmap(dir, nf_pos >> dir->i_sb->s_blocksize_bits,
82+
if (inode_bmap(dir, nf_pos >> sb->s_blocksize_bits,
8283
&epos, &eloc, &elen, &offset)
8384
!= (EXT_RECORDED_ALLOCATED >> 30)) {
8485
ret = -ENOENT;
8586
goto out;
8687
}
87-
block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
88-
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
88+
block = udf_get_lb_pblock(sb, &eloc, offset);
89+
if ((++offset << sb->s_blocksize_bits) < elen) {
8990
if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
9091
epos.offset -= sizeof(struct short_ad);
9192
else if (iinfo->i_alloc_type ==
@@ -95,18 +96,18 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
9596
offset = 0;
9697
}
9798

98-
if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) {
99+
if (!(fibh.sbh = fibh.ebh = udf_tread(sb, block))) {
99100
ret = -EIO;
100101
goto out;
101102
}
102103

103-
if (!(offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) {
104-
i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
105-
if (i + offset > (elen >> dir->i_sb->s_blocksize_bits))
106-
i = (elen >> dir->i_sb->s_blocksize_bits) - offset;
104+
if (!(offset & ((16 >> (sb->s_blocksize_bits - 9)) - 1))) {
105+
i = 16 >> (sb->s_blocksize_bits - 9);
106+
if (i + offset > (elen >> sb->s_blocksize_bits))
107+
i = (elen >> sb->s_blocksize_bits) - offset;
107108
for (num = 0; i > 0; i--) {
108-
block = udf_get_lb_pblock(dir->i_sb, &eloc, offset + i);
109-
tmp = udf_tgetblk(dir->i_sb, block);
109+
block = udf_get_lb_pblock(sb, &eloc, offset + i);
110+
tmp = udf_tgetblk(sb, block);
110111
if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
111112
bha[num++] = tmp;
112113
else
@@ -152,12 +153,12 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
152153
}
153154

154155
if ((cfi.fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
155-
if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
156+
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
156157
continue;
157158
}
158159

159160
if ((cfi.fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
160-
if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
161+
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
161162
continue;
162163
}
163164

@@ -167,13 +168,12 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
167168
continue;
168169
}
169170

170-
flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
171-
UDF_NAME_LEN);
171+
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
172172
if (!flen)
173173
continue;
174174

175175
tloc = lelb_to_cpu(cfi.icb.extLocation);
176-
iblock = udf_get_lb_pblock(dir->i_sb, &tloc, 0);
176+
iblock = udf_get_lb_pblock(sb, &tloc, 0);
177177
if (!dir_emit(ctx, fname, flen, iblock, DT_UNKNOWN))
178178
goto out;
179179
} /* end while */

‎fs/udf/namei.c‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,26 +159,27 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
159159
struct udf_inode_info *dinfo = UDF_I(dir);
160160
int isdotdot = child->len == 2 &&
161161
child->name[0] == '.' && child->name[1] == '.';
162+
struct super_block *sb = dir->i_sb;
162163

163164
size = udf_ext0_offset(dir) + dir->i_size;
164165
f_pos = udf_ext0_offset(dir);
165166

166167
fibh->sbh = fibh->ebh = NULL;
167-
fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
168+
fibh->soffset = fibh->eoffset = f_pos & (sb->s_blocksize - 1);
168169
if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
169-
if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits, &epos,
170+
if (inode_bmap(dir, f_pos >> sb->s_blocksize_bits, &epos,
170171
&eloc, &elen, &offset) != (EXT_RECORDED_ALLOCATED >> 30))
171172
goto out_err;
172-
block = udf_get_lb_pblock(dir->i_sb, &eloc, offset);
173-
if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
173+
block = udf_get_lb_pblock(sb, &eloc, offset);
174+
if ((++offset << sb->s_blocksize_bits) < elen) {
174175
if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
175176
epos.offset -= sizeof(struct short_ad);
176177
else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
177178
epos.offset -= sizeof(struct long_ad);
178179
} else
179180
offset = 0;
180181

181-
fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
182+
fibh->sbh = fibh->ebh = udf_tread(sb, block);
182183
if (!fibh->sbh)
183184
goto out_err;
184185
}
@@ -217,12 +218,12 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
217218
}
218219

219220
if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
220-
if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNDELETE))
221+
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
221222
continue;
222223
}
223224

224225
if ((cfi->fileCharacteristics & FID_FILE_CHAR_HIDDEN) != 0) {
225-
if (!UDF_QUERY_FLAG(dir->i_sb, UDF_FLAG_UNHIDE))
226+
if (!UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
226227
continue;
227228
}
228229

@@ -233,8 +234,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
233234
if (!lfi)
234235
continue;
235236

236-
flen = udf_get_filename(dir->i_sb, nameptr, lfi, fname,
237-
UDF_NAME_LEN);
237+
flen = udf_get_filename(sb, nameptr, lfi, fname, UDF_NAME_LEN);
238238
if (flen && udf_match(flen, fname, child->len, child->name))
239239
goto out_ok;
240240
}

0 commit comments

Comments
 (0)