diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-03-29 10:20:41 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-04-01 10:38:55 +0200 |
commit | 439d6830517e15a2b31e90733b8aeaaf98b9e0f2 (patch) | |
tree | 7fdd5aade40a7645d4912e3491eab62c06ef831f /common/imd.c | |
parent | 82d40a62141752acbd9677a32ebe54f405dd99fa (diff) | |
download | barebox-439d6830517e15a2b31e90733b8aeaaf98b9e0f2.tar.gz barebox-439d6830517e15a2b31e90733b8aeaaf98b9e0f2.tar.xz |
imd: rename imd_search_validate to imd_get
The name is more suitable for what the function does. Also let the
function return a pointer to the imd data found in the buffer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/imd.c')
-rw-r--r-- | common/imd.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/common/imd.c b/common/imd.c index 5570ae973a..3a7cbc96e4 100644 --- a/common/imd.c +++ b/common/imd.c @@ -112,17 +112,17 @@ static int imd_validate_tags(void *buf, int bufsize, int start_ofs) } /* - * imd_search_validate - find valid metadata in a buffer + * imd_get - find valid metadata in a buffer * @buf the buffer * @size buffer size - * @start The returned pointer to the metadata * * This iterates over a buffer and searches for metadata. The metadata * is checked for consistency (length fields not exceeding buffer and - * presence of end header) and returned in @start. The returned pointer - * is only valid when 0 is returned. The returned data may be unaligned. + * presence of end header) and returned. + * + * Return: a pointer to the image metadata or a ERR_PTR */ -static int imd_search_validate(void *buf, int size, struct imd_header **start) +struct imd_header *imd_get(void *buf, int size) { int start_ofs = 0; int i, ret; @@ -138,13 +138,11 @@ static int imd_search_validate(void *buf, int size, struct imd_header **start) debug("Start tag found at offset %d\n", i); ret = imd_validate_tags(buf, size, i); - if (!ret) { - *start = buf + i; - return 0; - } + if (!ret) + return buf + i; } - return -EINVAL; + return ERR_PTR(-EINVAL); } struct imd_type_names { @@ -282,9 +280,9 @@ int imd_command(int argc, char *argv[]) if (ret && ret != -EFBIG) return -errno; - ret = imd_search_validate(buf, size, &imd_start); - if (ret) - return ret; + imd_start = imd_get(buf, size); + if (IS_ERR(imd_start)) + return PTR_ERR(imd_start); if (type == IMD_TYPE_INVALID) { imd_for_each(imd_start, imd) { |