Skip to content

Commit 2d8c7ed

Browse files
committed
erofs: unify lcn as u64 for 32-bit platforms
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 <[email protected]>
1 parent c99493c commit 2d8c7ed

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, in_mbox;
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
if (!lookback_distance)
@@ -286,7 +285,7 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
286285
m->map->m_la = (lcn << lclusterbits) | m->clusterofs;
287286
return 0;
288287
}
289-
erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu",
288+
erofs_err(sb, "bogus lookback distance %u @ lcn %llu of nid %llu",
290289
lookback_distance, m->lcn, vi->nid);
291290
DBG_BUGON(1);
292291
return -EFSCORRUPTED;
@@ -300,7 +299,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
300299
struct erofs_inode *vi = EROFS_I(inode);
301300
bool bigpcl1 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
302301
bool bigpcl2 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2;
303-
unsigned long lcn = m->lcn + 1;
302+
u64 lcn = m->lcn + 1;
304303
int err;
305304

306305
DBG_BUGON(m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD);
@@ -331,7 +330,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
331330
m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD);
332331

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

0 commit comments

Comments
 (0)