ubi: some invalid code in the function scan_peb
Zhihao Cheng
chengzhihao1 at huawei.com
Wed Oct 18 00:42:04 PDT 2023
在 2023/10/18 15:28, Ryder Wang 写道:
> The patch below can remove the invalid code. It can pass ubi code build and ubi attach can also be OK from the testing.
>
Reviewed-by: Zhihao Cheng <chengzhihao1 at huawei.com>
> diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
> index 10b2459f8951..8268ca6a91d1
> --- a/drivers/mtd/ubi/attach.c
> +++ b/drivers/mtd/ubi/attach.c
> @@ -995,28 +995,6 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
> if (!ec_err) {
> int image_seq;
>
> - /* Make sure UBI version is OK */
> - if (ech->version != UBI_VERSION) {
> - ubi_err(ubi, "this UBI version is %d, image version is %d",
> - UBI_VERSION, (int)ech->version);
> - return -EINVAL;
> - }
> -
> - ec = be64_to_cpu(ech->ec);
> - if (ec > UBI_MAX_ERASECOUNTER) {
> - /*
> - * Erase counter overflow. The EC headers have 64 bits
> - * reserved, but we anyway make use of only 31 bit
> - * values, as this seems to be enough for any existing
> - * flash. Upgrade UBI and use 64-bit erase counters
> - * internally.
> - */
> - ubi_err(ubi, "erase counter overflow, max is %d",
> - UBI_MAX_ERASECOUNTER);
> - ubi_dump_ec_hdr(ech);
> - return -EINVAL;
> - }
> -
> /*
> * Make sure that all PEBs have the same image sequence number.
> * This allows us to detect situations when users flash UBI
>
>
> From: Zhihao Cheng <chengzhihao1 at huawei.com>
> Sent: Wednesday, October 18, 2023 14:31
> To: Ryder Wang <rydercoding at hotmail.com>; linux-mtd at lists.infradead.org <linux-mtd at lists.infradead.org>
> Subject: Re: ubi: some invalid code in the function scan_peb
>
> 在 2023/10/18 13:59, Ryder Wang 写道:
>> I just find some dead code in the function scan_peb in drvier/mtd/ubi/attach.c.
>>
>> In the function scan_peb, it calls validate_ec_hdr which calls validate_ec_hdr. If ubi version or erase count is incorrect, it will report -EINVAL and abort the function scan_peb. However, ubi version or erase count will be checked again in scan_peb and such check code will never find the errors because such errors should have been detected by validate_ec_hdr (aborting).
>>
>
> Yes, redundant checking indeed exists in scan_peb(), could you send a
> patch to clean it up?
>
More information about the linux-mtd
mailing list