From nobody Sun Feb 8 04:34:38 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 529E1183CB0 for ; Fri, 7 Feb 2025 06:41:39 +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=1738910504; cv=none; b=GqvmTuqwq4oHqDIFUSBIxHVcAs5Zo10mbUXG8Ciqtdw+572Z1moBClLOl5GHb8fpvuE4vXNjcAyVVoKusm1pVR/sJABNZ01jj4HE7yi+5BV+jQIVcAV6QYUFUSCPBsLzyehbjErftkoJ1gZYSQFM8O3f5xT+JoBgpzelYB5Ql+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738910504; c=relaxed/simple; bh=/BS7cxjaHruryBsiD9GwbNvNG7PmDSNRASffx/F9y0s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=R+7EbschEgy0X/ZhvGmtVtYFF2J8VgGgwPlzUJiDvjvwCrkQ0MhMhYQ/Ym3kUpMbcMSAZvaAge/4YWlTPC1WXvkzmqxGWQG2JFGt6Xh0Xd19YYaCJbtjWd3dwvF8931QkcafUWTwsKRy51FaWShsrwqcGSAn1uYrZZ/Xu7KrKRg= 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=KjXSDsCB; 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="KjXSDsCB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738910497; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=IckZPfDGFvE/+XKynooSNpFYbiDfWKFfsthqL+N1SNQ=; b=KjXSDsCBGT2QI9KXyJAo5VKsiAkBl5JmPUrrGHP/CgJQFn3en3kzq+rmxChsH5WawXFBuk29GKePTvPIt4tjtBRwQfdj3ZskfFghlr0sssDy/sQpEVjeTG6rmV/lu3SFdLF64WVB/ZlOW8C2Ej6sN+HPCDhNm/3afpFA99iZvsQ= Received: from localhost(mailfrom:hongzhen@linux.alibaba.com fp:SMTPD_---0WOySS0b_1738910496 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 14:41:36 +0800 From: Hongzhen Luo To: linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Hongzhen Luo Subject: [PATCH RESEND] erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches Date: Fri, 7 Feb 2025 14:41:35 +0800 Message-ID: <20250207064135.2249529-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 --- fs/erofs/zmap.c | 59 ++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 689437e99a5a..0ee78413bfd5 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -265,24 +265,20 @@ 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=3D Z_EROFS_LCLUSTER_TYPE_NONHEAD) { lookback_distance =3D m->delta[0]; if (!lookback_distance) goto err_bogus; continue; - case Z_EROFS_LCLUSTER_TYPE_PLAIN: - case Z_EROFS_LCLUSTER_TYPE_HEAD1: - case Z_EROFS_LCLUSTER_TYPE_HEAD2: + } else if (m->type < Z_EROFS_LCLUSTER_TYPE_MAX) { 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; } + 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", @@ -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