Skip to contentSkip to conversation

dtc: Add may const qualifications

PATCH David Gibson 2 participants 2 messages Dec 4, 2007

lore
Share & tools
lore
#0 lore raw

This adds 'const' qualifiers to many variables and functions. In particular it's now used for passing names to the tree accesor functions.

data.c +6 -6
Index: dtc/data.c
===================================================================
@@ -64,7 +64,7 @@ struct data data_grow_for(struct data d,
 	return nd;
 }
 
-struct data data_copy_mem(char *mem, int len)
+struct data data_copy_mem(const char *mem, int len)
 {
 	struct data d;
 
@@ -76,7 +76,7 @@ struct data data_copy_mem(char *mem, int
 	return d;
 }
 
-static char get_oct_char(char *s, int *i)
+static char get_oct_char(const char *s, int *i)
 {
 	char x[4];
 	char *endx;
@@ -98,7 +98,7 @@ static char get_oct_char(char *s, int *i
 	return val;
 }
 
-static char get_hex_char(char *s, int *i)
+static char get_hex_char(const char *s, int *i)
 {
 	char x[3];
 	char *endx;
@@ -117,7 +117,7 @@ static char get_hex_char(char *s, int *i
 	return val;
 }
 
-struct data data_copy_escape_string(char *s, int len)
+struct data data_copy_escape_string(const char *s, int len)
 {
 	int i = 0;
 	struct data d;
@@ -194,7 +194,7 @@ struct data data_copy_file(FILE *f, size
 	return d;
 }
 
-struct data data_append_data(struct data d, void *p, int len)
+struct data data_append_data(struct data d, const void *p, int len)
 {
 	d = data_grow_for(d, len);
 	memcpy(d.val + d.len, p, len);
@@ -237,7 +237,7 @@ struct data data_append_cell(struct data
 	return data_append_data(d, &beword, sizeof(beword));
 }
 
-struct data data_append_re(struct data d, struct fdt_reserve_entry *re)
+struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)
 {
 	struct fdt_reserve_entry bere;
 
dtc.c +7 -7
Index: dtc/dtc.c
===================================================================
@@ -30,7 +30,7 @@ int quiet;		/* Level of quietness */
 int reservenum;		/* Number of memory reservation slots */
 int minsize;		/* Minimum blob size */
 
-char *join_path(char *path, char *name)
+char *join_path(const char *path, const char *name)
 {
 	int lenp = strlen(path);
 	int lenn = strlen(name);
@@ -54,10 +54,10 @@ char *join_path(char *path, char *name)
 	return str;
 }
 
-void fill_fullpaths(struct node *tree, char *prefix)
+void fill_fullpaths(struct node *tree, const char *prefix)
 {
 	struct node *child;
-	char *unit;
+	const char *unit;
 
 	tree->fullpath = join_path(prefix, tree->name);
 
@@ -109,11 +109,11 @@ static void  __attribute__ ((noreturn)) 
 int main(int argc, char *argv[])
 {
 	struct boot_info *bi;
-	char *inform = "dts";
-	char *outform = "dts";
-	char *outname = "-";
+	const char *inform = "dts";
+	const char *outform = "dts";
+	const char *outname = "-";
 	int force = 0, check = 0;
-	char *arg;
+	const char *arg;
 	int opt;
 	FILE *inf = NULL;
 	FILE *outf = NULL;
flattree.c +22 -22

150 lines not on this page · raw message

livetree.c +6 -6
Index: dtc/livetree.c
===================================================================
@@ -180,7 +180,7 @@ struct boot_info *build_boot_info(struct
  * Tree accessor functions
  */
 
-char *get_unitname(struct node *node)
+const char *get_unitname(struct node *node)
 {
 	if (node->name[node->basenamelen] == '\0')
 		return "";
@@ -188,7 +188,7 @@ char *get_unitname(struct node *node)
 		return node->name + node->basenamelen + 1;
 }
 
-struct property *get_property(struct node *node, char *propname)
+struct property *get_property(struct node *node, const char *propname)
 {
 	struct property *prop;
 
@@ -205,7 +205,7 @@ cell_t propval_cell(struct property *pro
 	return be32_to_cpu(*((cell_t *)prop->val.val));
 }
 
-struct node *get_subnode(struct node *node, char *nodename)
+struct node *get_subnode(struct node *node, const char *nodename)
 {
 	struct node *child;
 
@@ -216,9 +216,9 @@ struct node *get_subnode(struct node *no
 	return NULL;
 }
 
-struct node *get_node_by_path(struct node *tree, char *path)
+struct node *get_node_by_path(struct node *tree, const char *path)
 {
-	char *p;
+	const char *p;
 	struct node *child;
 
 	if (!path || ! (*path))
@@ -275,7 +275,7 @@ struct node *get_node_by_phandle(struct 
 	return NULL;
 }
 
-struct node *get_node_by_ref(struct node *tree, char *ref)
+struct node *get_node_by_ref(struct node *tree, const char *ref)
 {
 	if (ref[0] == '/')
 		return get_node_by_path(tree, ref);
dtc.h +12 -12
Index: dtc/dtc.h
===================================================================
@@ -133,14 +133,14 @@ void data_free(struct data d);
 
 struct data data_grow_for(struct data d, int xlen);
 
-struct data data_copy_mem(char *mem, int len);
-struct data data_copy_escape_string(char *s, int len);
+struct data data_copy_mem(const char *mem, int len);
+struct data data_copy_escape_string(const char *s, int len);
 struct data data_copy_file(FILE *f, size_t len);
 
-struct data data_append_data(struct data d, void *p, int len);
+struct data data_append_data(struct data d, const void *p, int len);
 struct data data_merge(struct data d1, struct data d2);
 struct data data_append_cell(struct data d, cell_t word);
-struct data data_append_re(struct data d, struct fdt_reserve_entry *re);
+struct data data_append_re(struct data d, const struct fdt_reserve_entry *re);
 struct data data_append_addr(struct data d, u64 addr);
 struct data data_append_byte(struct data d, uint8_t byte);
 struct data data_append_zeroes(struct data d, int len);
@@ -199,14 +199,14 @@ struct node *chain_node(struct node *fir
 void add_property(struct node *node, struct property *prop);
 void add_child(struct node *parent, struct node *child);
 
-char *get_unitname(struct node *node);
-struct property *get_property(struct node *node, char *propname);
+const char *get_unitname(struct node *node);
+struct property *get_property(struct node *node, const char *propname);
 cell_t propval_cell(struct property *prop);
-struct node *get_subnode(struct node *node, char *nodename);
-struct node *get_node_by_path(struct node *tree, char *path);
+struct node *get_subnode(struct node *node, const char *nodename);
+struct node *get_node_by_path(struct node *tree, const char *path);
 struct node *get_node_by_label(struct node *tree, const char *label);
 struct node *get_node_by_phandle(struct node *tree, cell_t phandle);
-struct node *get_node_by_ref(struct node *tree, char *ref);
+struct node *get_node_by_ref(struct node *tree, const char *ref);
 cell_t get_node_phandle(struct node *root, struct node *node);
 
 /* Boot info (tree plus memreserve information */
@@ -255,11 +255,11 @@ struct boot_info *dt_from_source(const c
 
 /* FS trees */
 
-struct boot_info *dt_from_fs(char *dirname);
+struct boot_info *dt_from_fs(const char *dirname);
 
 /* misc */
 
-char *join_path(char *path, char *name);
-void fill_fullpaths(struct node *tree, char *prefix);
+char *join_path(const char *path, const char *name);
+void fill_fullpaths(struct node *tree, const char *prefix);
 
 #endif /* _DTC_H */
fstree.c +2 -2
Index: dtc/fstree.c
===================================================================
@@ -23,7 +23,7 @@
 #include <dirent.h>
 #include <sys/stat.h>
 
-static struct node *read_fstree(char *dirname)
+static struct node *read_fstree(const char *dirname)
 {
 	DIR *d;
 	struct dirent *de;
@@ -80,7 +80,7 @@ static struct node *read_fstree(char *di
 	return tree;
 }
 
-struct boot_info *dt_from_fs(char *dirname)
+struct boot_info *dt_from_fs(const char *dirname)
 {
 	struct node *tree;
 
treesource.c +3 -3
Index: dtc/treesource.c
===================================================================
@@ -58,7 +58,7 @@ int isstring(char c)
 
 static void write_propval_string(FILE *f, struct data val)
 {
-	char *str = val.val;
+	const char *str = val.val;
 	int i;
 	int newchunk = 1;
 	struct marker *m = val.markers;
@@ -161,7 +161,7 @@ static void write_propval_cells(FILE *f,
 static void write_propval_bytes(FILE *f, struct data val)
 {
 	void *propend = val.val + val.len;
-	char *bp = val.val;
+	const char *bp = val.val;
 	struct marker *m = val.markers;
 
 	fprintf(f, "[");
@@ -189,7 +189,7 @@ static void write_propval_bytes(FILE *f,
 static void write_propval(FILE *f, struct property *prop)
 {
 	int len = prop->val.len;
-	char *p = prop->val.val;
+	const char *p = prop->val.val;
 	struct marker *m = prop->val.markers;
 	int nnotstring = 0, nnul = 0;
 	int nnotstringlbl = 0, nnotcelllbl = 0;
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#1 lore raw

So, like, the other day David Gibson mumbled:

Quoted 5 lines

This adds 'const' qualifiers to many variables and functions. In particular it's now used for passing names to the tree accesor functions.

Typo fixed, rebased and applied.

Thanks,
jdl