From patchwork Thu May 26 03:13:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng He X-Patchwork-Id: 1635722 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=XeWy67ii; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L7tLc3B0Tz9s75 for ; Thu, 26 May 2022 13:13:44 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 82D6B8452C; Thu, 26 May 2022 03:13:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id glFp7wZHaafU; Thu, 26 May 2022 03:13:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 95B6684521; Thu, 26 May 2022 03:13:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5A020C002D; Thu, 26 May 2022 03:13:40 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 82FA8C002D for ; Thu, 26 May 2022 03:13:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id C60B5613FE for ; Thu, 26 May 2022 03:13:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ti12kMwMvcaR for ; Thu, 26 May 2022 03:13:34 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by smtp3.osuosl.org (Postfix) with ESMTPS id AC6ED613FC for ; Thu, 26 May 2022 03:13:34 +0000 (UTC) Received: by mail-pf1-x430.google.com with SMTP id h13so631220pfq.5 for ; Wed, 25 May 2022 20:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n3LxySRqlH+3wQnINf24RWL6S6NE+bkt1dAArrtZxp4=; b=XeWy67iinmQ2iAPYGpCkrnoX5eHYhOYkVuFHhTMpy1dhCykV+DkdEWzr9vgdhyGzC1 Dyp8e6rD1SlrDF2RvLUGmUAqW5rirQl03c/qeU+Z7AKoay82CJdhR+rBeuzVr45Lim5p TJ8IGakOKkK2B2NSaLRuG48hmIGcStR5dKrK8YtnKY4aSDz3wFb7RWxg9LMLFyO2NPFh 61tREj/+5og4u0p2dBb+mREhz2IRjK5jzkZCE/Jqgg2jXqyYqqjpY28SZ7xQfH4v1IWH rPRXOgDH6cfpxM/mIhUgrTnQyqGw4MqabWB9NCkvB243IV5pD8Xd9jWyFc0Mz2DKqLCI ycWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n3LxySRqlH+3wQnINf24RWL6S6NE+bkt1dAArrtZxp4=; b=tVscnjnPfg2GfRKB6wX5+drxr7MJeysEC86GbhDAXcquEBsjQPVkp7k/TpzDYa1ifT I1HkVWBrI3T8qTY3mUqMqBfdGSEULLjNokp3MOfgeK6pMJOe9boU8l4GOKovakcaRSOB ANApn1Ehl3zKf/dnSDfHBWLmRVCHEkCk9bWpx34PKl4iM9smChmdUvs7v9bPg2Fi9XYU VLt8vAVYtOj0Kpe7kvZiPZzTHTpSWrWicwZ0YVbIzHHPGjNjFfH2ZtQoJaxK4yjlJME3 0xPS+NXNEOiKWH5pFRkWs8lbtgLOanVvM+Valt291lBKbUNASDxyQeFnrDoG9rvo5X8R Bokw== X-Gm-Message-State: AOAM530f9GKMieWfLBllju9BxL/qdn41KX3v9dzTnH3BJZyCnYyX42Vt O98Hsln+lSgM7/SErTNr9ahBAF3BDvb0nLyT X-Google-Smtp-Source: ABdhPJxoyeyh1J+hh+am1KTyasB5YGvjtfNR4FSMIFYTu8AhD0l6Nr0s+gbjIdjKEm0tdClNgJmvTA== X-Received: by 2002:a63:e049:0:b0:3fa:bab7:e9b4 with SMTP id n9-20020a63e049000000b003fabab7e9b4mr8367995pgj.111.1653534813873; Wed, 25 May 2022 20:13:33 -0700 (PDT) Received: from localhost ([220.243.131.85]) by smtp.gmail.com with ESMTPSA id o4-20020a170902d4c400b001621ce92181sm164305plg.91.2022.05.25.20.13.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 20:13:33 -0700 (PDT) From: Peng He X-Google-Original-From: Peng He To: dev@openvswitch.org Date: Thu, 26 May 2022 03:13:18 +0000 Message-Id: <20220526031318.559449-2-hepeng.0320@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220526031318.559449-1-hepeng.0320@bytedance.com> References: <20220526031318.559449-1-hepeng.0320@bytedance.com> MIME-Version: 1.0 Cc: david.marchand@redhat.com, i.maximets@ovn.org Subject: [ovs-dev] [ovs-dev v7 3/3] checkpatch.py: Add checks for easy-to-misuse APIs. 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" Signed-off-by: Peng He Signed-off-by: Peng He Acked-by: Eelco Chaudron Acked-by: Aaron Conole --- tests/checkpatch.at | 24 +++++++++++++++++++++--- utilities/checkpatch.py | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/tests/checkpatch.at b/tests/checkpatch.at index fadb625e9..0a2cca34e 100755 --- a/tests/checkpatch.at +++ b/tests/checkpatch.at @@ -164,10 +164,10 @@ m4_define([COMMON_PATCH_HEADER], [dnl Signed-off-by: A --- - diff --git a/A.c b/A.c + diff --git a/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c") b/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c") index 0000000..1111111 100644 - --- a/A.c - +++ b/A.c + --- a/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c") + +++ b/$([[ ! -z "$1" ]] && echo "$1" || echo "A.c") @@ -1,1 +1,1 @@]) @@ -348,6 +348,24 @@ try_checkpatch \ AT_CLEANUP +AT_SETUP([checkpatch - check misuse APIs]) +try_checkpatch \ + "COMMON_PATCH_HEADER([a.c]) + + ovsrcu_barrier(); + " \ + "WARNING: Are you sure you need to use ovsrcu_barrier(), "\ +"in most cases ovsrcu_synchronize() will be fine? + #8 FILE: a.c:1: + ovsrcu_barrier(); +" + +try_checkpatch \ + "COMMON_PATCH_HEADER([lib/ovs-rcu.c]) + + ovsrcu_barrier(); + " + +AT_CLEANUP + AT_SETUP([checkpatch - whitespace around cast]) try_checkpatch \ "COMMON_PATCH_HEADER diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index 8c7faa419..8c02ac3ce 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -620,6 +620,10 @@ def regex_error_factory(description): return lambda: print_error(description) +def regex_warn_factory(description): + return lambda: print_warning(description) + + std_functions = [ ('malloc', 'Use xmalloc() in place of malloc()'), ('calloc', 'Use xcalloc() in place of calloc()'), @@ -636,6 +640,7 @@ std_functions = [ ('assert', 'Use ovs_assert() in place of assert()'), ('error', 'Use ovs_error() in place of error()'), ] + checks += [ {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, @@ -644,6 +649,21 @@ checks += [ 'print': regex_error_factory(description)} for (function_name, description) in std_functions] +easy_to_misuse_api = [ + ('ovsrcu_barrier', + 'lib/ovs-rcu.c', + 'Are you sure you need to use ovsrcu_barrier(), ' + 'in most cases ovsrcu_synchronize() will be fine?'), + ] + +checks += [ + {'regex': r'(\.c)(\.in)?$', + 'match_name': lambda x: x != location, + 'prereq': lambda x: not is_comment_line(x), + 'check': regex_function_factory(function_name), + 'print': regex_warn_factory(description)} + for (function_name, location, description) in easy_to_misuse_api] + def regex_operator_factory(operator): regex = re.compile(r'^[^#][^"\']*[^ "]%s[^ "\'][^"]*' % operator) @@ -676,12 +696,22 @@ def get_file_type_checks(filename): global checks checkList = [] for check in checks: + regex_check = True + match_check = True + if check['regex'] is None and check['match_name'] is None: checkList.append(check) + continue + if check['regex'] is not None and \ - re.compile(check['regex']).search(filename) is not None: - checkList.append(check) - elif check['match_name'] is not None and check['match_name'](filename): + re.compile(check['regex']).search(filename) is None: + regex_check = False + + if check['match_name'] is not None and \ + not check['match_name'](filename): + match_check = False + + if regex_check and match_check: checkList.append(check) return checkList