From nobody Sun Feb 8 03:58:23 2026 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 4F24C1487F8 for ; Fri, 7 Feb 2025 09:45:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921523; cv=none; b=ALpqEAYEDji0vWPMplS+agMG+q86KA/S0FyjvlGIg6RFF+9jqqNNDckW4eg4dIj8dBacCXRkUYaIydS9VwHJQYD17os6nvB7m09QhMKQvPcW8DLDi5FRGFIKz+ewf3Fe3YgOiD/dE4S90AdRaPcVvdbL7vvvwwrwFLNg0hhNawk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738921523; c=relaxed/simple; bh=SBxVUvf4Lk+FMW1XRtCxhVkhaHQJW8kfh4xz0ojVHnw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QjWaX3YIY/mTUn/Rsavzj4hBnWyYvhqeBY7jPSaAhoBIOM66kvyahHiqWyP5B2lD2VbKTumMW+GJHaRW48S1FE3gtHnrXK0s0goiLikhv33c8Ho9x9kKqpteqQqoYA44Yarg3UB2WJT0pnG+UqZB9IgLdFszzz68KRMzaKJO8iU= 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=gvVXP67f; arc=none smtp.client-ip=115.124.30.110 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="gvVXP67f" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738921518; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=aTHN72xtRcyr6BkEOOv9TbB/8fJMYWIMeTR8LpKalDM=; b=gvVXP67fd1m2g363+9Le3McMW9W5h3nkTvEWB2p7Q109TvkuXHAU4WEJpjho4L4liMvkMy1xVv71VzcC1XX1bR+YThKe/txb/St/Qul1QoxeaRZc6tpbLlK5D34PagXkcd5Yn+m4hNFj/xYiujFk8EaLGZgiq0M4UOnc7ESrzLc= Received: from localhost(mailfrom:hongzhen@linux.alibaba.com fp:SMTPD_---0WOz4p76_1738921517 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 17:45:18 +0800 From: Hongzhen Luo To: linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Hongzhen Luo Subject: [PATCH v4] erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches Date: Fri, 7 Feb 2025 17:45:15 +0800 Message-ID: <20250207094515.2589242-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 --- v4: Get rid of `goto err_bogus;`. 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 | 72 ++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 43 deletions(-) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 689437e99a5a..5a2bc4905f45 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -265,29 +265,26 @@ 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; + if (!lookback_distance) { + erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu", + lookback_distance, m->lcn, vi->nid); + DBG_BUGON(1); + return -EFSCORRUPTED; + } 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); return -EFSCORRUPTED; } =20 @@ -329,35 +326,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 +376,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 +440,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 +456,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