diff mbox series

[RESEND,2/3] env: mmc: correct the offset returned by mmc_offset_try_partition

Message ID 20200615103839.RESEND.2.Ib5b400348308b65bb50d9bfff5fe681027bff4e5@changeid
State Superseded
Headers show
Series env: mmc: allow support of mmc_get_env_dev with OF_CONTROL | expand

Commit Message

Patrick Delaunay June 15, 2020, 8:38 a.m. UTC
The output of the function mmc_offset_try_partition must be a
byte offset in mmc and not a multiple of blksz.

This function is used in mmc_offset(), called by mmc_get_env_addr()
and the offset is used in write_env(), erase_env() and read_env().

In these function, blk_start = offset / mmc->read_bl_len
or /write_bl_len so this offset is not a multiple of blksz.

Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
---

 env/mmc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Tom Rini July 27, 2020, 1:33 p.m. UTC | #1
On Mon, Jun 15, 2020 at 10:38:56AM +0200, Patrick Delaunay wrote:

> The output of the function mmc_offset_try_partition must be a

> byte offset in mmc and not a multiple of blksz.

> 

> This function is used in mmc_offset(), called by mmc_get_env_addr()

> and the offset is used in write_env(), erase_env() and read_env().

> 

> In these function, blk_start = offset / mmc->read_bl_len

> or /write_bl_len so this offset is not a multiple of blksz.

> 

> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>


Applied to u-boot/master, thanks!

-- 
Tom
diff mbox series

Patch

diff --git a/env/mmc.c b/env/mmc.c
index e67ef90bce..5de4a45817 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -56,10 +56,10 @@  static inline int mmc_offset_try_partition(const char *str, s64 *val)
 	}
 
 	/* round up to info.blksz */
-	len = (CONFIG_ENV_SIZE + info.blksz - 1) & ~(info.blksz - 1);
+	len = DIV_ROUND_UP(CONFIG_ENV_SIZE, info.blksz);
 
 	/* use the top of the partion for the environment */
-	*val = (info.start + info.size - 1) - len / info.blksz;
+	*val = (info.start + info.size - len) * info.blksz;
 
 	return 0;
 }