aboutsummaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJuan Castillo <juan.castillo@arm.com>2015-07-07 15:36:33 +0100
committerAchin Gupta <achin.gupta@arm.com>2015-07-16 20:36:41 +0100
commit31833aff6802a4b5bdc3b7007ce8b1871991e796 (patch)
treee22833169bc109d295291d10aed20c184ea5b7cd /drivers
parent7bcbb962fda8468c16544d4118220fdca2cf455f (diff)
downloadtrusted-firmware-a-31833aff6802a4b5bdc3b7007ce8b1871991e796.tar.gz
Fix bug in semihosting write function
The return value from the SYS_WRITE semihosting operation is 0 if the call is successful or the number of bytes not written, if there is an error. The implementation of the write function in the semihosting driver treats the return value as the number of bytes written, which is wrong. This patch fixes it. Change-Id: Id39dac3d17b5eac557408b8995abe90924c85b85
Diffstat (limited to 'drivers')
-rw-r--r--drivers/io/io_semihosting.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/drivers/io/io_semihosting.c b/drivers/io/io_semihosting.c
index 3c92c6d759..8e62be1d96 100644
--- a/drivers/io/io_semihosting.c
+++ b/drivers/io/io_semihosting.c
@@ -183,7 +183,6 @@ static int sh_file_read(io_entity_t *entity, uintptr_t buffer, size_t length,
static int sh_file_write(io_entity_t *entity, const uintptr_t buffer,
size_t length, size_t *length_written)
{
- int result = IO_FAIL;
long sh_result = -1;
long file_handle;
size_t bytes = length;
@@ -196,13 +195,9 @@ static int sh_file_write(io_entity_t *entity, const uintptr_t buffer,
sh_result = semihosting_file_write(file_handle, &bytes, buffer);
- if (sh_result >= 0) {
- *length_written = sh_result;
- result = IO_SUCCESS;
- } else
- result = IO_FAIL;
+ *length_written = length - bytes;
- return result;
+ return (sh_result == 0) ? IO_SUCCESS : IO_FAIL;
}