Commit 2d8c7edc authored by Gao Xiang's avatar Gao Xiang
Browse files

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: 152a333a ("staging: erofs: add compacted compression indexes support")
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent c99493ce
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
struct z_erofs_maprecorder {
	struct inode *inode;
	struct erofs_map_blocks *map;
	unsigned long lcn;
	u64 lcn;
	/* compression extent information gathered */
	u8  type, headtype;
	u16 clusterofs;
@@ -20,8 +20,7 @@ struct z_erofs_maprecorder {
	bool partialref, in_mbox;
};

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

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

static int z_erofs_load_lcluster_from_disk(struct z_erofs_maprecorder *m,
					   unsigned int lcn, bool lookahead)
					   u64 lcn, bool lookahead)
{
	struct erofs_inode *vi = EROFS_I(m->inode);
	int err;
@@ -249,7 +248,7 @@ static int z_erofs_load_lcluster_from_disk(struct z_erofs_maprecorder *m,
		return err;

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

	while (m->lcn >= lookback_distance) {
		unsigned long lcn = m->lcn - lookback_distance;
		u64 lcn = m->lcn - lookback_distance;
		int err;

		if (!lookback_distance)
@@ -286,7 +285,7 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,
		m->map->m_la = (lcn << lclusterbits) | m->clusterofs;
		return 0;
	}
	erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu",
	erofs_err(sb, "bogus lookback distance %u @ lcn %llu of nid %llu",
		  lookback_distance, m->lcn, vi->nid);
	DBG_BUGON(1);
	return -EFSCORRUPTED;
@@ -300,7 +299,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
	struct erofs_inode *vi = EROFS_I(inode);
	bool bigpcl1 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1;
	bool bigpcl2 = vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2;
	unsigned long lcn = m->lcn + 1;
	u64 lcn = m->lcn + 1;
	int err;

	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,
		  m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD);

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