summaryrefslogtreecommitdiff
path: root/libfdt
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2007-11-20 13:35:46 +1100
committerJon Loeliger <jdl@freescale.com>2007-11-20 09:00:37 -0600
commit9521dc5ecc66c158cd6853cabba2c29f545780f6 (patch)
tree066c76f58e756bc166b2ed9d670c8975ecc04961 /libfdt
parent682576d85bd159fc25ef99ab35a997fda172592e (diff)
downloaddtc-9521dc5ecc66c158cd6853cabba2c29f545780f6.tar.gz
libfdt: Abolish _typed() variants, add _cell() variants
In a number of places through libfdt and its tests, we have *_typed() macro variants on functions which use gcc's typeof and statement expression extensions to allow passing literals where the underlying function takes a buffer and size. These seemed like a good idea at the time, but in fact they have some problems. They use typeof and statement expressions, extensions I'd prefer to avoid for portability. Plus, they have potential gotchas - although they'll deal with the size of the thing passed, they won't deal with other representation issues (like endianness) and results could be very strange if the type of the expression passed isn't what you think it is. In fact, the only users of these _typed() macros were when the value passed is a single cell (32-bit integer). Therefore, this patch removes all these _typed() macros and replaces them with explicit _cell() variants which handle a single 32-bit integer, and which also perform endian convesions as appropriate. With this in place, it now becomes easy to use standardized big-endian representation for integer valued properties in the testcases, regardless of the platform we're running on. We therefore do that, which has the additional advantage that all the example trees created during a test run are now byte-for-byte identical regardless of platform. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'libfdt')
-rw-r--r--libfdt/libfdt.h33
1 files changed, 17 insertions, 16 deletions
diff --git a/libfdt/libfdt.h b/libfdt/libfdt.h
index d2f8320..a61e50d 100644
--- a/libfdt/libfdt.h
+++ b/libfdt/libfdt.h
@@ -663,12 +663,12 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,
int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
const void *val, int len);
-
-#define fdt_setprop_inplace_typed(fdt, nodeoffset, name, val) \
- ({ \
- typeof(val) x = val; \
- fdt_setprop_inplace(fdt, nodeoffset, name, &x, sizeof(x)); \
- })
+static inline int fdt_setprop_inplace_cell(void *fdt, int nodeoffset,
+ const char *name, uint32_t val)
+{
+ val = cpu_to_fdt32(val);
+ return fdt_setprop_inplace(fdt, nodeoffset, name, &val, sizeof(val));
+}
int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
int fdt_nop_node(void *fdt, int nodeoffset);
@@ -682,11 +682,11 @@ int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);
int fdt_finish_reservemap(void *fdt);
int fdt_begin_node(void *fdt, const char *name);
int fdt_property(void *fdt, const char *name, const void *val, int len);
-#define fdt_property_typed(fdt, name, val) \
- ({ \
- typeof(val) x = (val); \
- fdt_property((fdt), (name), &x, sizeof(x)); \
- })
+static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val)
+{
+ val = cpu_to_fdt32(val);
+ return fdt_property(fdt, name, &val, sizeof(val));
+}
#define fdt_property_string(fdt, name, str) \
fdt_property(fdt, name, str, strlen(str)+1)
int fdt_end_node(void *fdt);
@@ -704,11 +704,12 @@ int fdt_del_mem_rsv(void *fdt, int n);
int fdt_setprop(void *fdt, int nodeoffset, const char *name,
const void *val, int len);
-#define fdt_setprop_typed(fdt, nodeoffset, name, val) \
- ({ \
- typeof(val) x = (val); \
- fdt_setprop((fdt), (nodeoffset), (name), &x, sizeof(x)); \
- })
+static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
+ uint32_t val)
+{
+ val = cpu_to_fdt32(val);
+ return fdt_setprop(fdt, nodeoffset, name, &val, sizeof(val));
+}
#define fdt_setprop_string(fdt, nodeoffset, name, str) \
fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
int fdt_delprop(void *fdt, int nodeoffset, const char *name);