From nobody Sun Feb 8 04:34:23 2026 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92E6D6F06B for ; Mon, 10 Feb 2025 03:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739158177; cv=none; b=t+cZO7HCP9agAbOhk8R7v1xRzljqlJQkH+0mf9FbB+rFmDXoajDPekr1Ak2VLA8j+3JzfQjpfbHgS150wlaICrI86/WcOtyRvQ2iG1j/qa8xDEUJK+04JdSoOWXfZf4H8sCWR3ADOUBIZYDVDN8LWELGgCM5RH+Wfl7TJqd1zys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739158177; c=relaxed/simple; bh=FGe1i00oMMoyENbUPkT+/JG/6yjI7Mn9OUDh07mlOE0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=E1yWAzSKrKlFNJVv8vcEGWIgEMkUiYuhyepCAaH4E2BVnPJhAeKd++3s0NDxnJBe++fpt5CUcC4t46V3ZylyCwURgwHl8BzFHEZNRSTrllJiZz726ZpVJEKQv3fYMRIEGlkpEeMqIvUGzKvXjl+AZDBHNkywwAam6TVf77DzsQI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=KMZzOjvI; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="KMZzOjvI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1739158165; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=Qs9PUV3rYLxbnto2T61Zi+jRgEogtBhw2UcQ6K27XWw=; b=KMZzOjvI7QGmdlnyoY3BcMvTybuWibo5CtHC9M4ThfzbmWXfBqWl+6+wYOQXPGWW4SVGcNuVLFXIDh/Qj3jE5FEqFLVYS87++dbt9TzkF0zch6s0Y5k/kGqzNOOR1fHF6yJM7Z2ntHcVnTUIz4GCFei9oOBdNwWrFn+/jcZ9kBM= Received: from localhost(mailfrom:hongzhen@linux.alibaba.com fp:SMTPD_---0WP4g7Xo_1739158164 cluster:ay36) by smtp.aliyun-inc.com; Mon, 10 Feb 2025 11:29:24 +0800 From: Hongzhen Luo To: linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Hongzhen Luo Subject: [PATCH v5] erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches Date: Mon, 10 Feb 2025 11:29:23 +0800 Message-ID: <20250210032923.3382136-1-hongzhen@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There's no need to enumerate each type. No logic changes. Signed-off-by: Hongzhen Luo Reviewed-by: Chao Yu Reviewed-by: Gao Xiang --- v5: Exit the loop and return EOPNOTSUPP when `!lookback_distance`. v4: https://lore.kernel.org/linux-erofs/20250207094515.2589242-1-hongzhen@l= inux.alibaba.com/ v3: https://lore.kernel.org/all/20250207085056.2502010-1-hongzhen@linux.ali= baba.com/ v2: https://lore.kernel.org/all/20250207080829.2405528-1-hongzhen@linux.ali= baba.com/ v1: https://lore.kernel.org/all/20250207064135.2249529-1-hongzhen@linux.ali= baba.com/ --- fs/erofs/zmap.c | 63 +++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 689437e99a5a..d278ebd60281 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -265,26 +265,22 @@ static int z_erofs_extent_lookback(struct z_erofs_map= recorder *m, if (err) return err; =20 - switch (m->type) { - case Z_EROFS_LCLUSTER_TYPE_NONHEAD: + if (m->type >=3D Z_EROFS_LCLUSTER_TYPE_MAX) { + erofs_err(sb, "unknown type %u @ lcn %lu of nid %llu", + m->type, lcn, vi->nid); + DBG_BUGON(1); + return -EOPNOTSUPP; + } else if (m->type =3D=3D Z_EROFS_LCLUSTER_TYPE_NONHEAD) { lookback_distance =3D m->delta[0]; if (!lookback_distance) - goto err_bogus; + break; continue; - case Z_EROFS_LCLUSTER_TYPE_PLAIN: - case Z_EROFS_LCLUSTER_TYPE_HEAD1: - case Z_EROFS_LCLUSTER_TYPE_HEAD2: + } else { m->headtype =3D m->type; m->map->m_la =3D (lcn << lclusterbits) | m->clusterofs; return 0; - default: - erofs_err(sb, "unknown type %u @ lcn %lu of nid %llu", - m->type, lcn, vi->nid); - DBG_BUGON(1); - return -EOPNOTSUPP; } } -err_bogus: erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu", lookback_distance, m->lcn, vi->nid); DBG_BUGON(1); @@ -329,35 +325,28 @@ static int z_erofs_get_extent_compressedlen(struct z_= erofs_maprecorder *m, DBG_BUGON(lcn =3D=3D initial_lcn && m->type =3D=3D Z_EROFS_LCLUSTER_TYPE_NONHEAD); =20 - switch (m->type) { - case Z_EROFS_LCLUSTER_TYPE_PLAIN: - case Z_EROFS_LCLUSTER_TYPE_HEAD1: - case Z_EROFS_LCLUSTER_TYPE_HEAD2: + if (m->type =3D=3D Z_EROFS_LCLUSTER_TYPE_NONHEAD) { + if (m->delta[0] !=3D 1) { + erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid); + DBG_BUGON(1); + return -EFSCORRUPTED; + } + if (m->compressedblks) + goto out; + } else if (m->type < Z_EROFS_LCLUSTER_TYPE_MAX) { /* * if the 1st NONHEAD lcluster is actually PLAIN or HEAD type * rather than CBLKCNT, it's a 1 block-sized pcluster. */ m->compressedblks =3D 1; - break; - case Z_EROFS_LCLUSTER_TYPE_NONHEAD: - if (m->delta[0] !=3D 1) - goto err_bonus_cblkcnt; - if (m->compressedblks) - break; - fallthrough; - default: - erofs_err(sb, "cannot found CBLKCNT @ lcn %lu of nid %llu", lcn, - vi->nid); - DBG_BUGON(1); - return -EFSCORRUPTED; + goto out; } + erofs_err(sb, "cannot found CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid); + DBG_BUGON(1); + return -EFSCORRUPTED; out: m->map->m_plen =3D erofs_pos(sb, m->compressedblks); return 0; -err_bonus_cblkcnt: - erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid); - DBG_BUGON(1); - return -EFSCORRUPTED; } =20 static int z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder *= m) @@ -386,9 +375,7 @@ static int z_erofs_get_extent_decompressedlen(struct z_= erofs_maprecorder *m) m->delta[1] =3D 1; DBG_BUGON(1); } - } else if (m->type =3D=3D Z_EROFS_LCLUSTER_TYPE_PLAIN || - m->type =3D=3D Z_EROFS_LCLUSTER_TYPE_HEAD1 || - m->type =3D=3D Z_EROFS_LCLUSTER_TYPE_HEAD2) { + } else if (m->type < Z_EROFS_LCLUSTER_TYPE_MAX) { if (lcn !=3D headlcn) break; /* ends at the next HEAD lcluster */ m->delta[1] =3D 1; @@ -452,8 +439,7 @@ static int z_erofs_do_map_blocks(struct inode *inode, } /* m.lcn should be >=3D 1 if endoff < m.clusterofs */ if (!m.lcn) { - erofs_err(inode->i_sb, - "invalid logical cluster 0 at nid %llu", + erofs_err(inode->i_sb, "invalid logical cluster 0 at nid %llu", vi->nid); err =3D -EFSCORRUPTED; goto unmap_out; @@ -469,8 +455,7 @@ static int z_erofs_do_map_blocks(struct inode *inode, goto unmap_out; break; default: - erofs_err(inode->i_sb, - "unknown type %u @ offset %llu of nid %llu", + erofs_err(inode->i_sb, "unknown type %u @ offset %llu of nid %llu", m.type, ofs, vi->nid); err =3D -EOPNOTSUPP; goto unmap_out; --=20 2.43.5