2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

checkpatch.py: Add checks for easy-to-misuse APIs.

Signed-off-by: Peng He <hepeng.0320@bytedance.com>
Acked-by: Eelco Chaudron <echaudro@redhat.com>
Acked-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
Peng He
2022-05-26 03:13:18 +00:00
committed by Ilya Maximets
parent 805e9340d5
commit 071b802c61
2 changed files with 54 additions and 6 deletions

View File

@@ -620,6 +620,10 @@ def regex_error_factory(description):
return lambda: print_error(description)
def regex_warn_factory(description):
return lambda: print_warning(description)
std_functions = [
('malloc', 'Use xmalloc() in place of malloc()'),
('calloc', 'Use xcalloc() in place of calloc()'),
@@ -636,6 +640,7 @@ std_functions = [
('assert', 'Use ovs_assert() in place of assert()'),
('error', 'Use ovs_error() in place of error()'),
]
checks += [
{'regex': r'(\.c|\.h)(\.in)?$',
'match_name': None,
@@ -644,6 +649,21 @@ checks += [
'print': regex_error_factory(description)}
for (function_name, description) in std_functions]
easy_to_misuse_api = [
('ovsrcu_barrier',
'lib/ovs-rcu.c',
'Are you sure you need to use ovsrcu_barrier(), '
'in most cases ovsrcu_synchronize() will be fine?'),
]
checks += [
{'regex': r'(\.c)(\.in)?$',
'match_name': lambda x: x != location,
'prereq': lambda x: not is_comment_line(x),
'check': regex_function_factory(function_name),
'print': regex_warn_factory(description)}
for (function_name, location, description) in easy_to_misuse_api]
def regex_operator_factory(operator):
regex = re.compile(r'^[^#][^"\']*[^ "]%s[^ "\'][^"]*' % operator)
@@ -676,12 +696,22 @@ def get_file_type_checks(filename):
global checks
checkList = []
for check in checks:
regex_check = True
match_check = True
if check['regex'] is None and check['match_name'] is None:
checkList.append(check)
continue
if check['regex'] is not None and \
re.compile(check['regex']).search(filename) is not None:
checkList.append(check)
elif check['match_name'] is not None and check['match_name'](filename):
re.compile(check['regex']).search(filename) is None:
regex_check = False
if check['match_name'] is not None and \
not check['match_name'](filename):
match_check = False
if regex_check and match_check:
checkList.append(check)
return checkList