Skip to content

Commit 4fc9b12

Browse files
hsiangkaogregkh
authored andcommitted
erofs: unify lcn as u64 for 32-bit platforms
[ Upstream commit 2d8c7ed ] As sashiko reported [1], `lcn` was typed as `unsigned long` (or `unsigned int` sometimes), which is only 32 bits wide on 32-bit platforms, which causes `(lcn << lclusterbits)` to be truncated at 4 GiB. In order to consolidate the logic, just use `u64` consistently around the codebase. [1] https://sashiko.dev/r/20260420034612.1899973-1-hsiangkao%40linux.alibaba.com Fixes: 152a333 ("staging: erofs: add compacted compression indexes support") Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent dbfac1b commit 4fc9b12

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

fs/erofs/zmap.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
struct z_erofs_maprecorder {
1111
struct inode *inode;
1212
struct erofs_map_blocks *map;
13-
unsigned long lcn;
13+
u64 lcn;
1414
/* compression extent information gathered */
1515
u8 type, headtype;
1616
u16 clusterofs;
@@ -20,8 +20,7 @@ struct z_erofs_maprecorder {
2020
bool partialref;
2121
};
2222

23-
static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m,
24-
unsigned long lcn)
23+
static int z_erofs_load_full_lcluster(struct z_erofs_maprecorder *m, u64 lcn)
2524
{
2625
struct inode *const inode = m->inode;
2726
struct erofs_inode *const vi = EROFS_I(inode);
@@ -94,7 +93,7 @@ static int get_compacted_la_distance(unsigned int lobits,
9493
}
9594

9695
static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
97-
unsigned long lcn, bool lookahead)
96+
u64 lcn, bool lookahead)
9897
{
9998
struct inode *const inode = m->inode;
10099
struct erofs_inode *const vi = EROFS_I(inode);
@@ -234,7 +233,7 @@ static int z_erofs_load_compact_lcluster(struct z_erofs_maprecorder *m,
234233
}
235234

236235
static int z_erofs_load_lcluster_from_disk(struct z_erofs_maprecorder *m,
237-
unsigned int lcn, bool lookahead)
236+
u64 lcn, bool lookahead)
238237
{
239238
struct erofs_inode *vi = EROFS_I(m->inode);
240239
int err;
@@ -249,7 +248,7 @@ static int z_erofs_load_lcluster_from_disk(struct z_erofs_maprecorder *m,
249248
return err;
250249

251250
if (m->type >= Z_EROFS_LCLUSTER_TYPE_MAX) {
252-
erofs_err(m->inode->i_sb, "unknown type %u @ lcn %u of nid %llu",
251+
erofs_err(m->inode->i_sb, "unknown type %u @ lcn %llu of nid %llu",
253252
m->type, lcn, EROFS_I(m->inode)->nid);
254253
DBG_BUGON(1);
255254
return -EOPNOTSUPP;
@@ -269,7 +268,7 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
269268
const unsigned int lclusterbits = vi->z_lclusterbits;
270269

271270
while (m->lcn >= lookback_distance) {
272-
unsigned long lcn = m->lcn - lookback_distance;
271+
u64 lcn = m->lcn - lookback_distance;
273272
int err;
274273

275274
err = z_erofs_load_lcluster_from_disk(m, lcn, false);
@@ -287,7 +286,7 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
287286
return 0;
288287
}
289288
}
290-
erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu",
289+
erofs_err(sb, "bogus lookback distance %u @ lcn %llu of nid %llu",
291290
lookback_distance, m->lcn, vi->nid);
292291
DBG_BUGON(1);
293292
return -EFSCORRUPTED;
@@ -301,7 +300,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
301300
struct erofs_inode *vi = EROFS_I(inode);
302301
bool bigpcl1 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
303302
bool bigpcl2 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2;
304-
unsigned long lcn = m->lcn + 1;
303+
u64 lcn = m->lcn + 1;
305304
int err;
306305

307306
DBG_BUGON(m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD);
@@ -332,7 +331,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
332331
m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD);
333332

334333
if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD && m->delta[0] != 1) {
335-
erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid);
334+
erofs_err(sb, "bogus CBLKCNT @ lcn %llu of nid %llu", lcn, vi->nid);
336335
DBG_BUGON(1);
337336
return -EFSCORRUPTED;
338337
}

0 commit comments

Comments
 (0)