mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] mtd: don't try to detect UBI in too small flash partitions
Date: Thu, 29 Feb 2024 08:42:00 +0100	[thread overview]
Message-ID: <ZeA1SB9HodGkk5HO@pengutronix.de> (raw)
In-Reply-To: <20240228160304.1588645-1-a.fatoum@pengutronix.de>

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 |



      reply	other threads:[~2024-02-29  7:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 16:03 Ahmad Fatoum
2024-02-29  7:42 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZeA1SB9HodGkk5HO@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox