From nobody Sun Feb 8 10:29:43 2026 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 91F921547CA for ; Fri, 7 Feb 2025 08:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738916033; cv=none; b=uhZy20d1M87kWHuLJXFis1HCvaHcE9cUeKYJWSHMnpRd0bwZJYM89UoV6cFmyQdPmXSHQ9uhPHwoBAwQJzQSEQ7Pup72B7q9vYJ+p8YGqZyowlXGp8PTG59TBGcdj4cs9eD/zdFZqr4ErazthvTgg3XeLfNwQvF+xeah2YnXUGQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738916033; c=relaxed/simple; bh=1d979SMpTvfaQYObS7fA8SQtXquqn1pvuecnqSzawEw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JmPnnFZNpe9C4A/I9GkHCylml9Kx4ATcwQcL8vY6GbAzzn+dMf4AIJfpqBkbje/TufMr8Z9N6siwOdjg07KQymH11ahOY2We/U7b4BSeT3GUjxB5CkTvDMCa1O4Q6q48Lwvs75LxP3rnK5QNChiBJmoyJXWLOnVjdl5jcZHatHs= 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=LGx5E8gU; arc=none smtp.client-ip=115.124.30.113 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="LGx5E8gU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738916027; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=roiWbo9CpskJmB7RUqO3TURA636FBHMLgNiNyGc+Dr0=; b=LGx5E8gUAFrdDsb76gsucAkJxBroLwfYvej27Cwxrv7isep4FAB1UoqiHLS34QkX0JSrKdvVWqDfe3sNDd8wkXnc2/n65Dsuz4S9Od+V7pOBbQ3iPQ4vg9GJmllrFISbMM237Wdo4hs+UFUBR0qf/rUz61O/rFVdEBkCm+ncR0o= Received: from localhost(mailfrom:hongzhen@linux.alibaba.com fp:SMTPD_---0WOylSQ5_1738915710 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 16:08:30 +0800 From: Hongzhen Luo To: linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Hongzhen Luo Subject: [PATCH v2] erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches Date: Fri, 7 Feb 2025 16:08:29 +0800 Message-ID: <20250207080829.2405528-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 --- Changes since v1: Put the exception branch at the beginning. v1: https://lore.kernel.org/all/20250207064135.2249529-1-hongzhen@linux.ali= baba.com/ --- fs/erofs/zmap.c | 65 +++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 689437e99a5a..f65c76991e02 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -265,23 +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; + } + + 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; } } err_bogus: @@ -329,35 +328,31 @@ 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 Z_EROFS_LCLUSTER_TYPE_MAX) { + erofs_err(sb, "cannot found CBLKCNT @ lcn %lu of nid %llu", lcn, vi->nid= ); + DBG_BUGON(1); + return -EFSCORRUPTED; + } + + 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; } 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 +381,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 +445,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 +461,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