Skip to content

Commit 121fd33

Browse files
vishalc-ibmborkmann
authored andcommitted
bpf, docs: Fix invalid escape sequence warnings in bpf_doc.py
The script bpf_doc.py generates multiple SyntaxWarnings related to invalid escape sequences when executed with Python 3.12. These warnings do not appear in Python 3.10 and 3.11 and do not affect the kernel build, which completes successfully. This patch resolves these SyntaxWarnings by converting the relevant string literals to raw strings or by escaping backslashes. This ensures that backslashes are interpreted as literal characters, eliminating the warnings. Reported-by: Srikar Dronamraju <[email protected]> Signed-off-by: Vishal Chourasia <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Tested-by: Quentin Monnet <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 3e019d8 commit 121fd33

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

scripts/bpf_doc.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def proto_break_down(self):
5959
Break down helper function protocol into smaller chunks: return type,
6060
name, distincts arguments.
6161
"""
62-
arg_re = re.compile('((\w+ )*?(\w+|...))( (\**)(\w+))?$')
62+
arg_re = re.compile(r'((\w+ )*?(\w+|...))( (\**)(\w+))?$')
6363
res = {}
64-
proto_re = re.compile('(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$')
64+
proto_re = re.compile(r'(.+) (\**)(\w+)\(((([^,]+)(, )?){1,5})\)$')
6565

6666
capture = proto_re.match(self.proto)
6767
res['ret_type'] = capture.group(1)
@@ -114,11 +114,11 @@ def parse_helper(self):
114114
return Helper(proto=proto, desc=desc, ret=ret)
115115

116116
def parse_symbol(self):
117-
p = re.compile(' \* ?(BPF\w+)$')
117+
p = re.compile(r' \* ?(BPF\w+)$')
118118
capture = p.match(self.line)
119119
if not capture:
120120
raise NoSyscallCommandFound
121-
end_re = re.compile(' \* ?NOTES$')
121+
end_re = re.compile(r' \* ?NOTES$')
122122
end = end_re.match(self.line)
123123
if end:
124124
raise NoSyscallCommandFound
@@ -133,15 +133,15 @@ def parse_proto(self):
133133
# - Same as above, with "const" and/or "struct" in front of type
134134
# - "..." (undefined number of arguments, for bpf_trace_printk())
135135
# There is at least one term ("void"), and at most five arguments.
136-
p = re.compile(' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$')
136+
p = re.compile(r' \* ?((.+) \**\w+\((((const )?(struct )?(\w+|\.\.\.)( \**\w+)?)(, )?){1,5}\))$')
137137
capture = p.match(self.line)
138138
if not capture:
139139
raise NoHelperFound
140140
self.line = self.reader.readline()
141141
return capture.group(1)
142142

143143
def parse_desc(self, proto):
144-
p = re.compile(' \* ?(?:\t| {5,8})Description$')
144+
p = re.compile(r' \* ?(?:\t| {5,8})Description$')
145145
capture = p.match(self.line)
146146
if not capture:
147147
raise Exception("No description section found for " + proto)
@@ -154,7 +154,7 @@ def parse_desc(self, proto):
154154
if self.line == ' *\n':
155155
desc += '\n'
156156
else:
157-
p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')
157+
p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')
158158
capture = p.match(self.line)
159159
if capture:
160160
desc_present = True
@@ -167,7 +167,7 @@ def parse_desc(self, proto):
167167
return desc
168168

169169
def parse_ret(self, proto):
170-
p = re.compile(' \* ?(?:\t| {5,8})Return$')
170+
p = re.compile(r' \* ?(?:\t| {5,8})Return$')
171171
capture = p.match(self.line)
172172
if not capture:
173173
raise Exception("No return section found for " + proto)
@@ -180,7 +180,7 @@ def parse_ret(self, proto):
180180
if self.line == ' *\n':
181181
ret += '\n'
182182
else:
183-
p = re.compile(' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')
183+
p = re.compile(r' \* ?(?:\t| {5,8})(?:\t| {8})(.*)')
184184
capture = p.match(self.line)
185185
if capture:
186186
ret_present = True
@@ -219,12 +219,12 @@ def parse_enum_syscall(self):
219219
self.seek_to('enum bpf_cmd {',
220220
'Could not find start of bpf_cmd enum', 0)
221221
# Searches for either one or more BPF\w+ enums
222-
bpf_p = re.compile('\s*(BPF\w+)+')
222+
bpf_p = re.compile(r'\s*(BPF\w+)+')
223223
# Searches for an enum entry assigned to another entry,
224224
# for e.g. BPF_PROG_RUN = BPF_PROG_TEST_RUN, which is
225225
# not documented hence should be skipped in check to
226226
# determine if the right number of syscalls are documented
227-
assign_p = re.compile('\s*(BPF\w+)\s*=\s*(BPF\w+)')
227+
assign_p = re.compile(r'\s*(BPF\w+)\s*=\s*(BPF\w+)')
228228
bpf_cmd_str = ''
229229
while True:
230230
capture = assign_p.match(self.line)
@@ -239,7 +239,7 @@ def parse_enum_syscall(self):
239239
break
240240
self.line = self.reader.readline()
241241
# Find the number of occurences of BPF\w+
242-
self.enum_syscalls = re.findall('(BPF\w+)+', bpf_cmd_str)
242+
self.enum_syscalls = re.findall(r'(BPF\w+)+', bpf_cmd_str)
243243

244244
def parse_desc_helpers(self):
245245
self.seek_to(helpersDocStart,
@@ -263,7 +263,7 @@ def parse_define_helpers(self):
263263
self.seek_to('#define ___BPF_FUNC_MAPPER(FN, ctx...)',
264264
'Could not find start of eBPF helper definition list')
265265
# Searches for one FN(\w+) define or a backslash for newline
266-
p = re.compile('\s*FN\((\w+), (\d+), ##ctx\)|\\\\')
266+
p = re.compile(r'\s*FN\((\w+), (\d+), ##ctx\)|\\\\')
267267
fn_defines_str = ''
268268
i = 0
269269
while True:
@@ -278,7 +278,7 @@ def parse_define_helpers(self):
278278
break
279279
self.line = self.reader.readline()
280280
# Find the number of occurences of FN(\w+)
281-
self.define_unique_helpers = re.findall('FN\(\w+, \d+, ##ctx\)', fn_defines_str)
281+
self.define_unique_helpers = re.findall(r'FN\(\w+, \d+, ##ctx\)', fn_defines_str)
282282

283283
def validate_helpers(self):
284284
last_helper = ''
@@ -425,7 +425,7 @@ def get_last_doc_update(self, delimiter):
425425
try:
426426
cmd = ['git', 'log', '-1', '--pretty=format:%cs', '--no-patch',
427427
'-L',
428-
'/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)]
428+
'/{}/,/\\*\\//:include/uapi/linux/bpf.h'.format(delimiter)]
429429
date = subprocess.run(cmd, cwd=linuxRoot,
430430
capture_output=True, check=True)
431431
return date.stdout.decode().rstrip()
@@ -516,7 +516,7 @@ def print_footer(self):
516516
programs that are compatible with the GNU Privacy License (GPL).
517517
518518
In order to use such helpers, the eBPF program must be loaded with the correct
519-
license string passed (via **attr**) to the **bpf**\ () system call, and this
519+
license string passed (via **attr**) to the **bpf**\\ () system call, and this
520520
generally translates into the C source code of the program containing a line
521521
similar to the following:
522522
@@ -550,7 +550,7 @@ def print_footer(self):
550550
* The bpftool utility can be used to probe the availability of helper functions
551551
on the system (as well as supported program and map types, and a number of
552552
other parameters). To do so, run **bpftool feature probe** (see
553-
**bpftool-feature**\ (8) for details). Add the **unprivileged** keyword to
553+
**bpftool-feature**\\ (8) for details). Add the **unprivileged** keyword to
554554
list features available to unprivileged users.
555555
556556
Compatibility between helper functions and program types can generally be found
@@ -562,23 +562,23 @@ def print_footer(self):
562562
requirement for GPL license is also in those **struct bpf_func_proto**.
563563
564564
Compatibility between helper functions and map types can be found in the
565-
**check_map_func_compatibility**\ () function in file *kernel/bpf/verifier.c*.
565+
**check_map_func_compatibility**\\ () function in file *kernel/bpf/verifier.c*.
566566
567567
Helper functions that invalidate the checks on **data** and **data_end**
568568
pointers for network processing are listed in function
569-
**bpf_helper_changes_pkt_data**\ () in file *net/core/filter.c*.
569+
**bpf_helper_changes_pkt_data**\\ () in file *net/core/filter.c*.
570570
571571
SEE ALSO
572572
========
573573
574-
**bpf**\ (2),
575-
**bpftool**\ (8),
576-
**cgroups**\ (7),
577-
**ip**\ (8),
578-
**perf_event_open**\ (2),
579-
**sendmsg**\ (2),
580-
**socket**\ (7),
581-
**tc-bpf**\ (8)'''
574+
**bpf**\\ (2),
575+
**bpftool**\\ (8),
576+
**cgroups**\\ (7),
577+
**ip**\\ (8),
578+
**perf_event_open**\\ (2),
579+
**sendmsg**\\ (2),
580+
**socket**\\ (7),
581+
**tc-bpf**\\ (8)'''
582582
print(footer)
583583

584584
def print_proto(self, helper):
@@ -598,7 +598,7 @@ def print_proto(self, helper):
598598
one_arg = '{}{}'.format(comma, a['type'])
599599
if a['name']:
600600
if a['star']:
601-
one_arg += ' {}**\ '.format(a['star'].replace('*', '\\*'))
601+
one_arg += ' {}**\\ '.format(a['star'].replace('*', '\\*'))
602602
else:
603603
one_arg += '** '
604604
one_arg += '*{}*\\ **'.format(a['name'])

0 commit comments

Comments
 (0)