mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mtd: don't try to detect UBI in too small flash partitions
@ 2024-02-28 16:03 Ahmad Fatoum
  2024-02-29  7:42 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-02-28 16:03 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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.

Avoid this confusing error by early exiting in this case.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 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;
+
 	npebs = max(npebs, 64);
 
 	/*
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] mtd: don't try to detect UBI in too small flash partitions
  2024-02-28 16:03 [PATCH] mtd: don't try to detect UBI in too small flash partitions Ahmad Fatoum
@ 2024-02-29  7:42 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-02-29  7:42 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

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@pengutronix.de>
> ---
>  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 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-29  7:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 16:03 [PATCH] mtd: don't try to detect UBI in too small flash partitions Ahmad Fatoum
2024-02-29  7:42 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox