erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches
PATCH v3 1/1 erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches
There's no need to enumerate each type. No logic changes.
---
v3: Code cleanup, remove logically inequivalent changes.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
--- fs/erofs/zmap.c | 60 +++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 37 deletions(-)
fs/erofs/zmap.c +23 -37
@@ -265,23 +265,20 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,if (err)return err; -switch (m->type) { -case Z_EROFS_LCLUSTER_TYPE_NONHEAD : +if (m->type >=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 ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ) { lookback_distance = 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 = m->type; m->map->m_la = (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 == initial_lcn && m->type ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ); -switch (m->type) { -case Z_EROFS_LCLUSTER_TYPE_PLAIN : -case Z_EROFS_LCLUSTER_TYPE_HEAD1 : -case Z_EROFS_LCLUSTER_TYPE_HEAD2 : +if (m->type ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ) { +if (m->delta[0 ] !=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 =1 ; -break ; -case Z_EROFS_LCLUSTER_TYPE_NONHEAD : -if (m->delta[0 ] !=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 =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 ; }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 ] =1 ;DBG_BUGON (1 ); } - }else if (m->type ==Z_EROFS_LCLUSTER_TYPE_PLAIN || - m->type ==Z_EROFS_LCLUSTER_TYPE_HEAD1 || - m->type ==Z_EROFS_LCLUSTER_TYPE_HEAD2 ) { + }else if (m->type <Z_EROFS_LCLUSTER_TYPE_MAX ) {if (lcn != headlcn)break ;/* ends at the next HEAD lcluster */ m->delta[1 ] =1 ;
@@ -452,8 +440,7 @@ static int z_erofs_do_map_blocks(struct inode *inode, }/* m.lcn should be >= 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 = -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 = -EOPNOTSUPP ; goto unmap_out;
Signature · 1 line
2.43.5
Quoted 19 lines · Hongzhen Luo
There's no need to enumerate each type. No logic changes.
Signed-off-by Hongzhen Luo <[email protected]>---> v3: Code cleanup, remove logically inequivalent changes.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/--- fs/erofs/zmap.c | 60 +++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 37 deletions(-)fs/erofs/zmap.c +0
-1@@ -265,23 +265,20 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,if (err)return err; -switch (m->type) {
fs/erofs/zmap.c static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m, · line 276
Quoted 10 lines
fs/erofs/zmap.c +6
-1-case Z_EROFS_LCLUSTER_TYPE_NONHEAD : +if (m->type >=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 ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ) { lookback_distance = m->delta[0 ];if (!lookback_distance) goto err_bogus;'
Maybe just kill goto err_bogus; too, like:
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;
}Otherwise it looks good to me.
Thanks,
Gao Xiang
Quoted 41 lines · Gao Xiang
Quoted 28 lines · Hongzhen Luo
There's no need to enumerate each type. No logic changes.
Signed-off-by Hongzhen Luo <[email protected]>---> v3: Code cleanup, remove logically inequivalent changes.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
---
fs/erofs/zmap.c| 60 +++++++++++++++++++------------------------------1 file changed, 23 insertions(+), 37 deletions(-)fs/erofs/zmap.c +6
-1@@ -265,23 +265,20 @@ static int z_erofs_extent_lookback(structz_erofs_maprecorder *m, if (err) return err; - switch (m->type) { - case Z_EROFS_LCLUSTER_TYPE_NONHEAD: + if (m->type >= 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 == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { lookback_distance = m->delta[0]; if (!lookback_distance)Quoted 1 line
goto
err_bogus;'Maybe just kill
goto err_bogus;too, like:
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;
}
Quoted 4 lines
Otherwise it looks good to me.
Thanks,
Gao Xiang
Sure, I will send an updated version later.
Thanks,
Hongzhen
Quoted 40 lines · Gao Xiang
Quoted 27 lines · Hongzhen Luo
There's no need to enumerate each type. No logic changes.
Signed-off-by Hongzhen Luo <[email protected]>---> v3: Code cleanup, remove logically inequivalent changes.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
---
fs/erofs/zmap.c| 60 +++++++++++++++++++------------------------------1 file changed, 23 insertions(+), 37 deletions(-)fs/erofs/zmap.c +6
-2@@ -265,23 +265,20 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m, if (err) return err; - switch (m->type) { - case Z_EROFS_LCLUSTER_TYPE_NONHEAD: + if (m->type >= 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 == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { lookback_distance = m->delta[0]; if (!lookback_distance)Quoted 1 line
goto
err_bogus;'Maybe just kill
goto err_bogus;too, like:
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;
}
Quoted 1 line
Otherwise it looks good to me.
Sorry, I was wrong. I was missing the part of the end of function, how about the following diff?
fs/erofs/zmap.c +1 -2
@@ -273,7 +273,7 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m, }else if (m->type ==Z_EROFS_LCLUSTER_TYPE_NONHEAD ) { lookback_distance = m->delta[0 ];if (!lookback_distance) - goto err_bogus; +break ;continue ; }else { m->headtype = m->type;
@@ -281,7 +281,6 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m,return 0 ; } } -err_bogus:erofs_err (sb,"bogus lookback distance %u @ lcn %lu of nid %llu" , lookback_distance, m->lcn, vi->nid);DBG_BUGON (1 );
Thanks,
Gao Xiang
Quoted 74 lines · Gao Xiang
Quoted 42 lines · Gao Xiang
Quoted 29 lines · Hongzhen Luo
There's no need to enumerate each type. No logic changes.
Signed-off-by Hongzhen Luo <[email protected]>---> v3: Code cleanup, remove logically inequivalent changes.
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/
---
fs/erofs/zmap.c| 60
+++++++++++++++++++------------------------------1 file changed, 23 insertions(+), 37 deletions(-)fs/erofs/zmap.c +6
-2@@ -265,23 +265,20 @@ static int z_erofs_extent_lookback(structz_erofs_maprecorder *m, if (err) return err; - switch (m->type) { - case Z_EROFS_LCLUSTER_TYPE_NONHEAD: + if (m->type >= 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 == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { lookback_distance = m->delta[0]; if (!lookback_distance)Quoted 1 line
goto
err_bogus;'Maybe just kill
goto err_bogus;too, like:
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;
}Quoted 1 line
Otherwise it looks good to me.
Sorry, I was wrong. I was missing the part of the end of function, how about the following diff?
fs/erofs/zmap.c +1
-1@@ -273,7 +273,7 @@ static int z_erofs_extent_lookback(structz_erofs_maprecorder *m, } else if (m->type == Z_EROFS_LCLUSTER_TYPE_NONHEAD) { lookback_distance = m->delta[0]; if (!lookback_distance) - goto err_bogus; + break; continue; } else {
m->headtype=m->type;fs/erofs/zmap.c +0
-1@@ -281,7 +281,6 @@ static int z_erofs_extent_lookback(struct z_erofs_maprecorder *m, return 0; } } -err_bogus: erofs_err(sb, "bogus lookback distance %u @ lcn %lu of nid %llu", lookback_distance, m->lcn, vi->nid);
DBG_BUGON(1);
Quoted 2 lines
Thanks,
Gao Xiang
Sure, I will send an updated version later.
Thanks,
Hongzhen Luo