Skip to content

Commit 6f96674

Browse files
qmonnetborkmann
authored andcommitted
bpf: relax constraints on formatting for eBPF helper documentation
The Python script used to parse and extract eBPF helpers documentation from include/uapi/linux/bpf.h expects a very specific formatting for the descriptions (single dot represents a space, '>' stands for a tab): /* ... *.int bpf_helper(list of arguments) *.> Description *.> > Start of description *.> > Another line of description *.> > And yet another line of description *.> Return *.> > 0 on success, or a negative error in case of failure ... */ This is too strict, and painful for developers who wants to add documentation for new helpers. Worse, it is extremely difficult to check that the formatting is correct during reviews. Change the format expected by the script and make it more flexible. The script now works whether or not the initial space (right after the star) is present, and accepts both tabs and white spaces (or a combination of both) for indenting description sections and contents. Concretely, something like the following would now be supported: /* ... *int bpf_helper(list of arguments) *......Description *.> > Start of description... *> > Another line of description *..............And yet another line of description *> Return *.> ........0 on success, or a negative error in case of failure ... */ While at it, remove unnecessary carets from each regex used with match() in the script. They are redundant, as match() tries to match from the beginning of the string by default. v2: Remove unnecessary caret when a regex is used with match(). Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent a2c7a98 commit 6f96674

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

scripts/bpf_helpers_doc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def proto_break_down(self):
3939
Break down helper function protocol into smaller chunks: return type,
4040
name, distincts arguments.
4141
"""
42-
arg_re = re.compile('^((const )?(struct )?(\w+|...))( (\**)(\w+))?$')
42+
arg_re = re.compile('((const )?(struct )?(\w+|...))( (\**)(\w+))?$')
4343
res = {}
44-
proto_re = re.compile('^(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$')
44+
proto_re = re.compile('(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$')
4545

4646
capture = proto_re.match(self.proto)
4747
res['ret_type'] = capture.group(1)
@@ -87,15 +87,15 @@ def parse_proto(self):
8787
# - Same as above, with "const" and/or "struct" in front of type
8888
# - "..." (undefined number of arguments, for bpf_trace_printk())
8989
# There is at least one term ("void"), and at most five arguments.
90-
p = re.compile('^ \* ((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$')
90+
p = re.compile(' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$')
9191
capture = p.match(self.line)
9292
if not capture:
9393
raise NoHelperFound
9494
self.line = self.reader.readline()
9595
return capture.group(1)
9696

9797
def parse_desc(self):
98-
p = re.compile('^ \* \tDescription$')
98+
p = re.compile(' \* ?(?:\t| {6,8})Description$')
9999
capture = p.match(self.line)
100100
if not capture:
101101
# Helper can have empty description and we might be parsing another
@@ -109,7 +109,7 @@ def parse_desc(self):
109109
if self.line == ' *\n':
110110
desc += '\n'
111111
else:
112-
p = re.compile('^ \* \t\t(.*)')
112+
p = re.compile(' \* ?(?:\t| {6,8})(?:\t| {8})(.*)')
113113
capture = p.match(self.line)
114114
if capture:
115115
desc += capture.group(1) + '\n'
@@ -118,7 +118,7 @@ def parse_desc(self):
118118
return desc
119119

120120
def parse_ret(self):
121-
p = re.compile('^ \* \tReturn$')
121+
p = re.compile(' \* ?(?:\t| {6,8})Return$')
122122
capture = p.match(self.line)
123123
if not capture:
124124
# Helper can have empty retval and we might be parsing another
@@ -132,7 +132,7 @@ def parse_ret(self):
132132
if self.line == ' *\n':
133133
ret += '\n'
134134
else:
135-
p = re.compile('^ \* \t\t(.*)')
135+
p = re.compile(' \* ?(?:\t| {6,8})(?:\t| {8})(.*)')
136136
capture = p.match(self.line)
137137
if capture:
138138
ret += capture.group(1) + '\n'

0 commit comments

Comments
 (0)