diff options
author | Cyril Bur <cyril.bur@au1.ibm.com> | 2015-06-23 13:22:08 +1000 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-06-23 13:38:42 +1000 |
commit | 69b152cab30aae6188b590b2df9a6f55932c4408 (patch) | |
tree | 3f8f375a5d80131dd4c0a1955b25a3e6b669d8d0 /libflash/libflash.c | |
parent | 6c458a0369494a7f0ae2e6352850502c5e393f8f (diff) | |
download | skiboot-69b152cab30aae6188b590b2df9a6f55932c4408.zip skiboot-69b152cab30aae6188b590b2df9a6f55932c4408.tar.gz skiboot-69b152cab30aae6188b590b2df9a6f55932c4408.tar.bz2 |
libflash/ecc: Simplify and cleanup ecc code.
The ecc 'memcpy' style functions return success or fail in terms of the ECC
enum. This doesn't really make sense, use true or false. As the result the
ecc enum doesn't need to be exposed anymore, which makes more sense, not
clear why it was exposed in the first place.
Convert some of the ecc #defines to static inlines, shouldn't make any
difference but feels safer.
Fix minor stylistic and typo issues.
Reviewed-By: Alistair Popple <alistair@popple.id.au>
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libflash/libflash.c')
-rw-r--r-- | libflash/libflash.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/libflash/libflash.c b/libflash/libflash.c index e7b3c8e..a142e17 100644 --- a/libflash/libflash.c +++ b/libflash/libflash.c @@ -153,7 +153,7 @@ int flash_read_corrected(struct blocklevel_device *bl, uint32_t pos, void *buf, return flash_read(bl, pos, buf, len); /* Copy the buffer in chunks */ - bufecc = malloc(ECC_BUFFER_SIZE(COPY_BUFFER_LENGTH)); + bufecc = malloc(ecc_buffer_size(COPY_BUFFER_LENGTH)); if (!bufecc) return FLASH_ERR_MALLOC_FAILED; @@ -162,13 +162,13 @@ int flash_read_corrected(struct blocklevel_device *bl, uint32_t pos, void *buf, copylen = MIN(len, COPY_BUFFER_LENGTH); /* Read ECCed data from flash */ - rc = flash_read(bl, pos, bufecc, ECC_BUFFER_SIZE(copylen)); + rc = flash_read(bl, pos, bufecc, ecc_buffer_size(copylen)); if (rc) goto err; /* Extract data from ECCed data */ ret = memcpy_from_ecc(buf, bufecc, copylen); - if (ret == UE) { + if (ret) { rc = FLASH_ERR_ECC_INVALID; goto err; } @@ -176,7 +176,7 @@ int flash_read_corrected(struct blocklevel_device *bl, uint32_t pos, void *buf, /* Update for next copy */ len -= copylen; buf = (uint8_t *)buf + copylen; - pos += ECC_BUFFER_SIZE(copylen); + pos += ecc_buffer_size(copylen); } rc = 0; @@ -397,7 +397,7 @@ int flash_write_corrected(struct blocklevel_device *bl, uint32_t pos, const void uint32_t len, bool verify, bool ecc) { struct ecc64 *bufecc; - uint32_t copylen; + uint32_t copylen, copylen_minus_ecc; int rc; uint8_t ret; @@ -405,17 +405,18 @@ int flash_write_corrected(struct blocklevel_device *bl, uint32_t pos, const void return flash_write(bl, pos, buf, len, verify); /* Copy the buffer in chunks */ - bufecc = malloc(ECC_BUFFER_SIZE(COPY_BUFFER_LENGTH)); + bufecc = malloc(ecc_buffer_size(COPY_BUFFER_LENGTH)); if (!bufecc) return FLASH_ERR_MALLOC_FAILED; while (len > 0) { /* What's left to copy? */ copylen = MIN(len, COPY_BUFFER_LENGTH); + copylen_minus_ecc = ecc_buffer_size_minus_ecc(copylen); /* Add the ecc byte to the data */ - ret = memcpy_to_ecc(bufecc, buf, BUFFER_SIZE_MINUS_ECC(copylen)); - if (ret == UE) { + ret = memcpy_to_ecc(bufecc, buf, copylen_minus_ecc); + if (ret) { rc = FLASH_ERR_ECC_INVALID; goto err; } @@ -426,8 +427,8 @@ int flash_write_corrected(struct blocklevel_device *bl, uint32_t pos, const void goto err; /* Update for next copy */ - len -= BUFFER_SIZE_MINUS_ECC(copylen); - buf = (uint8_t *)buf + BUFFER_SIZE_MINUS_ECC(copylen); + len -= copylen_minus_ecc; + buf = (uint8_t *)buf + copylen_minus_ecc; pos += copylen; } @@ -554,17 +555,17 @@ int flash_smart_write_corrected(struct blocklevel_device *bl, uint32_t dst, cons if (!ecc) return flash_smart_write(bl, dst, src, size); - buf = malloc(ECC_BUFFER_SIZE(size)); + buf = malloc(ecc_buffer_size(size)); if (!buf) return FLASH_ERR_MALLOC_FAILED; rc = memcpy_to_ecc(buf, src, size); - if (rc != GD) { + if (rc) { rc = FLASH_ERR_ECC_INVALID; goto out; } - rc = flash_smart_write(bl, dst, buf, ECC_BUFFER_SIZE(size)); + rc = flash_smart_write(bl, dst, buf, ecc_buffer_size(size)); out: free(buf); |