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 <[email protected]>
---
v2: Drop checks for functions that don't replace library functions
    Fix naming of functions xfoo() -> ovs_foo() where appropriate
    Fix descriptions
---
 utilities/checkpatch.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index d486de81c8ff..d1941c441248 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -210,6 +210,34 @@ 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 xcalloc() in place of calloc()'),
+        ('realloc', 'Use xrealloc() in place of realloc()'),
+        ('strdup', 'Use xstrdup() in place of strdup()'),
+        ('asprintf', 'Use xasprintf() in place of asprintf()'),
+        ('vasprintf', 'Use xvasprintf() in place of vasprintf()'),
+        ('strcpy', 'Use ovs_strlcpy() in place of strcpy()'),
+        ('strlcpy', 'Use ovs_strlcpy() in place of strlcpy()'),
+        ('strncpy', 'Use ovs_strzcpy() in place of strncpy()'),
+        ('strerror', 'Use ovs_strerror() in place of strerror()'),
+        ('sleep', 'Use xsleep() in place of sleep()'),
+        ('abort', 'Use ovs_abort() in place of abort()'),
+        ('error', 'Use ovs_error() 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

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to