From nobody Sun Feb 8 12:57:55 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 665721A23BC for ; Fri, 7 Feb 2025 08:51:06 +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=1738918271; cv=none; b=CJYTJMnwwFGmHuPa141UnzK0S2S5GujJiUA4xzbdkjSx31AdFjzOI6jwYWDRbGWvETxwsn+f+4pSpAgvn6AVa+adxoxzguIN/2dhy5FbYe2h4EAHnDUTWbad3xaezvvbLrqnaO/SkGzmAcu5XpUhwp1SVlSaATeBDbtKWX1y+Do= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738918271; c=relaxed/simple; bh=JwObRK8+JZaLP9k38M1U14pOYZL6RhstCyR5Jyf5s1E=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Lqmi4+HLEp4prSr7FIdgG7RCJC6Au5YNuTSQlGtfqZrQ+G+9pfDp/lvSFihivvop4Uq6JEzctgKgcUDjYvbiZjM/1migg5LQF2tlnWRPxXMMyVeb4HIbW32s1xKUXnweD2RPvgJfljP5nQF+MJLJ4WjZ2h0kpuuuFAM3JjzI/UY= 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=xUhfNSgA; 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="xUhfNSgA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1738918258; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=yZdjiVBUZ7mHPELUSaxgUg9mN8uVVkOic27ntckAPiU=; b=xUhfNSgAcrhxrcZVW+ADDpB9tn1wN/BBOu7TA9jF3Uq/NUss249e5dpOynWE3QnHmQAA2STOtd/J3IKLgRhw4HVkQvPKA54hLx3biqYjG0qvqYbw7w7ugkdmiM6MfnRAKqExVqlalTxOXzr+S/2HK+QZffelQpPDaX19TtrzCbg= Received: from localhost(mailfrom:hongzhen@linux.alibaba.com fp:SMTPD_---0WOyyh9M_1738918257 cluster:ay36) by smtp.aliyun-inc.com; Fri, 07 Feb 2025 16:50:58 +0800 From: Hongzhen Luo To: linux-erofs@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Hongzhen Luo Subject: [PATCH v3] erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches Date: Fri, 7 Feb 2025 16:50:56 +0800 Message-ID: <20250207085056.2502010-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 --- v3: Code cleanup, remove logically inequivalent changes. 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 | 60 +++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 689437e99a5a..7dba1573498b 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -265,23 +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 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; 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: @@ -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