Skip to content

Commit 4afe6b8

Browse files
Al Virohsiangkao
authored andcommitted
erofs: don't round offset down for erofs_read_metabuf()
There's only one place where struct z_erofs_maprecorder ->kaddr is used not in the same function that has assigned it - the value read in unpack_compacted_index() gets calculated in z_erofs_load_compact_lcluster(). With minor massage we can switch to storing it with offset in block already added. Signed-off-by: Al Viro <[email protected]> Link: https://lore.kernel.org/r/20240425195944.GE1031757@ZenIV Signed-off-by: Gao Xiang <[email protected]>
1 parent 076d965 commit 4afe6b8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

fs/erofs/zmap.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
3434
unsigned int advise;
3535

3636
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
37-
erofs_pos(inode->i_sb, erofs_blknr(inode->i_sb, pos)), EROFS_KMAP);
37+
pos, EROFS_KMAP);
3838
if (IS_ERR(m->kaddr))
3939
return PTR_ERR(m->kaddr);
4040

4141
m->nextpackoff = pos + sizeof(struct z_erofs_lcluster_index);
4242
m->lcn = lcn;
43-
di = m->kaddr + erofs_blkoff(inode->i_sb, pos);
43+
di = m->kaddr;
4444

4545
advise = le16_to_cpu(di->di_advise);
4646
m->type = advise & Z_EROFS_LI_LCLUSTER_TYPE_MASK;
@@ -109,7 +109,7 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
109109
{
110110
struct erofs_inode *const vi = EROFS_I(m->inode);
111111
const unsigned int lclusterbits = vi->z_logical_clusterbits;
112-
unsigned int vcnt, base, lo, lobits, encodebits, nblk, eofs;
112+
unsigned int vcnt, lo, lobits, encodebits, nblk, bytes;
113113
int i;
114114
u8 *in, type;
115115
bool big_pcluster;
@@ -127,11 +127,11 @@ static int unpack_compacted_index(struct z_erofs_maprecorder *m,
127127
big_pcluster = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
128128
lobits = max(lclusterbits, ilog2(Z_EROFS_LI_D0_CBLKCNT) + 1U);
129129
encodebits = ((vcnt << amortizedshift) - sizeof(__le32)) * 8 / vcnt;
130-
eofs = erofs_blkoff(m->inode->i_sb, pos);
131-
base = round_down(eofs, vcnt << amortizedshift);
132-
in = m->kaddr + base;
130+
bytes = pos & ((vcnt << amortizedshift) - 1);
133131

134-
i = (eofs - base) >> amortizedshift;
132+
in = m->kaddr - bytes;
133+
134+
i = bytes >> amortizedshift;
135135

136136
lo = decode_compactedbits(lobits, in, encodebits * i, &type);
137137
m->type = type;
@@ -256,7 +256,7 @@ static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
256256
out:
257257
pos += lcn * (1 << amortizedshift);
258258
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
259-
erofs_pos(inode->i_sb, erofs_blknr(inode->i_sb, pos)), EROFS_KMAP);
259+
pos, EROFS_KMAP);
260260
if (IS_ERR(m->kaddr))
261261
return PTR_ERR(m->kaddr);
262262
return unpack_compacted_index(m, amortizedshift, pos, lookahead);

0 commit comments

Comments
 (0)