<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 2025/2/7 15:33, Hongbo Li wrote:<br>
</div>
<blockquote type="cite"
cite="mid:7a9a2ead-88e5-4b53-9322-c649c92e73c2@huawei.com">
<br>
<br>
On 2025/2/7 14:41, Hongzhen Luo wrote:
<br>
<blockquote type="cite">There's no need to enumerate each type.
No logic changes.
<br>
<br>
Signed-off-by: Hongzhen Luo <a class="moz-txt-link-rfc2396E" href="mailto:hongzhen@linux.alibaba.com"><hongzhen@linux.alibaba.com></a>
<br>
---
<br>
fs/erofs/zmap.c | 59
++++++++++++++++++-------------------------------
<br>
1 file changed, 22 insertions(+), 37 deletions(-)
<br>
<br>
diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
<br>
index 689437e99a5a..0ee78413bfd5 100644
<br>
--- a/fs/erofs/zmap.c
<br>
+++ b/fs/erofs/zmap.c
<br>
@@ -265,24 +265,20 @@ static int z_erofs_extent_lookback(struct
z_erofs_maprecorder *m,
<br>
if (err)
<br>
return err;
<br>
- switch (m->type) {
<br>
- case Z_EROFS_LCLUSTER_TYPE_NONHEAD:
<br>
+ if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) {
<br>
lookback_distance = m->delta[0];
<br>
if (!lookback_distance)
<br>
goto err_bogus;
<br>
continue;
<br>
- case Z_EROFS_LCLUSTER_TYPE_PLAIN:
<br>
- case Z_EROFS_LCLUSTER_TYPE_HEAD1:
<br>
- case Z_EROFS_LCLUSTER_TYPE_HEAD2:
<br>
+ } else if (m->type < Z_EROFS_LCLUSTER_TYPE_MAX) {
<br>
m->headtype = m->type;
<br>
m->map->m_la = (lcn << lclusterbits) |
m->clusterofs;
<br>
return 0;
<br>
- default:
<br>
- erofs_err(sb, "unknown type %u @ lcn %lu of nid
%llu",
<br>
- m->type, lcn, vi->nid);
<br>
- DBG_BUGON(1);
<br>
- return -EOPNOTSUPP;
<br>
}
<br>
+ erofs_err(sb, "unknown type %u @ lcn %lu of nid %llu",
<br>
+ m->type, lcn, vi->nid);
<br>
+ DBG_BUGON(1);
<br>
+ return -EOPNOTSUPP;
<br>
</blockquote>
<br>
May be it would be easier to understand if you put the exception
branch at the beginning. Such as:
<br>
<br>
if (m->type >= Z_EROFS_LCLUSTER_TYPE_MAX) {
<br>
// return -EOPNOTSUPP;
<br>
}
<br>
<br>
if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) {
<br>
// do something
<br>
}
<br>
<br>
// do something for other cases..
<br>
<br>
This is also useful for other places. :)
<br>
<br>
Thanks,
<br>
Hongbo
<br>
<br>
</blockquote>
<p>Okay, I will send an improved version later.</p>
<p>Thanks,</p>
<p>Hongzhen<span
style="color: rgb(51, 51, 51); font-family: PingFangSC-Regular; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: pre-line; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">
</span></p>
<blockquote type="cite"
cite="mid:7a9a2ead-88e5-4b53-9322-c649c92e73c2@huawei.com">
<blockquote type="cite"> }
<br>
err_bogus:
<br>
erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid
%llu",
<br>
@@ -329,35 +325,28 @@ static int
z_erofs_get_extent_compressedlen(struct z_erofs_maprecorder *m,
<br>
DBG_BUGON(lcn == initial_lcn &&
<br>
m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD);
<br>
- switch (m->type) {
<br>
- case Z_EROFS_LCLUSTER_TYPE_PLAIN:
<br>
- case Z_EROFS_LCLUSTER_TYPE_HEAD1:
<br>
- case Z_EROFS_LCLUSTER_TYPE_HEAD2:
<br>
+ if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) {
<br>
+ if (m->delta[0] != 1) {
<br>
+ erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid
%llu", lcn, vi->nid);
<br>
+ DBG_BUGON(1);
<br>
+ return -EFSCORRUPTED;
<br>
+ }
<br>
+ if (m->compressedblks)
<br>
+ goto out;
<br>
+ } else if (m->type < Z_EROFS_LCLUSTER_TYPE_MAX) {
<br>
/*
<br>
* if the 1st NONHEAD lcluster is actually PLAIN or
HEAD type
<br>
* rather than CBLKCNT, it's a 1 block-sized pcluster.
<br>
*/
<br>
m->compressedblks = 1;
<br>
- break;
<br>
- case Z_EROFS_LCLUSTER_TYPE_NONHEAD:
<br>
- if (m->delta[0] != 1)
<br>
- goto err_bonus_cblkcnt;
<br>
- if (m->compressedblks)
<br>
- break;
<br>
- fallthrough;
<br>
- default:
<br>
- erofs_err(sb, "cannot found CBLKCNT @ lcn %lu of nid
%llu", lcn,
<br>
- vi->nid);
<br>
- DBG_BUGON(1);
<br>
- return -EFSCORRUPTED;
<br>
+ goto out;
<br>
}
<br>
+ erofs_err(sb, "cannot found CBLKCNT @ lcn %lu of nid %llu",
lcn, vi->nid);
<br>
+ DBG_BUGON(1);
<br>
+ return -EFSCORRUPTED;
<br>
out:
<br>
m->map->m_plen = erofs_pos(sb,
m->compressedblks);
<br>
return 0;
<br>
-err_bonus_cblkcnt:
<br>
- erofs_err(sb, "bogus CBLKCNT @ lcn %lu of nid %llu", lcn,
vi->nid);
<br>
- DBG_BUGON(1);
<br>
- return -EFSCORRUPTED;
<br>
}
<br>
static int z_erofs_get_extent_decompressedlen(struct
z_erofs_maprecorder *m)
<br>
@@ -386,9 +375,7 @@ static int
z_erofs_get_extent_decompressedlen(struct z_erofs_maprecorder
*m)
<br>
m->delta[1] = 1;
<br>
DBG_BUGON(1);
<br>
}
<br>
- } else if (m->type == Z_EROFS_LCLUSTER_TYPE_PLAIN ||
<br>
- m->type == Z_EROFS_LCLUSTER_TYPE_HEAD1 ||
<br>
- m->type == Z_EROFS_LCLUSTER_TYPE_HEAD2) {
<br>
+ } else if (m->type < Z_EROFS_LCLUSTER_TYPE_MAX) {
<br>
if (lcn != headlcn)
<br>
break; /* ends at the next HEAD lcluster */
<br>
m->delta[1] = 1;
<br>
@@ -452,8 +439,7 @@ static int z_erofs_do_map_blocks(struct
inode *inode,
<br>
}
<br>
/* m.lcn should be >= 1 if endoff < m.clusterofs
*/
<br>
if (!m.lcn) {
<br>
- erofs_err(inode->i_sb,
<br>
- "invalid logical cluster 0 at nid %llu",
<br>
+ erofs_err(inode->i_sb, "invalid logical cluster
0 at nid %llu",
<br>
vi->nid);
<br>
err = -EFSCORRUPTED;
<br>
goto unmap_out;
<br>
@@ -469,8 +455,7 @@ static int z_erofs_do_map_blocks(struct
inode *inode,
<br>
goto unmap_out;
<br>
break;
<br>
default:
<br>
- erofs_err(inode->i_sb,
<br>
- "unknown type %u @ offset %llu of nid %llu",
<br>
+ erofs_err(inode->i_sb, "unknown type %u @ offset
%llu of nid %llu",
<br>
m.type, ofs, vi->nid);
<br>
err = -EOPNOTSUPP;
<br>
goto unmap_out;
<br>
</blockquote>
</blockquote>
</body>
</html>