diff options
author | Nicolas Boichat <drinkcat@google.com> | 2017-02-18 22:13:57 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-02-23 19:06:16 -0800 |
commit | ed396c5efbadefaf7b6a7dee64258f063f4b9fd3 (patch) | |
tree | 1ec5f4425d45c99420745825e94046de38dbf992 | |
parent | 918cb2ca3aacf6fa4bda71619fbeaea1c0257bdf (diff) | |
download | chrome-ec-ed396c5efbadefaf7b6a7dee64258f063f4b9fd3.tar.gz |
common/flash.c: Remove redundant code
Saves a little bit of flash size:
Compared 167 of 167 files.
77 files changed.
Total size change: -3240 bytes.
Average size change: -42 bytes.
BRANCH=none
BUG=chrome-os-partner:61671
TEST=make buildall -j
TEST=hammer: 'flashwp true' works as expected
TEST=hammer+CONFIG_FLASH_PSTATE_BANK: 'flashwp true' still works
TEST=reef: 'flashwp now' sets all_now flag in flashinfo
Change-Id: Ic2fe8f0c67520afea276369fdf8c59e75e95208e
Reviewed-on: https://chromium-review.googlesource.com/444488
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r-- | common/flash.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/common/flash.c b/common/flash.c index 9b201ee543..275e4692e8 100644 --- a/common/flash.c +++ b/common/flash.c @@ -220,7 +220,6 @@ static int validate_pstate_struct(struct persist_state *pstate) if (pstate->version != PERSIST_STATE_VERSION) { memset(pstate, 0, sizeof(*pstate)); pstate->version = PERSIST_STATE_VERSION; - pstate->valid_fields = 0; } return EC_SUCCESS; @@ -589,6 +588,9 @@ int flash_set_protect(uint32_t mask, uint32_t flags) (EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_ALL_AT_BOOT); int new_flags_at_boot = old_flags_at_boot; + /* Sanitize input flags */ + flags = flags & mask; + /* * Process flags we can set. Track the most recent error, but process * all flags before returning. @@ -614,7 +616,7 @@ int flash_set_protect(uint32_t mask, uint32_t flags) */ new_flags_at_boot &= ~(mask & EC_FLASH_PROTECT_RO_AT_BOOT); - new_flags_at_boot |= mask & flags & EC_FLASH_PROTECT_RO_AT_BOOT; + new_flags_at_boot |= flags & EC_FLASH_PROTECT_RO_AT_BOOT; if ((mask & EC_FLASH_PROTECT_ALL_AT_BOOT) && !(flags & EC_FLASH_PROTECT_ALL_AT_BOOT)) @@ -637,10 +639,9 @@ int flash_set_protect(uint32_t mask, uint32_t flags) /* * The case where ALL_AT_BOOT is unset is already covered above, - * but this does not hurt. + * so we do not need to mask it out. */ - new_flags_at_boot &= ~(mask & EC_FLASH_PROTECT_ALL_AT_BOOT); - new_flags_at_boot |= mask & flags & EC_FLASH_PROTECT_ALL_AT_BOOT; + new_flags_at_boot |= flags & EC_FLASH_PROTECT_ALL_AT_BOOT; if (new_flags_at_boot != old_flags_at_boot) { rv = flash_protect_at_boot(new_flags_at_boot); @@ -648,20 +649,17 @@ int flash_set_protect(uint32_t mask, uint32_t flags) retval = rv; } - if ((mask & EC_FLASH_PROTECT_RO_NOW) && - (flags & EC_FLASH_PROTECT_RO_NOW)) { + if (flags & EC_FLASH_PROTECT_RO_NOW) { rv = flash_physical_protect_now(0); if (rv) retval = rv; } - if ((mask & EC_FLASH_PROTECT_ALL_NOW) && - (flags & EC_FLASH_PROTECT_ALL_NOW)) { + if (flags & EC_FLASH_PROTECT_ALL_NOW) { rv = flash_physical_protect_now(1); if (rv) retval = rv; } - return retval; } |