Deleted Added
full compact
fdt.c (204431) fdt.c (204433)
1/*
2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
4 *
5 * libfdt is dual licensed: you can use it either under the terms of
6 * the GPL, or the BSD license, at your option.
7 *
8 * a) This library is free software; you can redistribute it and/or

--- 60 unchanged lines hidden (view full) ---

69 return -FDT_ERR_BADSTATE;
70 } else {
71 return -FDT_ERR_BADMAGIC;
72 }
73
74 return 0;
75}
76
1/*
2 * libfdt - Flat Device Tree manipulation
3 * Copyright (C) 2006 David Gibson, IBM Corporation.
4 *
5 * libfdt is dual licensed: you can use it either under the terms of
6 * the GPL, or the BSD license, at your option.
7 *
8 * a) This library is free software; you can redistribute it and/or

--- 60 unchanged lines hidden (view full) ---

69 return -FDT_ERR_BADSTATE;
70 } else {
71 return -FDT_ERR_BADMAGIC;
72 }
73
74 return 0;
75}
76
77const void *fdt_offset_ptr(const void *fdt, int offset, int len)
77const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
78{
79 const char *p;
80
81 if (fdt_version(fdt) >= 0x11)
82 if (((offset + len) < offset)
83 || ((offset + len) > fdt_size_dt_struct(fdt)))
84 return NULL;
85
86 p = _fdt_offset_ptr(fdt, offset);
87
88 if (p + len < p)
89 return NULL;
90 return p;
91}
92
78{
79 const char *p;
80
81 if (fdt_version(fdt) >= 0x11)
82 if (((offset + len) < offset)
83 || ((offset + len) > fdt_size_dt_struct(fdt)))
84 return NULL;
85
86 p = _fdt_offset_ptr(fdt, offset);
87
88 if (p + len < p)
89 return NULL;
90 return p;
91}
92
93uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset)
93uint32_t fdt_next_tag(const void *fdt, int startoffset, int *nextoffset)
94{
95 const uint32_t *tagp, *lenp;
96 uint32_t tag;
94{
95 const uint32_t *tagp, *lenp;
96 uint32_t tag;
97 int offset = startoffset;
97 const char *p;
98
98 const char *p;
99
99 if (offset % FDT_TAGSIZE)
100 return -1;
101
100 *nextoffset = -FDT_ERR_TRUNCATED;
102 tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);
101 tagp = fdt_offset_ptr(fdt, offset, FDT_TAGSIZE);
103 if (! tagp)
102 if (!tagp)
104 return FDT_END; /* premature end */
105 tag = fdt32_to_cpu(*tagp);
106 offset += FDT_TAGSIZE;
107
103 return FDT_END; /* premature end */
104 tag = fdt32_to_cpu(*tagp);
105 offset += FDT_TAGSIZE;
106
107 *nextoffset = -FDT_ERR_BADSTRUCTURE;
108 switch (tag) {
109 case FDT_BEGIN_NODE:
110 /* skip name */
111 do {
112 p = fdt_offset_ptr(fdt, offset++, 1);
113 } while (p && (*p != '\0'));
108 switch (tag) {
109 case FDT_BEGIN_NODE:
110 /* skip name */
111 do {
112 p = fdt_offset_ptr(fdt, offset++, 1);
113 } while (p && (*p != '\0'));
114 if (! p)
115 return FDT_END;
114 if (!p)
115 return FDT_END; /* premature end */
116 break;
116 break;
117
117 case FDT_PROP:
118 lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
118 case FDT_PROP:
119 lenp = fdt_offset_ptr(fdt, offset, sizeof(*lenp));
119 if (! lenp)
120 return FDT_END;
121 /* skip name offset, length and value */
122 offset += 2*FDT_TAGSIZE + fdt32_to_cpu(*lenp);
120 if (!lenp)
121 return FDT_END; /* premature end */
122 /* skip-name offset, length and value */
123 offset += sizeof(struct fdt_property) - FDT_TAGSIZE
124 + fdt32_to_cpu(*lenp);
123 break;
125 break;
126
127 case FDT_END:
128 case FDT_END_NODE:
129 case FDT_NOP:
130 break;
131
132 default:
133 return FDT_END;
124 }
125
134 }
135
126 if (nextoffset)
127 *nextoffset = FDT_TAGALIGN(offset);
136 if (!fdt_offset_ptr(fdt, startoffset, offset - startoffset))
137 return FDT_END; /* premature end */
128
138
139 *nextoffset = FDT_TAGALIGN(offset);
129 return tag;
130}
131
132int _fdt_check_node_offset(const void *fdt, int offset)
133{
134 if ((offset < 0) || (offset % FDT_TAGSIZE)
135 || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
136 return -FDT_ERR_BADOFFSET;

--- 20 unchanged lines hidden (view full) ---

157 break;
158
159 case FDT_BEGIN_NODE:
160 if (depth)
161 (*depth)++;
162 break;
163
164 case FDT_END_NODE:
140 return tag;
141}
142
143int _fdt_check_node_offset(const void *fdt, int offset)
144{
145 if ((offset < 0) || (offset % FDT_TAGSIZE)
146 || (fdt_next_tag(fdt, offset, &offset) != FDT_BEGIN_NODE))
147 return -FDT_ERR_BADOFFSET;

--- 20 unchanged lines hidden (view full) ---

168 break;
169
170 case FDT_BEGIN_NODE:
171 if (depth)
172 (*depth)++;
173 break;
174
175 case FDT_END_NODE:
165 if (depth)
166 (*depth)--;
176 if (depth && ((--(*depth)) < 0))
177 return nextoffset;
167 break;
168
169 case FDT_END:
178 break;
179
180 case FDT_END:
170 return -FDT_ERR_NOTFOUND;
171
172 default:
173 return -FDT_ERR_BADSTRUCTURE;
181 if ((nextoffset >= 0)
182 || ((nextoffset == -FDT_ERR_TRUNCATED) && !depth))
183 return -FDT_ERR_NOTFOUND;
184 else
185 return nextoffset;
174 }
175 } while (tag != FDT_BEGIN_NODE);
176
177 return offset;
178}
179
180const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
181{

--- 20 unchanged lines hidden ---
186 }
187 } while (tag != FDT_BEGIN_NODE);
188
189 return offset;
190}
191
192const char *_fdt_find_string(const char *strtab, int tabsize, const char *s)
193{

--- 20 unchanged lines hidden ---