diff mbox

[ovs-dev,PATCHv2] checkpatch: Check for stdlib usage.

Message ID 20170524005716.25105-1-joe@ovn.org
State Accepted
Headers show

Commit Message

Joe Stringer May 24, 2017, 12:57 a.m. UTC
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@ovn.org>
---
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(+)

Comments

Aaron Conole May 25, 2017, 7:02 p.m. UTC | #1
Joe Stringer <joe@ovn.org> writes:

> 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@ovn.org>
> ---
> v2: Drop checks for functions that don't replace library functions
>     Fix naming of functions xfoo() -> ovs_foo() where appropriate
>     Fix descriptions
> ---

This version LGTM.

Acked-by: Aaron Conole <aconole@redhat.com>
Ben Pfaff May 25, 2017, 8:10 p.m. UTC | #2
On Tue, May 23, 2017 at 05:57:16PM -0700, Joe Stringer wrote:
> 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@ovn.org>

Acked-by: Ben Pfaff <blp@ovn.org>
diff mbox

Patch

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."""