Skip to content

Commit 234b2fb

Browse files
robherringZile995
authored andcommitted
BACKPORT: scripts/dtc: Update to upstream version 9d3649bd3be245c9
Sync dtc with upstream as of commit 9d3649bd3be2 (Add testcases for fdt_path_offset_namelen()). Signed-off-by: Rob Herring <robh@kernel.org> Cc: Grant Likely <grant.likely@linaro.org> Cc: devicetree@vger.kernel.org Signed-off-by: Albert I <kras@raphielgang.org>
1 parent c68a4ec commit 234b2fb

29 files changed

+1743
-1533
lines changed

scripts/dtc/checks.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct check {
5353
void *data;
5454
bool warn, error;
5555
enum checkstatus status;
56-
int inprogress;
56+
bool inprogress;
5757
int num_prereqs;
5858
struct check **prereq;
5959
};
@@ -113,6 +113,7 @@ static inline void check_msg(struct check *c, const char *fmt, ...)
113113
vfprintf(stderr, fmt, ap);
114114
fprintf(stderr, "\n");
115115
}
116+
va_end(ap);
116117
}
117118

118119
#define FAIL(c, ...) \
@@ -141,21 +142,21 @@ static void check_nodes_props(struct check *c, struct node *dt, struct node *nod
141142
check_nodes_props(c, dt, child);
142143
}
143144

