Re: [PATCH v5] erofs: use Z_EROFS_LCLUSTER_TYPE_MAX to simplify switches
From: Chao Yu
Date: Mon Mar 17 2025 - 02:03:42 EST
On 3/17/25 01:17, Gao Xiang wrote:
> Hi Chao,
>
> On 2025/3/16 10:36, Chao Yu wrote:
>> On 2025/2/10 11:29, Hongzhen Luo wrote:
>>> There's no need to enumerate each type. No logic changes.
>>>
>>> Signed-off-by: Hongzhen Luo <hongzhen@xxxxxxxxxxxxxxxxx>
>>
>> Looks good to me, feel free to add:
>>
>> Reviewed-by: Chao Yu <chao@xxxxxxxxxx>
>>
>> And one minor comment below.
>>
>>> diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
>>> index 689437e99a5a..d278ebd60281 100644
>>> --- a/fs/erofs/zmap.c
>>> +++ b/fs/erofs/zmap.c
>>> @@ -265,26 +265,22 @@ 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;
>>> + break;
>>> 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;
>>
>> Should return EFSCORRUPTED here? is m->type >= Z_EROFS_LCLUSTER_TYPE_MAX a possible
>> case?
>
> It's impossible by the latest on-disk definition, see:
> #define Z_EROFS_LI_LCLUSTER_TYPE_MASK (Z_EROFS_LCLUSTER_TYPE_MAX - 1)
>
> Previously, it was useful before Z_EROFS_LCLUSTER_TYPE_HEAD2 was
> introduced, but the `default:` case is already deadcode now.
Xiang, thanks for the explanation.
So seems it can happen when mounting last image w/ old kernel which can not
support newly introduced Z_EROFS_LCLUSTER_TYPE_* type, then it makes sense to
return EOPNOTSUPP.
>
>>
>> Btw, we'd better to do sanity check for m->type in z_erofs_load_full_lcluster(),
>> then we can treat m->type as reliable variable later.
>>
>> advise = le16_to_cpu(di->di_advise);
>> m->type = advise & Z_EROFS_LI_LCLUSTER_TYPE_MASK;
>> if (m->type >= Z_EROFS_LCLUSTER_TYPE_MAX) {
>
> It's always false here.
So, what do you think of this?