diff options
author | Enrico Jorns <ejo@pengutronix.de> | 2022-08-19 14:32:13 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2022-09-27 08:32:46 +0200 |
commit | b83c64f7a12538417649accc1269c22d5ff074bb (patch) | |
tree | 04afb5e431fa023daf201438cf4e5a1d36aa6700 /tests/unittests/sysfs_mock/class/mtd/mtd0/name | |
parent | 374d3cd10eebacae3f5e987ce9e8cf8e8418a4db (diff) |
libmtd: do not ignore non-zero eraseblock size when MTD_NO_ERASE is set
In 54d68799, mtd->eb_cnt was enforced to be '1' if MTD_NO_ERASE is set.
This was done with the aim of preventing divisions by zero.
However, even if MTD_NO_ERASE is set, mtd->eb_size (eraseblock size) can
still be set to a non-zero value which would not cause a division by
zero.
Instead, enforcing an eraseblock count of '1' here even leads to
inconsistent eraseblock counting in mtd-utils and lets for example a
'flash_erase' on an mtdnand device fail:
| # flash_erase /dev/mtd0 0 0
| Erasing 32768 Kibyte @ 0 -- 0 % complete libmtd: error!: bad eraseblock number 255, mtd0 has 1 eraseblocks
| flash_erase: error!: /dev/mtd0: MTD Erase entire chip failureTrying one by one each sector.
| error 22 (Invalid argument)
| Erasing 128 Kibyte @ 0 -- 0 % complete libmtd: error!: bad eraseblock number 1, mtd0 has 1 eraseblocks
| flash_erase: error!: /dev/mtd0: MTD get bad block failed
| error 22 (Invalid argument)
Also mtdinfo would look inconsistent (eraseblock size vs amount):
| # mtdinfo /dev/mtd0
| mtd0
| Name: mtdram test device
| Type: ram
| Eraseblock size: 131072 bytes, 128.0 KiB
| Amount of eraseblocks: 1 (33554432 bytes, 32.0 MiB)
| Minimum input/output unit size: 1 byte
| Sub-page size: 1 byte
| Character device major/minor: 90:0
| Bad blocks are allowed: false
| Device is writable: true
Fix this by enforcing mtd->eb_cnt to be '1' only when mtd->eb_size is
actually zero and would lead to a division by zero otherwise.
Fixes: 54d68799 ("libmtd: avoid divide by zero")
Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'tests/unittests/sysfs_mock/class/mtd/mtd0/name')
0 files changed, 0 insertions, 0 deletions