[ovs-dev] [PATCH] checkpatch: Check for stdlib usage.
Joe Stringer
joe at ovn.org
Mon May 22 22:51:39 UTC 2017
Many standard library functions are wrapped in OVS, so check for usage
of the original versions and suggest that authors replace them with the
OVS versions.
Signed-off-by: Joe Stringer <joe at ovn.org>
---
utilities/checkpatch.py | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index d486de81c8ff..4e2f5a42817f 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -210,6 +210,37 @@ checks = [
]
+def regex_function_factory(func_name):
+ regex = re.compile('[^x]%s\([^)]*\)' % func_name)
+ return lambda x: regex.search(x) is not None
+
+
+std_functions = [
+ ('malloc', 'Use xmalloc() in place of malloc()'),
+ ('calloc', 'Use xcmalloc() in place of calloc()'),
+ ('zalloc', 'Use xzmalloc() in place of zalloc()'),
+ ('realloc', 'Use xrealloc() in place of realloc()'),
+ ('memdup', 'Use xmemdup() in place of memdup()'),
+ ('memdup0', 'Use xmemdup0() in place of memdup0()'),
+ ('strdup', 'Use xstrdup() in place of strdup()'),
+ ('asprintf', 'Use xasprintf() in place of asprintf()'),
+ ('vasprintf', 'Use xvasprintf() in place of vasprintf()'),
+ ('2nrealloc', 'Use x2nrealloc() in place of 2nrealloc()'),
+ ('strlcpy', 'Use ovs_strlcpy() in place of strlcpy()'),
+ ('strzcpy', 'Use ovs_strzcpy() in place of strzcpy()'),
+ ('strerror', 'Use ovs_strerror() in place of strerror()'),
+ ('sleep', 'Use xsleep() in place of sleep()'),
+ ('abort', 'Use xabort() in place of abort()'),
+ ('error', 'Use xerror() in place of error()'),
+]
+checks += [
+ {'regex': '(.c|.h)(.in)?$',
+ 'match_name': None,
+ 'check': regex_function_factory(function_name),
+ 'print': lambda: print_error(description)}
+for function_name, description in std_functions]
+
+
def get_file_type_checks(filename):
"""Returns the list of checks for a file based on matching the filename
against regex."""
--
2.12.2
More information about the dev
mailing list