mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 4/7] imd: rename imd_search_validate to imd_get
Date: Tue, 29 Mar 2016 10:50:51 +0200	[thread overview]
Message-ID: <1459241454-21155-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1459241454-21155-1-git-send-email-s.hauer@pengutronix.de>

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>
---
 common/imd.c         | 24 +++++++++++-------------
 scripts/bareboximd.c |  1 +
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/common/imd.c b/common/imd.c
index 9bd1563..318980b 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) {
diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c
index a3622af..d4da681 100644
--- a/scripts/bareboximd.c
+++ b/scripts/bareboximd.c
@@ -33,6 +33,7 @@
 #include <string.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <linux/err.h>
 
 #include "../include/image-metadata.h"
 
-- 
2.7.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-03-29  8:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-29  8:50 [PATCH 1/7] imd: use struct imd_header * as argument Sascha Hauer
2016-03-29  8:50 ` [PATCH 2/7] imd: string returned from imd_string_data should be const Sascha Hauer
2016-03-29  9:34   ` Stefan Christ
2016-04-01  8:43     ` Sascha Hauer
2016-03-29  8:50 ` [PATCH 3/7] scripts: Add scripts/include/ to include path for target programs Sascha Hauer
2016-03-29  8:50 ` Sascha Hauer [this message]
2016-03-29  8:50 ` [PATCH 5/7] imd: export functions Sascha Hauer
2016-03-29  8:50 ` [PATCH 6/7] imd: Add function to read parameters Sascha Hauer
2016-03-29  8:50 ` [PATCH 7/7] bbu: print and evaluate image Metadata Sascha Hauer
2016-03-29  9:29   ` Stefan Christ
2016-04-01  8:41     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459241454-21155-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox