[Cryptech-Commits] [sw/libhal] 04/05: Disallow NULL core argument in lowest-level HAL I/O routines.
git at cryptech.is
git at cryptech.is
Mon Oct 5 03:28:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch config_core_selector
in repository sw/libhal.
commit ff4ff7c8ccf0c5d5c1c363053f0fc84ec5674edf
Author: Rob Austein <sra at hactrn.net>
Date: Sun Oct 4 23:23:07 2015 -0400
Disallow NULL core argument in lowest-level HAL I/O routines.
---
hal_io_eim.c | 6 ++++++
hal_io_i2c.c | 57 ++++++++++++++++++++-------------------------------------
2 files changed, 26 insertions(+), 37 deletions(-)
diff --git a/hal_io_eim.c b/hal_io_eim.c
index 4f9df65..7d2e32a 100644
--- a/hal_io_eim.c
+++ b/hal_io_eim.c
@@ -98,6 +98,9 @@ hal_error_t hal_io_write(const hal_core_t *core, hal_addr_t offset, const uint8_
{
hal_error_t err;
+ if (core == NULL)
+ return HAL_ERROR_CORE_NOT_FOUND;
+
if (len % 4 != 0)
return HAL_ERROR_IO_BAD_COUNT;
@@ -122,6 +125,9 @@ hal_error_t hal_io_read(const hal_core_t *core, hal_addr_t offset, uint8_t *buf,
int rlen = len;
hal_error_t err;
+ if (core == NULL)
+ return HAL_ERROR_CORE_NOT_FOUND;
+
if (len % 4 != 0)
return HAL_ERROR_IO_BAD_COUNT;
diff --git a/hal_io_i2c.c b/hal_io_i2c.c
index 3e8ac59..7fb306e 100644
--- a/hal_io_i2c.c
+++ b/hal_io_i2c.c
@@ -267,24 +267,14 @@ static hal_error_t hal_io_get_read_resp(hal_addr_t offset, uint8_t *data)
return HAL_OK;
}
-static hal_error_t hal_io_get_read_resp_expected(hal_addr_t offset, const uint8_t *data)
+hal_error_t hal_io_write(const hal_core_t *core, hal_addr_t offset, const uint8_t *buf, size_t len)
{
- uint8_t buf[9];
- uint8_t expected[9] = { SOR, READ_OK, (offset >> 8) & 0xff, offset & 0xff,
- data[0], data[1], data[2], data[3], EOR };
hal_error_t err;
- dump("expect", expected, 9);
-
- if ((err = hal_io_get_resp(buf, sizeof(buf))) != HAL_OK)
- return err;
-
- return hal_io_compare(buf, expected, sizeof(buf));
-}
+ if (core == NULL)
+ return HAL_ERROR_CORE_NOT_FOUND;
-hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len)
-{
- hal_error_t err;
+ offset += hal_core_base(core);
for (; len > 0; offset++, buf += 4, len -= 4)
if ((err = hal_io_send_write_cmd(offset, buf)) != HAL_OK ||
@@ -294,43 +284,36 @@ hal_error_t hal_io_write(hal_addr_t offset, const uint8_t *buf, size_t len)
return HAL_OK;
}
-hal_error_t hal_io_read(hal_addr_t offset, uint8_t *buf, size_t len)
+hal_error_t hal_io_read(const hal_core_t *core, hal_addr_t offset, uint8_t *buf, size_t len)
{
hal_error_t err;
- for (; len > 0; offset++, buf += 4, len -= 4)
- if ((err = hal_io_send_read_cmd(offset)) != HAL_OK ||
- (err = hal_io_get_read_resp(offset, buf)) != HAL_OK)
- return err;
+ if (core == NULL)
+ return HAL_ERROR_CORE_NOT_FOUND;
- return HAL_OK;
-}
-
-hal_error_t hal_io_expected(hal_addr_t offset, const uint8_t *buf, size_t len)
-{
- hal_error_t err;
+ offset += hal_core_base(core);
for (; len > 0; offset++, buf += 4, len -= 4)
- if ((err = hal_io_send_read_cmd(offset)) != HAL_OK ||
- (err = hal_io_get_read_resp_expected(offset, buf)) != HAL_OK)
+ if ((err = hal_io_send_read_cmd(offset)) != HAL_OK ||
+ (err = hal_io_get_read_resp(offset, buf)) != HAL_OK)
return err;
return HAL_OK;
}
-hal_error_t hal_io_init(hal_addr_t offset)
+hal_error_t hal_io_init(const hal_core_t *core)
{
uint8_t buf[4] = { 0, 0, 0, CTRL_INIT };
- return hal_io_write(offset, buf, 4);
+ return hal_io_write(core, ADDR_CTRL, buf, 4);
}
-hal_error_t hal_io_next(hal_addr_t offset)
+hal_error_t hal_io_next(const hal_core_t *core)
{
uint8_t buf[4] = { 0, 0, 0, CTRL_NEXT };
- return hal_io_write(offset, buf, 4);
+ return hal_io_write(core, ADDR_CTRL, buf, 4);
}
-hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count)
+hal_error_t hal_io_wait(const hal_core_t *core, uint8_t status, int *count)
{
hal_error_t err;
uint8_t buf[4];
@@ -341,7 +324,7 @@ hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count)
if (count && (*count > 0) && (i >= *count))
return HAL_ERROR_IO_TIMEOUT;
- if ((err = hal_io_read(offset, buf, 4)) != HAL_OK)
+ if ((err = hal_io_read(core, ADDR_STATUS, buf, 4)) != HAL_OK)
return err;
if (buf[3] & status) {
@@ -353,16 +336,16 @@ hal_error_t hal_io_wait(hal_addr_t offset, uint8_t status, int *count)
}
}
-hal_error_t hal_io_wait_ready(hal_addr_t offset)
+hal_error_t hal_io_wait_ready(const hal_core_t *core)
{
int limit = 10;
- return hal_io_wait(offset, STATUS_READY, &limit);
+ return hal_io_wait(core, STATUS_READY, &limit);
}
-hal_error_t hal_io_wait_valid(hal_addr_t offset)
+hal_error_t hal_io_wait_valid(const hal_core_t *core)
{
int limit = 10;
- return hal_io_wait(offset, STATUS_VALID, &limit);
+ return hal_io_wait(core, STATUS_VALID, &limit);
}
/*
More information about the Commits
mailing list