[PATCH 06/12] Consolidate utilfdt_read_len() variants

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



There are no less than _four_ variants on utilfdt_read() which is a bit
excessive.  The _len() variants are particularly pointless, since we can
achieve the same thing with very little extra verbosity by using the usual
convention of ignoring return parameters if they're NULL.  So, get rid of
them (we keep the shorter names without _len, but add now-optional len
parameters).

Signed-off-by: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>
---
 fdtdump.c         |  2 +-
 fdtget.c          |  2 +-
 fdtoverlay.c      |  4 ++--
 fdtput.c          |  2 +-
 tests/testutils.c |  2 +-
 util.c            | 21 +++++----------------
 util.h            | 20 ++++----------------
 7 files changed, 15 insertions(+), 38 deletions(-)

diff --git a/fdtdump.c b/fdtdump.c
index fa3b561..d12eb35 100644
--- a/fdtdump.c
+++ b/fdtdump.c
@@ -204,7 +204,7 @@ int main(int argc, char *argv[])
 		usage("missing input filename");
 	file = argv[optind];
 
-	buf = utilfdt_read_len(file, &len);
+	buf = utilfdt_read(file, &len);
 	if (!buf)
 		die("could not read: %s\n", file);
 
diff --git a/fdtget.c b/fdtget.c
index 34d8194..ee7139f 100644
--- a/fdtget.c
+++ b/fdtget.c
@@ -271,7 +271,7 @@ static int do_fdtget(struct display_info *disp, const char *filename,
 	const char *prop;
 	int i, node;
 
-	blob = utilfdt_read(filename);
+	blob = utilfdt_read(filename, NULL);
 	if (!blob)
 		return -1;
 
diff --git a/fdtoverlay.c b/fdtoverlay.c
index 62a942d..2a2c89c 100644
--- a/fdtoverlay.c
+++ b/fdtoverlay.c
@@ -63,7 +63,7 @@ static int do_fdtoverlay(const char *input_filename,
 	off_t blob_len, ov_len, total_len;
 	int i, ret = -1;
 
-	blob = utilfdt_read_len(input_filename, &blob_len);
+	blob = utilfdt_read(input_filename, &blob_len);
 	if (!blob) {
 		fprintf(stderr, "\nFailed to read base blob %s\n",
 				input_filename);
@@ -84,7 +84,7 @@ static int do_fdtoverlay(const char *input_filename,
 	/* read and keep track of the overlay blobs */
 	total_len = 0;
 	for (i = 0; i < argc; i++) {
-		ovblob[i] = utilfdt_read_len(argv[i], &ov_len);
+		ovblob[i] = utilfdt_read(argv[i], &ov_len);
 		if (!ovblob[i]) {
 			fprintf(stderr, "\nFailed to read overlay %s\n",
 					argv[i]);
diff --git a/fdtput.c b/fdtput.c
index 72a0058..9e739bd 100644
--- a/fdtput.c
+++ b/fdtput.c
@@ -333,7 +333,7 @@ static int do_fdtput(struct display_info *disp, const char *filename,
 	char *node;
 	int len, ret = 0;
 
-	blob = utilfdt_read(filename);
+	blob = utilfdt_read(filename, NULL);
 	if (!blob)
 		return -1;
 
diff --git a/tests/testutils.c b/tests/testutils.c
index f03140e..4a2acc9 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -164,7 +164,7 @@ int nodename_eq(const char *s1, const char *s2)
 void *load_blob(const char *filename)
 {
 	char *blob;
-	int ret = utilfdt_read_err(filename, &blob);
+	int ret = utilfdt_read_err(filename, &blob, NULL);
 
 	if (ret)
 		CONFIG("Couldn't open blob from \"%s\": %s", filename,
diff --git a/util.c b/util.c
index 9953c32..0edd672 100644
--- a/util.c
+++ b/util.c
@@ -227,7 +227,7 @@ char get_escape_char(const char *s, int *i)
 	return val;
 }
 
-int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len)
+int utilfdt_read_err(const char *filename, char **buffp, off_t *len)
 {
 	int fd = 0;	/* assume stdin */
 	char *buf = NULL;
@@ -264,20 +264,15 @@ int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len)
 		free(buf);
 	else
 		*buffp = buf;
-	*len = bufsize;
+	if (len)
+		*len = bufsize;
 	return ret;
 }
 
-int utilfdt_read_err(const char *filename, char **buffp)
-{
-	off_t len;
-	return utilfdt_read_err_len(filename, buffp, &len);
-}
-
-char *utilfdt_read_len(const char *filename, off_t *len)
+char *utilfdt_read(const char *filename, off_t *len)
 {
 	char *buff;
-	int ret = utilfdt_read_err_len(filename, &buff, len);
+	int ret = utilfdt_read_err(filename, &buff, len);
 
 	if (ret) {
 		fprintf(stderr, "Couldn't open blob from '%s': %s\n", filename,
@@ -288,12 +283,6 @@ char *utilfdt_read_len(const char *filename, off_t *len)
 	return buff;
 }
 
-char *utilfdt_read(const char *filename)
-{
-	off_t len;
-	return utilfdt_read_len(filename, &len);
-}
-
 int utilfdt_write_err(const char *filename, const void *blob)
 {
 	int fd = 1;	/* assume stdout */
diff --git a/util.h b/util.h
index 66fba8e..d3058ed 100644
--- a/util.h
+++ b/util.h
@@ -98,16 +98,10 @@ char get_escape_char(const char *s, int *i);
  * stderr.
  *
  * @param filename	The filename to read, or - for stdin
- * @return Pointer to allocated buffer containing fdt, or NULL on error
- */
-char *utilfdt_read(const char *filename);
-
-/**
- * Like utilfdt_read(), but also passes back the size of the file read.
- *
  * @param len		If non-NULL, the amount of data we managed to read
+ * @return Pointer to allocated buffer containing fdt, or NULL on error
  */
-char *utilfdt_read_len(const char *filename, off_t *len);
+char *utilfdt_read(const char *filename, off_t *len);
 
 /**
  * Read a device tree file into a buffer. Does not report errors, but only
@@ -116,16 +110,10 @@ char *utilfdt_read_len(const char *filename, off_t *len);
  *
  * @param filename	The filename to read, or - for stdin
  * @param buffp		Returns pointer to buffer containing fdt
- * @return 0 if ok, else an errno value representing the error
- */
-int utilfdt_read_err(const char *filename, char **buffp);
-
-/**
- * Like utilfdt_read_err(), but also passes back the size of the file read.
- *
  * @param len		If non-NULL, the amount of data we managed to read
+ * @return 0 if ok, else an errno value representing the error
  */
-int utilfdt_read_err_len(const char *filename, char **buffp, off_t *len);
+int utilfdt_read_err(const char *filename, char **buffp, off_t *len);
 
 /**
  * Write a device tree buffer to a file. This will report any errors on
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe devicetree-compiler" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux