All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Fenkart <afenkart@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 4/4] env_sf: use DIV_ROUND_UP to calculate number of sectors to erase
Date: Sat,  8 Apr 2017 11:59:34 +0200	[thread overview]
Message-ID: <20170408095934.32733-5-afenkart@gmail.com> (raw)
In-Reply-To: <20170408095934.32733-1-afenkart@gmail.com>

simpler to read

Signed-off-by: Andreas Fenkart <afenkart@gmail.com>
---
 common/env_sf.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/common/env_sf.c b/common/env_sf.c
index 6a1583ebec..9944602367 100644
--- a/common/env_sf.c
+++ b/common/env_sf.c
@@ -80,7 +80,7 @@ int saveenv(void)
 {
 	env_t	env_new;
 	char	*saved_buffer = NULL, flag = OBSOLETE_FLAG;
-	u32	saved_size, saved_offset, sector = 1;
+	u32	saved_size, saved_offset, sector;
 	int	ret;
 
 	ret = setup_flash_device();
@@ -115,11 +115,7 @@ int saveenv(void)
 			goto done;
 	}
 
-	if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) {
-		sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE;
-		if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE)
-			sector++;
-	}
+	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);
 
 	puts("Erasing SPI flash...");
 	ret = spi_flash_erase(env_flash, env_new_offset,
@@ -245,7 +241,7 @@ out:
 #else
 int saveenv(void)
 {
-	u32	saved_size, saved_offset, sector = 1;
+	u32	saved_size, saved_offset, sector;
 	char	*saved_buffer = NULL;
 	int	ret = 1;
 	env_t	env_new;
@@ -268,16 +264,12 @@ int saveenv(void)
 			goto done;
 	}
 
-	if (CONFIG_ENV_SIZE > CONFIG_ENV_SECT_SIZE) {
-		sector = CONFIG_ENV_SIZE / CONFIG_ENV_SECT_SIZE;
-		if (CONFIG_ENV_SIZE % CONFIG_ENV_SECT_SIZE)
-			sector++;
-	}
-
 	ret = env_export(&env_new);
 	if (ret)
 		goto done;
 
+	sector = DIV_ROUND_UP(CONFIG_ENV_SIZE, CONFIG_ENV_SECT_SIZE);
+
 	puts("Erasing SPI flash...");
 	ret = spi_flash_erase(env_flash, CONFIG_ENV_OFFSET,
 		sector * CONFIG_ENV_SECT_SIZE);
-- 
2.11.0

  parent reply	other threads:[~2017-04-08  9:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-08  9:59 [U-Boot] [PATCH v2 0/4] env_sf: minor refactorings Andreas Fenkart
2017-04-08  9:59 ` [U-Boot] [PATCH v2 1/4] env_sf: factor out prepare_flash_device Andreas Fenkart
2017-04-08  9:59 ` [U-Boot] [PATCH v2 2/4] enf_sf: reuse setup_flash_device instead of open coding it Andreas Fenkart
2017-04-09 19:28   ` Simon Glass
2017-04-08  9:59 ` [U-Boot] [PATCH v2 3/4] env_sf: re-order error handling in single-buffer env_relocate_spec Andreas Fenkart
2017-04-09 19:28   ` Simon Glass
2017-04-08  9:59 ` Andreas Fenkart [this message]
2017-04-09 19:28   ` [U-Boot] [PATCH v2 4/4] env_sf: use DIV_ROUND_UP to calculate number of sectors to erase Simon Glass
2017-05-03  5:55 ` [U-Boot] [PATCH v2 0/4] env_sf: minor refactorings Jagan Teki

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=20170408095934.32733-5-afenkart@gmail.com \
    --to=afenkart@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.