Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp4446394ybg; Mon, 8 Jun 2020 08:04:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxb223hoO+C3tlaDovosZ2ddmk+e28m7RkUxol5sDGGYNr8kP3Afx2MiJQA2E/wn/PyJTA9 X-Received: by 2002:a17:906:6a1b:: with SMTP id o27mr21928887ejr.271.1591628651035; Mon, 08 Jun 2020 08:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591628651; cv=none; d=google.com; s=arc-20160816; b=Giuu8SJelONlrE5D8n+MQbF6Rqu6K78xy0amF/tm70xZtHQTa/gubsuRBZmO5bUuxX c0lbFRo80wbCYch2JW1RTbcWPa9eKxsCTKQzpjyTP1tYkaHfJ8mfMyPSjQPcormpJUoV P7pE6WEJNHvNw1f/w9IxR3w/SfGW4yVL5OnmgQe8xbLrXY7YF9SWe8gOw+2+VFOUDnUw 29fsXjHVGTXFXVNQLiMgFEvxhPUCv5xUegUBFjIsw/yAjMennKjUpstDf3gUJiqIvHbY /5tJB3X4dCsDEkR1bPnEm97Wpg3oz1ghsbC2BaYzMW/y+xGRplvJ1CvXhmd67UPgvNad gN6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=lR7SkMxR2WvDhYKg7h/qTpiMFY/yOdg6mP8JNQ15c78=; b=jfUkKJSrmYht5Ay9aK2DWzDxJQG7dYkCWIRJJG/bIojM+adGcxyOEIymMbwdfX0jXg dN0q4L+qnm8B1QkIo0gBCDknIYMd2QsE1mbg+5TJ41CtezAejilIMpzQVb/ej0gI8saP jRZj1VPTN1iaoTkmETV85emXYUOrkHwDRVBDvLTKTvnxMzdAzvnA/29/RwVBT+9PnKgt j0FpeT/8GYf3xO+q8LQxvON0wapoEmT7XokQ6hLebOerCkiB1Gg74nJCLtzxc56PULSo aiRH+8O2hG3cVjMvd/3/SbKsJEvOVfZw5zdhvqzRO+O6dRLjjGtjObI5SQr+O9lh7LMM n7Gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n9si9095049eju.428.2020.06.08.08.03.45; Mon, 08 Jun 2020 08:04:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730216AbgFHPBa (ORCPT + 99 others); Mon, 8 Jun 2020 11:01:30 -0400 Received: from mail-lj1-f175.google.com ([209.85.208.175]:33241 "EHLO mail-lj1-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730194AbgFHPB0 (ORCPT ); Mon, 8 Jun 2020 11:01:26 -0400 Received: by mail-lj1-f175.google.com with SMTP id s1so20917933ljo.0 for ; Mon, 08 Jun 2020 08:01:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lR7SkMxR2WvDhYKg7h/qTpiMFY/yOdg6mP8JNQ15c78=; b=iLiFNENYRru5l4ZrkUIkMzdlCD9ukFLPAAE5IOw7SnSVxEzVp1O5dh5N2RyAIXlhPP PBUXeDesH4XF0SHlw92eh9JJ3n84JJXdxZ5RgUYWgDuC6Cn0e6UC++NX0zRxXSBWDVCt rfScNSk38ccE93njYQ7n5DTczXYGHPaORL8Ug00BerGT1Mxl26/ynr+xTyuJN8E7hsRm d7cvhSCIRekVt+7iDmYOsSynSrvlW50ZflFOfkZ1Qwl3clQrVdE/aG1BOw73iajWx+4w jKsSe8UiQ7gi/WcIq9JgkwvbW6kV8hSv468a6EIqwHHfZo+AtrmD9oyn5k+yB54Q0h0P Uk/A== X-Gm-Message-State: AOAM531Gza4gQGFngImDurxRW8ai/vtgrvNJYulduAzP0eT/SzYuM3nn 9R6IJdOGnkKHzBkEVvClTZw= X-Received: by 2002:a2e:800b:: with SMTP id j11mr12204281ljg.467.1591628484282; Mon, 08 Jun 2020 08:01:24 -0700 (PDT) Received: from localhost.localdomain ([213.87.137.116]) by smtp.googlemail.com with ESMTPSA id r16sm279228ljn.106.2020.06.08.08.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2020 08:01:23 -0700 (PDT) From: Denis Efremov To: Julia Lawall Cc: Denis Efremov , linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr Subject: [PATCH v2 4/4] coccinelle: api: add selfcheck for memdup_user rule Date: Mon, 8 Jun 2020 18:00:38 +0300 Message-Id: <20200608150038.223747-5-efremov@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200608150038.223747-1-efremov@linux.com> References: <20200608150038.223747-1-efremov@linux.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check that the rule matches vmemdup_user implementation. memdup_user is out of scope because we are not matching kmalloc_track_caller() function. Signed-off-by: Denis Efremov --- scripts/coccinelle/api/memdup_user.cocci | 46 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/scripts/coccinelle/api/memdup_user.cocci b/scripts/coccinelle/api/memdup_user.cocci index 8621bd98be1e..78fded83b197 100644 --- a/scripts/coccinelle/api/memdup_user.cocci +++ b/scripts/coccinelle/api/memdup_user.cocci @@ -14,13 +14,24 @@ virtual patch virtual context virtual org virtual report +virtual selfcheck @initialize:python@ @@ -filter = frozenset(['memdup_user', 'vmemdup_user']) + +definitions = { + 'memdup_user': 'mm/util.c', + 'vmemdup_user': 'mm/util.c', +} + +filter = frozenset(definitions.keys()) +coccinelle.filtered = set() +coccinelle.checked_files = set() def relevant(p): - return not (filter & {el.current_element for el in p}) + found = filter & {el.current_element for el in p} + coccinelle.filtered |= found + return not found @depends on patch@ expression from,to,size; @@ -117,3 +128,34 @@ p << rv.p; @@ coccilib.report.print_report(p[0], "WARNING opportunity for vmemdup_user") + +@script:python depends on selfcheck@ +@@ +coccinelle.checked_files |= set(definitions.values()) & set(cocci.files()) + +@finalize:python depends on selfcheck@ +filtered << merge.filtered; +checked_files << merge.checked_files; +@@ + +# Don't check memdup_user because the pattern is not capturing +# kmalloc_track_caller() calls +del definitions['memdup_user'] + +# mapping between checked files and filtered definitions +found_defns = {} +for files, funcs in zip(checked_files, filtered): + for file in files: + found_defns[file] = funcs + +# reverse mapping of definitions +expected_defns = {v : set() for v in definitions.values()} +for k, v in definitions.items(): + expected_defns[v] |= {k} + +for efile, efuncs in expected_defns.items(): + if efile in found_defns: + not_found = efuncs - found_defns[efile] + if not_found: + print('SELF-CHECK: the pattern no longer matches ' \ + 'definitions {} in file {}'.format(not_found, efile)) -- 2.26.2