Hi Ahmad, On Wed, Feb 28, 2024 at 05:03:04PM +0100, Ahmad Fatoum wrote: > The detect callback will try to detect an UBI volume inside a partition. > If that partition happens to be smaller than 512 bytes, detect will fail > with -EINVAL. This 512 bytes here is confusing. You are referring to the eraseblock size which is usually much bigger than 512 bytes. > > Avoid this confusing error by early exiting in this case. > > Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> > --- > drivers/mtd/core.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c > index 97a7996cf68e..34f919b96ea4 100644 > --- a/drivers/mtd/core.c > +++ b/drivers/mtd/core.c > @@ -599,6 +599,10 @@ static int mtd_detect(struct device *dev) > enum filetype filetype; > int npebs = mtd_div_by_eb(mtd->size, mtd); > > + /* No point in looking for UBI on a partition that's smaller than an erase block */ > + if (!npebs) > + return 0; When this triggers your partitioning is wrong. Partitions should always align to eraseblock boundaries. While it is possible to have not eraseblock aligned partitions, you'll be unable to write on these partitions as you would always erase parts of the neighbour partition. However, there's a minimal number of eraseblocks that a device must have to be usable with UBI, see http://www.linux-mtd.infradead.org/doc/ubi.html#L_overhead So instead of !npebs you can test for npebs < 5. > + > npebs = max(npebs, 64); Not your patches fault, but as I just see it: This is wrong. It should be min(), not max(). The goal of this is to check the first 64 eraseblocks, but not more pebs the device actually has. Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |