From patchwork Mon May 22 22:51:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 765625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wWv6g2vqKz9s3w for ; Tue, 23 May 2017 08:51:54 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B73D7483; Mon, 22 May 2017 22:51:51 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 52837481 for ; Mon, 22 May 2017 22:51:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B7EEF209 for ; Mon, 22 May 2017 22:51:49 +0000 (UTC) Received: from mfilter18-d.gandi.net (mfilter18-d.gandi.net [217.70.178.146]) by relay2-d.mail.gandi.net (Postfix) with ESMTP id 7D619C5A50 for ; Tue, 23 May 2017 00:51:48 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter18-d.gandi.net Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194]) by mfilter18-d.gandi.net (mfilter18-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id UoIfbbiJAW-O for ; Tue, 23 May 2017 00:51:47 +0200 (CEST) X-Originating-IP: 50.204.120.238 Received: from localhost.localdomain (50-204-120-238-static.hfc.comcastbusiness.net [50.204.120.238]) (Authenticated sender: joe@ovn.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 848FCC5A44 for ; Tue, 23 May 2017 00:51:46 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Mon, 22 May 2017 15:51:39 -0700 Message-Id: <20170522225139.3961-1-joe@ovn.org> X-Mailer: git-send-email 2.12.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] checkpatch: Check for stdlib usage. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 Acked-by: Greg Rose --- 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."""