diff mbox series

[1/2] env/sf.c: use a variable to hold the sector size

Message ID 20200506084701.8076-2-rasmus.villemoes@prevas.dk
State Accepted
Commit 4da7347d85aa4409945201279d71ae501cd5c164
Headers show
Series add CONFIG_ENV_SECT_SIZE_AUTO | expand

Commit Message

Rasmus Villemoes May 6, 2020, 8:47 a.m. UTC
As preparation for the next patch, use a local variable to represent
the sector size. No functional change.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
---
 env/sf.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

Comments

Rasmus Villemoes Sept. 18, 2020, 8:16 a.m. UTC | #1
On 06/05/2020 10.47, Rasmus Villemoes wrote:
> As preparation for the next patch, use a local variable to represent

> the sector size. No functional change.

> 


ping

> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

> ---

>  env/sf.c | 22 ++++++++++++----------

>  1 file changed, 12 insertions(+), 10 deletions(-)

> 

> diff --git a/env/sf.c b/env/sf.c

> index 22b70ad319..cd5339578b 100644

> --- a/env/sf.c

> +++ b/env/sf.c

> @@ -70,6 +70,7 @@ static int env_sf_save(void)

>  	env_t	env_new;

>  	char	*saved_buffer = NULL, flag = ENV_REDUND_OBSOLETE;

>  	u32	saved_size, saved_offset, sector;

> +	u32	sect_size = CONFIG_ENV_SECT_SIZE;

>  	int	ret;

>  

>  	ret = setup_flash_device();

> @@ -90,8 +91,8 @@ static int env_sf_save(void)

>  	}

>  

>  	/* Is the sector larger than the env (i.e. embedded) */

> -	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {

> -		saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;

> +	if (sect_size > CONFIG_ENV_SIZE) {

> +		saved_size = sect_size - CONFIG_ENV_SIZE;

>  		saved_offset = env_new_offset + CONFIG_ENV_SIZE;

>  		saved_buffer = memalign(ARCH_DMA_MINALIGN, saved_size);

>  		if (!saved_buffer) {

> @@ -104,11 +105,11 @@ static int env_sf_save(void)

>  			goto done;

>  	}

>  

> -	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);

> +	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, sect_size);

>  

>  	puts("Erasing SPI flash...");

>  	ret = spi_flash_erase(env_flash, env_new_offset,

> -				sector * CONFIG_ENV_SECT_SIZE);

> +				sector * sect_size);

>  	if (ret)

>  		goto done;

>  

> @@ -119,7 +120,7 @@ static int env_sf_save(void)

>  	if (ret)

>  		goto done;

>  

