Skip to content

Commit e9baef0

Browse files
committed
tracing: Combine enum and arrays into single macro in filter code
Instead of having a separate enum that is the index into another array, like a string array, make a single macro that combines them into a single list, and then the two can not get out of sync. This makes it easier to add and remove items. The macro trick is: #define DOGS \ C( JACK, "Jack Russell") \ C( ITALIAN, "Italian Greyhound") \ C( GERMAN, "German Shepherd") #undef C #define C(a, b) a enum { DOGS }; #undef C #define C(a, b) b static char dogs[] = { DOGS }; Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 567f698 commit e9baef0

File tree

1 file changed

+48
-64
lines changed

1 file changed

+48
-64
lines changed

kernel/trace/trace_events_filter.c

Lines changed: 48 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -33,79 +33,63 @@
3333
"# Only events with the given fields will be affected.\n" \
3434
"# If no events are modified, an error message will be displayed here"
3535

36-
enum filter_op_ids
37-
{
38-
OP_OR,
39-
OP_AND,
40-
OP_GLOB,
41-
OP_NE,
42-
OP_EQ,
43-
OP_LT,
44-
OP_LE,
45-
OP_GT,
46-
OP_GE,
47-
OP_BAND,
48-
OP_NOT,
49-
OP_NONE,
50-
OP_OPEN_PAREN,
51-
};
36+
#define OPS \
37+
C( OP_OR, "||", 1 ), \
38+
C( OP_AND, "&&", 2 ), \
39+
C( OP_GLOB, "~", 4 ), \
40+
C( OP_NE, "!=", 4 ), \
41+
C( OP_EQ, "==", 4 ), \
42+
C( OP_LT, "<", 5 ), \
43+
C( OP_LE, "<=", 5 ), \
44+
C( OP_GT, ">", 5 ), \
45+
C( OP_GE, ">=", 5 ), \
46+
C( OP_BAND, "&", 6 ), \
47+
C( OP_NOT, "!", 6 ), \
48+
C( OP_NONE, "OP_NONE", 0 ), \
49+
C( OP_OPEN_PAREN, "(", 0 ), \
50+
C( OP_MAX, NULL, 0 )
51+
52+
#undef C
53+
#define C(a, b, c) a
54+
55+
enum filter_op_ids { OPS };
5256

5357
struct filter_op {
5458
int id;
5559
char *string;
5660
int precedence;
5761
};
5862

59-
/* Order must be the same as enum filter_op_ids above */
60-
static struct filter_op filter_ops[] = {
61-
{ OP_OR, "||", 1 },
62-
{ OP_AND, "&&", 2 },
63-
{ OP_GLOB, "~", 4 },
64-
{ OP_NE, "!=", 4 },
65-
{ OP_EQ, "==", 4 },
66-
{ OP_LT, "<", 5 },
67-
{ OP_LE, "<=", 5 },
68-
{ OP_GT, ">", 5 },
69-
{ OP_GE, ">=", 5 },
70-
{ OP_BAND, "&", 6 },
71-
{ OP_NOT, "!", 6 },
72-
{ OP_NONE, "OP_NONE", 0 },
73-
{ OP_OPEN_PAREN, "(", 0 },
74-
};
63+
#undef C
64+
#define C(a, b, c) { a, b, c }
7565

76-
enum {
77-
FILT_ERR_NONE,
78-
FILT_ERR_INVALID_OP,
79-
FILT_ERR_UNBALANCED_PAREN,
80-
FILT_ERR_TOO_MANY_OPERANDS,
81-
FILT_ERR_OPERAND_TOO_LONG,
82-
FILT_ERR_FIELD_NOT_FOUND,
83-
FILT_ERR_ILLEGAL_FIELD_OP,
84-
FILT_ERR_ILLEGAL_INTVAL,
85-
FILT_ERR_BAD_SUBSYS_FILTER,
86-
FILT_ERR_TOO_MANY_PREDS,
87-
FILT_ERR_MISSING_FIELD,
88-
FILT_ERR_INVALID_FILTER,
89-
FILT_ERR_IP_FIELD_ONLY,
90-
FILT_ERR_ILLEGAL_NOT_OP,
91-
};
66+
static struct filter_op filter_ops[] = { OPS };
9267

93-
static char *err_text[] = {
94-
"No error",
95-
"Invalid operator",
96-
"Unbalanced parens",
97-
"Too many operands",
98-
"Operand too long",
99-
"Field not found",
100-
"Illegal operation for field type",
101-
"Illegal integer value",
102-
"Couldn't find or set field in one of a subsystem's events",
103-
"Too many terms in predicate expression",
104-
"Missing field name and/or value",
105-
"Meaningless filter expression",
106-
"Only 'ip' field is supported for function trace",
107-
"Illegal use of '!'",
108-
};
68+
#define ERRORS \
69+
C( NONE, "No error"), \
70+
C( INVALID_OP, "Invalid operator"), \
71+
C( UNBALANCED_PAREN, "Unbalanced parens"), \
72+
C( TOO_MANY_OPERANDS, "Too many operands"), \
73+
C( OPERAND_TOO_LONG, "Operand too long"), \
74+
C( FIELD_NOT_FOUND, "Field not found"), \
75+
C( ILLEGAL_FIELD_OP, "Illegal operation for field type"), \
76+
C( ILLEGAL_INTVAL, "Illegal integer value"), \
77+
C( BAD_SUBSYS_FILTER, "Couldn't find or set field in one of a subsystem's events"), \
78+
C( TOO_MANY_PREDS, "Too many terms in predicate expression"), \
79+
C( MISSING_FIELD, "Missing field name and/or value"), \
80+
C( INVALID_FILTER, "Meaningless filter expression"), \
81+
C( IP_FIELD_ONLY, "Only 'ip' field is supported for function trace"), \
82+
C( ILLEGAL_NOT_OP, "Illegal use of '!'"),
83+
84+
#undef C
85+
#define C(a, b) FILT_ERR_##a
86+
87+
enum { ERRORS };
88+
89+
#undef C
90+
#define C(a, b) b
91+
92+
static char *err_text[] = { ERRORS };
10993

11094
struct opstack_op {
11195
enum filter_op_ids op;

0 commit comments

Comments
 (0)