Skip to contentSkip to conversation

erofs: silence warnings related to impossible m_plen

PATCH In review Gao Xiang 2 participants 2 messages Mar 10, 2022 – Mar 11, 2022 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: silence warnings related to impossible m_plen

Dan reported two smatch warnings [1],
.. warn: should '1 << lclusterbits' be a 64 bit type?
.. warn: should 'm->compressedlcs << lclusterbits' be a 64 bit type?

In practice, m_plen cannot be more than 1MiB due to on-disk constraint for the compression mode, so we're always safe here.

In order to make static analyzers happy and don't report again, let's silence them instead.

[1] https://lore.kernel.org/r/[email protected]

---
 fs/erofs/zmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/erofs/zmap.c +2 -2
index 361b1d6e4bf9..b4059b9c3bac 100644
@@ -494,7 +494,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
 	     !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_1)) ||
 	    ((m->headtype == Z_EROFS_VLE_CLUSTER_TYPE_HEAD2) &&
 	     !(vi->z_advise & Z_EROFS_ADVISE_BIG_PCLUSTER_2))) {
-		map->m_plen = 1 << lclusterbits;
+		map->m_plen = 1ULL << lclusterbits;
 		return 0;
 	}
 	lcn = m->lcn + 1;
@@ -540,7 +540,7 @@ static int z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
 		return -EFSCORRUPTED;
 	}
 out:
-	map->m_plen = m->compressedlcs << lclusterbits;
+	map->m_plen = (u64)m->compressedlcs << lclusterbits;
 	return 0;
 err_bonus_cblkcnt:
 	erofs_err(m->inode->i_sb,
Signature · 1 line
2.24.4
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Gao Xiang

Dan reported two smatch warnings [1],
.. warn: should '1 << lclusterbits' be a 64 bit type?
.. warn: should 'm->compressedlcs << lclusterbits' be a 64 bit type?

In practice, m_plen cannot be more than 1MiB due to on-disk constraint for the compression mode, so we're always safe here.

Quoted 8 lines

In order to make static analyzers happy and don't report again, let's silence them instead.

[1] https://lore.kernel.org/r/[email protected]

Thanks,