144-
static int run_check(struct check *c, struct node *dt)
145+
static bool run_check(struct check *c, struct node *dt)
145146
{
146-
int error = 0;
147+
bool error = false;
147148
int i;
148149

149150
assert(!c->inprogress);
150151

151152
if (c->status != UNCHECKED)
152153
goto out;
153154

154-
c->inprogress = 1;
155+
c->inprogress = true;
155156

156157
for (i = 0; i < c->num_prereqs; i++) {
157158
struct check *prq = c->prereq[i];
158-
error |= run_check(prq, dt);
159+
error = error || run_check(prq, dt);
159160
if (prq->status != PASSED) {
160161
c->status = PREREQ;
161162
check_msg(c, "Failed prerequisite '%s'",
@@ -177,9 +178,9 @@ static int run_check(struct check *c, struct node *dt)
177178
TRACE(c, "\tCompleted, status %d", c->status);
178179

179180
out:
180-
c->inprogress = 0;
181+
c->inprogress = false;
181182
if ((c->status != PASSED) && (c->error))
182-
error = 1;
183+
error = true;
183184
return error;
184185
}
185186

@@ -706,15 +707,15 @@ static void disable_warning_error(struct check *c, bool warn, bool error)
706707
c->error = c->error && !error;
707708
}
708709

709-
void parse_checks_option(bool warn, bool error, const char *optarg)
710+
void parse_checks_option(bool warn, bool error, const char *arg)
710711
{
711712
int i;
712-
const char *name = optarg;
713+
const char *name = arg;
713714
bool enable = true;
714715

715-
if ((strncmp(optarg, "no-", 3) == 0)
716-
|| (strncmp(optarg, "no_", 3) == 0)) {
717-
name = optarg + 3;
716+
if ((strncmp(arg, "no-", 3) == 0)
717+
|| (strncmp(arg, "no_", 3) == 0)) {
718+
name = arg + 3;
718719
enable = false;
719720
}
720721

@@ -733,7 +734,7 @@ void parse_checks_option(bool warn, bool error, const char *optarg)
733734
die("Unrecognized check name \"%s\"\n", name);
734735
}
735736

736-
void process_checks(int force, struct boot_info *bi)
737+
void process_checks(bool force, struct boot_info *bi)
737738
{
738739
struct node *dt = bi->dt;
739740
int i;

scripts/dtc/data.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ struct data data_copy_escape_string(const char *s, int len)
7474
struct data d;
7575
char *q;
7676

77-
d = data_grow_for(empty_data, strlen(s)+1);
77+
d = data_grow_for(empty_data, len + 1);
7878

7979
q = d.val;
8080
while (i < len) {
@@ -250,20 +250,20 @@ struct data data_add_marker(struct data d, enum markertype type, char *ref)
250250
return data_append_markers(d, m);
251251
}
252252

253-
int data_is_one_string(struct data d)
253+
bool data_is_one_string(struct data d)
254254
{
255255
int i;
256256
int len = d.len;
257257

258258
if (len == 0)
259-
return 0;
259+
return false;
260260

261261
for (i = 0; i < len-1; i++)
262262
if (d.val[i] == '\0')
263-
return 0;
263+
return false;
264264

265265
if (d.val[len-1] != '\0')
266-
return 0;
266+
return false;
267267

268-
return 1;
268+
return true;
269269
}

scripts/dtc/dtc-lexer.l

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
%option noyywrap nounput noinput never-interactive
2222

23-
%x INCLUDE
2423
%x BYTESTRING
2524
%x PROPNODENAME
2625
%s V1
@@ -40,6 +39,7 @@ LINECOMMENT "//".*\n
4039
#include "dtc-parser.tab.h"
4140

4241
YYLTYPE yylloc;
42+
extern bool treesource_error;
4343

4444
/* CAUTION: this will stop working if we ever use yyless() or yyunput() */
4545
#define YY_USER_ACTION \
@@ -61,7 +61,8 @@ static int dts_version = 1;
6161
BEGIN(V1); \
6262

6363
static void push_input_file(const char *filename);
64-
static int pop_input_file(void);
64+
static bool pop_input_file(void);
65+
static void lexical_error(const char *fmt, ...);
6566
%}
6667

6768
%%
@@ -75,11 +76,11 @@ static int pop_input_file(void);
7576
char *line, *tmp, *fn;
7677
/* skip text before line # */
7778
line = yytext;
78-
while (!isdigit(*line))
79+
while (!isdigit((unsigned char)*line))
7980
line++;
8081
/* skip digits in line # */
8182
tmp = line;
82-
while (!isspace(*tmp))
83+
while (!isspace((unsigned char)*tmp))
8384
tmp++;
8485
/* "NULL"-terminate line # */
8586
*tmp = '\0';
@@ -146,15 +147,42 @@ static int pop_input_file(void);
146147
}
147148

148149
<V1>([0-9]+|0[xX][0-9a-fA-F]+)(U|L|UL|LL|ULL)? {
149-
yylval.literal = xstrdup(yytext);
150-
DPRINT("Literal: '%s'\n", yylval.literal);
150+
char *e;
151+
DPRINT("Integer Literal: '%s'\n", yytext);
152+
153+
errno = 0;
154+
yylval.integer = strtoull(yytext, &e, 0);
155+
156+
assert(!(*e) || !e[strspn(e, "UL")]);
157+
158+
if (errno == ERANGE)
159+
lexical_error("Integer literal '%s' out of range",
160+
yytext);
161+
else
162+
/* ERANGE is the only strtoull error triggerable
163+
* by strings matching the pattern */
164+
assert(errno == 0);
151165
return DT_LITERAL;
152166
}
153167

154168
<*>{CHAR_LITERAL} {
155-
yytext[yyleng-1] = '\0';
156-
yylval.literal = xstrdup(yytext+1);
157-
DPRINT("Character literal: %s\n", yylval.literal);
169+
struct data d;
170+
DPRINT("Character literal: %s\n", yytext);
171+
172+
d = data_copy_escape_string(yytext+1, yyleng-2);
173+
if (d.len == 1) {
174+
lexical_error("Empty character literal");
175+
yylval.integer = 0;
176+
return DT_CHAR_LITERAL;
177+
}
178+
179+
yylval.integer = (unsigned char)d.val[0];
180+
181+
if (d.len > 2)
182+
lexical_error("Character literal has %d"
183+
" characters instead of 1",
184+
d.len - 1);
185+
158186
return DT_CHAR_LITERAL;
159187
}
160188

@@ -164,7 +192,7 @@ static int pop_input_file(void);
164192
return DT_REF;
165193
}
166194

167-
<*>"&{/"{PATHCHAR}+\} { /* new-style path reference */
195+
<*>"&{/"{PATHCHAR}*\} { /* new-style path reference */
168196
yytext[yyleng-1] = '\0';
169197
DPRINT("Ref: %s\n", yytext+2);
170198
yylval.labelref = xstrdup(yytext+2);
@@ -238,13 +266,24 @@ static void push_input_file(const char *filename)
238266
}
239267

240268

241-
static int pop_input_file(void)
269+
static bool pop_input_file(void)
242270
{
243271
if (srcfile_pop() == 0)
244-
return 0;
272+
return false;
245273

246274
yypop_buffer_state();
247275
yyin = current_srcfile->f;
248276

249-
return 1;
277+
return true;
278+
}
279+
280+
static void lexical_error(const char *fmt, ...)
281+
{
282+
va_list ap;
283+
284+
va_start(ap, fmt);
285+
srcpos_verror(&yylloc, "Lexical error", fmt, ap);
286+
va_end(ap);
287+
288+
treesource_error = true;
250289
}

0 commit comments

Comments
 (0)