From patchwork Wed Nov 18 21:18:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1402552 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cbwfm6kJNz9sSs for ; Thu, 19 Nov 2020 08:19:12 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 1666086FCC; Wed, 18 Nov 2020 21:19:09 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2ymQzyURvXPR; Wed, 18 Nov 2020 21:19:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id 6B27686FBB; Wed, 18 Nov 2020 21:19:08 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 4B7B1C0800; Wed, 18 Nov 2020 21:19:08 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 29432C07FF for ; Wed, 18 Nov 2020 21:19:07 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 10DAF204E8 for ; Wed, 18 Nov 2020 21:19:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id I2WVAR4GtxTr for ; Wed, 18 Nov 2020 21:19:05 +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 silver.osuosl.org (Postfix) with ESMTPS id 15DB2204D3 for ; Wed, 18 Nov 2020 21:19:04 +0000 (UTC) X-Originating-IP: 78.45.89.65 Received: from im-t490s.redhat.com (ip-78-45-89-65.net.upcbroadband.cz [78.45.89.65]) (Authenticated sender: i.maximets@ovn.org) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id D086340003; Wed, 18 Nov 2020 21:19:00 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Wed, 18 Nov 2020 22:18:58 +0100 Message-Id: <20201118211858.1362812-1-i.maximets@ovn.org> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Cc: Ilya Maximets Subject: [ovs-dev] [PATCH] checkpatch: Add check for a whitespace after cast. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Coding style says: "Put a space between the ``()`` used in a cast and the expression whose type is cast: ``(void *) 0``.". This style rule is frequently overlooked. Let's check for it. Signed-off-by: Ilya Maximets Acked-by: Ian Stokes --- tests/checkpatch.at | 17 +++++++++++++++++ utilities/checkpatch.py | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/checkpatch.at b/tests/checkpatch.at index 6c7394772..a51e46e7a 100755 --- a/tests/checkpatch.at +++ b/tests/checkpatch.at @@ -326,3 +326,20 @@ try_checkpatch \ " AT_CLEANUP + +AT_SETUP([checkpatch - whitespace around cast]) +try_checkpatch \ + "COMMON_PATCH_HEADER + + (int) a; + " + +try_checkpatch \ + "COMMON_PATCH_HEADER + + (int)a; + " \ + "ERROR: Inappropriate spacing around cast + #8 FILE: A.c:1: + (int)a; +" + +AT_CLEANUP diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index ed231fa6f..681de12ce 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -167,6 +167,7 @@ __regex_is_for_if_single_line_bracket = \ __regex_ends_with_bracket = \ re.compile(r'[^\s]\) {(\s+/\*[\s\Sa-zA-Z0-9\.,\?\*/+-]*)?$') __regex_ptr_declaration_missing_whitespace = re.compile(r'[a-zA-Z0-9]\*[^*]') +__regex_cast_missing_whitespace = re.compile(r'\)[a-zA-Z0-9]') __regex_is_comment_line = re.compile(r'^\s*(/\*|\*\s)') __regex_has_comment = re.compile(r'.*(/\*|\*\s)') __regex_has_c99_comment = re.compile(r'.*//.*$') @@ -286,6 +287,12 @@ def pointer_whitespace_check(line): return __regex_ptr_declaration_missing_whitespace.search(line) is not None +def cast_whitespace_check(line): + """Return TRUE if there is no space between the '()' used in a cast and + the expression whose type is cast, i.e.: '(void *)foo'""" + return __regex_cast_missing_whitespace.search(line) is not None + + def line_length_check(line): """Return TRUE if the line length is too long""" if len(line) > 79: @@ -551,6 +558,12 @@ checks = [ 'print': lambda: print_error("Inappropriate spacing in pointer declaration")}, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, + 'prereq': lambda x: not is_comment_line(x), + 'check': lambda x: cast_whitespace_check(x), + 'print': + lambda: print_error("Inappropriate spacing around cast")}, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: not is_comment_line(x), 'check': lambda x: trailing_operator(x),