Skip to content

Commit

Permalink
Remove leading underscores from identifiers
Browse files Browse the repository at this point in the history
In a number of places, dtc and associated tools and test code use
leading _ characters on identifiers to flag them as "internal", an
idiom taken from the Linux kernel.  This is a bad idea in a userspace
program, because identifiers with a leading _ are reserved for the C
library / system.

In some cases, the extra _ served no real purpose, so simply drop it.  In
others move to the end of the identifier, which is a convention we're free
to use for our own purposes.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
dgibson committed Oct 26, 2017
1 parent 2d45d1c commit 3b62fda
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 43 deletions.
32 changes: 16 additions & 16 deletions checks.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ struct check {
struct check **prereq;
};

#define CHECK_ENTRY(_nm, _fn, _d, _w, _e, ...) \
static struct check *_nm##_prereqs[] = { __VA_ARGS__ }; \
static struct check _nm = { \
.name = #_nm, \
.fn = (_fn), \
.data = (_d), \
.warn = (_w), \
.error = (_e), \
#define CHECK_ENTRY(nm_, fn_, d_, w_, e_, ...) \
static struct check *nm_##_prereqs[] = { __VA_ARGS__ }; \
static struct check nm_ = { \
.name = #nm_, \
.fn = (fn_), \
.data = (d_), \
.warn = (w_), \
.error = (e_), \
.status = UNCHECKED, \
.num_prereqs = ARRAY_SIZE(_nm##_prereqs), \
.prereq = _nm##_prereqs, \
.num_prereqs = ARRAY_SIZE(nm_##_prereqs), \
.prereq = nm_##_prereqs, \
};
#define WARNING(_nm, _fn, _d, ...) \
CHECK_ENTRY(_nm, _fn, _d, true, false, __VA_ARGS__)
#define ERROR(_nm, _fn, _d, ...) \
CHECK_ENTRY(_nm, _fn, _d, false, true, __VA_ARGS__)
#define CHECK(_nm, _fn, _d, ...) \
CHECK_ENTRY(_nm, _fn, _d, false, false, __VA_ARGS__)
#define WARNING(nm_, fn_, d_, ...) \
CHECK_ENTRY(nm_, fn_, d_, true, false, __VA_ARGS__)
#define ERROR(nm_, fn_, d_, ...) \
CHECK_ENTRY(nm_, fn_, d_, false, true, __VA_ARGS__)
#define CHECK(nm_, fn_, d_, ...) \
CHECK_ENTRY(nm_, fn_, d_, false, false, __VA_ARGS__)

static inline void PRINTF(3, 4) check_msg(struct check *c, struct dt_info *dti,
const char *fmt, ...)
Expand Down
6 changes: 3 additions & 3 deletions dtc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _DTC_H
#define _DTC_H
#ifndef DTC_H
#define DTC_H

/*
* (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
Expand Down Expand Up @@ -289,4 +289,4 @@ struct dt_info *dt_from_source(const char *f);

struct dt_info *dt_from_fs(const char *dirname);

#endif /* _DTC_H */
#endif /* DTC_H */
6 changes: 3 additions & 3 deletions fdtput.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static int encode_value(struct display_info *disp, char **arg, int arg_count,

#define ALIGN(x) (((x) + (FDT_TAGSIZE) - 1) & ~((FDT_TAGSIZE) - 1))

static char *_realloc_fdt(char *fdt, int delta)
static char *realloc_fdt(char *fdt, int delta)
{
int new_sz = fdt_totalsize(fdt) + delta;
fdt = xrealloc(fdt, new_sz);
Expand All @@ -144,7 +144,7 @@ static char *realloc_node(char *fdt, const char *name)
/* FDT_BEGIN_NODE, node name in off_struct and FDT_END_NODE */
delta = sizeof(struct fdt_node_header) + ALIGN(strlen(name) + 1)
+ FDT_TAGSIZE;
return _realloc_fdt(fdt, delta);
return realloc_fdt(fdt, delta);
}

static char *realloc_property(char *fdt, int nodeoffset,
Expand All @@ -161,7 +161,7 @@ static char *realloc_property(char *fdt, int nodeoffset,
/* actual value in off_struct */
delta += ALIGN(newlen) - ALIGN(oldlen);

return _realloc_fdt(fdt, delta);
return realloc_fdt(fdt, delta);
}

static int store_key_value(char **blob, const char *node_name,
Expand Down
6 changes: 3 additions & 3 deletions srcpos.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* USA
*/

#ifndef _SRCPOS_H_
#define _SRCPOS_H_
#ifndef SRCPOS_H
#define SRCPOS_H

#include <stdio.h>
#include <stdbool.h>
Expand Down Expand Up @@ -114,4 +114,4 @@ extern void PRINTF(3, 4) srcpos_error(struct srcpos *pos, const char *prefix,

extern void srcpos_set_line(char *f, int l);

#endif /* _SRCPOS_H_ */
#endif /* SRCPOS_H */
2 changes: 1 addition & 1 deletion tests/dumptrees.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static struct {
void *blob;
const char *filename;
} trees[] = {
#define TREE(name) { &_##name, #name ".dtb" }
#define TREE(name) { &name, #name ".dtb" }
TREE(test_tree1),
TREE(bad_node_char), TREE(bad_node_format), TREE(bad_prop_char),
TREE(ovf_size_strings),
Expand Down
12 changes: 6 additions & 6 deletions tests/testdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#define TEST_CHAR5 '\xff'

#ifndef __ASSEMBLY__
extern struct fdt_header _test_tree1;
extern struct fdt_header _truncated_property;
extern struct fdt_header _bad_node_char;
extern struct fdt_header _bad_node_format;
extern struct fdt_header _bad_prop_char;
extern struct fdt_header _ovf_size_strings;
extern struct fdt_header test_tree1;
extern struct fdt_header truncated_property;
extern struct fdt_header bad_node_char;
extern struct fdt_header bad_node_format;
extern struct fdt_header bad_prop_char;
extern struct fdt_header ovf_size_strings;
#endif /* ! __ASSEMBLY */
6 changes: 3 additions & 3 deletions tests/tests.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _TESTS_H
#define _TESTS_H
#ifndef TESTS_H
#define TESTS_H
/*
* libfdt - Flat Device Tree manipulation
* Testcase definitions
Expand Down Expand Up @@ -126,4 +126,4 @@ void *open_blob_rw(void *blob);

#include "util.h"

#endif /* _TESTS_H */
#endif /* TESTS_H */
6 changes: 2 additions & 4 deletions tests/trees.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#define TREE_HDR(tree) \
.balign 8 ; \
.globl _##tree ; \
_##tree: \
.globl tree ; \
tree: \
FDTLONG(FDT_MAGIC) ; \
FDTLONG(tree##_end - tree) ; \
Expand Down Expand Up @@ -208,8 +207,7 @@ bad_prop_char_end:

/* overflow_size_strings */
.balign 8
.globl _ovf_size_strings
_ovf_size_strings:
.globl ovf_size_strings
ovf_size_strings:
FDTLONG(FDT_MAGIC)
FDTLONG(ovf_size_strings_end - ovf_size_strings)
Expand Down
2 changes: 1 addition & 1 deletion tests/truncated_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

int main(int argc, char *argv[])
{
void *fdt = &_truncated_property;
void *fdt = &truncated_property;
const void *prop;
int len;

Expand Down
6 changes: 3 additions & 3 deletions util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _UTIL_H
#define _UTIL_H
#ifndef UTIL_H
#define UTIL_H

#include <stdarg.h>
#include <stdbool.h>
Expand Down Expand Up @@ -263,4 +263,4 @@ void NORETURN util_usage(const char *errmsg, const char *synopsis,
case 'V': util_version(); \
case '?': usage("unknown option");

#endif /* _UTIL_H */
#endif /* UTIL_H */

0 comments on commit 3b62fda

Please sign in to comment.