> -	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {

> +	if (sect_size > CONFIG_ENV_SIZE) {

>  		ret = spi_flash_write(env_flash, saved_offset,

>  					saved_size, saved_buffer);

>  		if (ret)

> @@ -184,6 +185,7 @@ out:

>  static int env_sf_save(void)

>  {

>  	u32	saved_size, saved_offset, sector;

> +	u32	sect_size = CONFIG_ENV_SECT_SIZE;

>  	char	*saved_buffer = NULL;

>  	int	ret = 1;

>  	env_t	env_new;

> @@ -193,8 +195,8 @@ static int env_sf_save(void)

>  		return ret;

>  

>  	/* Is the sector larger than the env (i.e. embedded) */

> -	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {

> -		saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;

> +	if (sect_size > CONFIG_ENV_SIZE) {

> +		saved_size = sect_size - CONFIG_ENV_SIZE;

>  		saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE;

>  		saved_buffer = malloc(saved_size);

>  		if (!saved_buffer)

> @@ -210,11 +212,11 @@ static int env_sf_save(void)

>  	if (ret)

>  		goto done;

>  

> -	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);

> +	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, sect_size);

>  

>  	puts("Erasing SPI flash...");

>  	ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET,

> -		sector * CONFIG_ENV_SECT_SIZE);

> +		sector * sect_size);

>  	if (ret)

>  		goto done;

>  

> @@ -224,7 +226,7 @@ static int env_sf_save(void)

>  	if (ret)

>  		goto done;

>  

> -	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {

> +	if (sect_size > CONFIG_ENV_SIZE) {

>  		ret = spi_flash_write(env_flash, saved_offset,

>  			saved_size, saved_buffer);

>  		if (ret)

> 



-- 
Rasmus Villemoes
Software Developer
Prevas A/S
Hedeager 3
DK-8200 Aarhus N
+45 51210274
rasmus.villemoes@prevas.dk
www.prevas.dk
Tom Rini Sept. 18, 2020, 2:49 p.m. UTC | #2
On Fri, Sep 18, 2020 at 10:16:32AM +0200, Rasmus Villemoes wrote:

> On 06/05/2020 10.47, Rasmus Villemoes wrote:

> > As preparation for the next patch, use a local variable to represent

> > the sector size. No functional change.

> > 

> 

> ping


I should probably put this series, and other env things in to -next soon
after reading them over one more time.  Thanks.

-- 
Tom
diff mbox series

Patch

diff --git a/env/sf.c b/env/sf.c
index 22b70ad319..cd5339578b 100644
--- a/env/sf.c
+++ b/env/sf.c
@@ -70,6 +70,7 @@  static int env_sf_save(void)
 	env_t	env_new;
 	char	*saved_buffer = NULL, flag = ENV_REDUND_OBSOLETE;
 	u32	saved_size, saved_offset, sector;
+	u32	sect_size = CONFIG_ENV_SECT_SIZE;
 	int	ret;
 
 	ret = setup_flash_device();
@@ -90,8 +91,8 @@  static int env_sf_save(void)
 	}
 
 	/* Is the sector larger than the env (i.e. embedded) */
-	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
-		saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;
+	if (sect_size > CONFIG_ENV_SIZE) {
+		saved_size = sect_size - CONFIG_ENV_SIZE;
 		saved_offset = env_new_offset + CONFIG_ENV_SIZE;
 		saved_buffer = memalign(ARCH_DMA_MINALIGN, saved_size);
 		if (!saved_buffer) {
@@ -104,11 +105,11 @@  static int env_sf_save(void)
 			goto done;
 	}
 
-	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);
+	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, sect_size);
 
 	puts("Erasing SPI flash...");
 	ret = spi_flash_erase(env_flash, env_new_offset,
-				sector * CONFIG_ENV_SECT_SIZE);
+				sector * sect_size);
 	if (ret)
 		goto done;
 
@@ -119,7 +120,7 @@  static int env_sf_save(void)
 	if (ret)
 		goto done;
 
-	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
+	if (sect_size > CONFIG_ENV_SIZE) {
 		ret = spi_flash_write(env_flash, saved_offset,
 					saved_size, saved_buffer);
 		if (ret)
@@ -184,6 +185,7 @@  out:
 static int env_sf_save(void)
 {
 	u32	saved_size, saved_offset, sector;
+	u32	sect_size = CONFIG_ENV_SECT_SIZE;
 	char	*saved_buffer = NULL;
 	int	ret = 1;
 	env_t	env_new;
@@ -193,8 +195,8 @@  static int env_sf_save(void)
 		return ret;
 
 	/* Is the sector larger than the env (i.e. embedded) */
-	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
-		saved_size = CONFIG_ENV_SECT_SIZE - CONFIG_ENV_SIZE;
+	if (sect_size > CONFIG_ENV_SIZE) {
+		saved_size = sect_size - CONFIG_ENV_SIZE;
 		saved_offset = CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE;
 		saved_buffer = malloc(saved_size);
 		if (!saved_buffer)
@@ -210,11 +212,11 @@  static int env_sf_save(void)
 	if (ret)
 		goto done;
 
-	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);
+	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, sect_size);
 
 	puts("Erasing SPI flash...");
 	ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET,
-		sector * CONFIG_ENV_SECT_SIZE);
+		sector * sect_size);
 	if (ret)
 		goto done;
 
@@ -224,7 +226,7 @@  static int env_sf_save(void)
 	if (ret)
 		goto done;
 
-	if (CONFIG_ENV_SECT_SIZE > CONFIG_ENV_SIZE) {
+	if (sect_size > CONFIG_ENV_SIZE) {
 		ret = spi_flash_write(env_flash, saved_offset,
 			saved_size, saved_buffer);
 		if (ret)