Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp822967ybg; Tue, 9 Jun 2020 13:52:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+mB5Tg+QMBLdIPIz/a7t8VjMh20JTRZqiy876a05gMUUC6s/qaHMzy8ccr8roULrUNqG1 X-Received: by 2002:a17:906:3e84:: with SMTP id a4mr225436ejj.372.1591735924469; Tue, 09 Jun 2020 13:52:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591735924; cv=none; d=google.com; s=arc-20160816; b=oxZdIfzE1alxB5ul4IjMqkKAsFUCMa/SUCq9varMmSblAhVD5WoYcPpnV98Ol7Lwq0 UMlYmLq15n/k3RWuvUV+PDpYViGLqfhCdduMmaggTYvst1QbTR7R9lQ5Qb34rVJRq2dK QLtL3WVV2pLNmIFzvrYFe0kNgx4g7m1966+eRLGbV/c09yNHM8QWTeDPzfddEEtJ6TpH vr2qZLvYyn+lbp8J5EHbfkJK05Y202+/1QDNJZoz7fopBey8siNzHH1pKj+RQ5FmhQY3 EhjCLmBM0sqDazgp18YqBivNTm+gn/Zfe1s8o4y09XnqLCFG7rpnib/3+kEk3yhsLofz rhrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=IXM4bggjDlPeFnZr7KAMG98PazJGfzPhh+Kr9ZKlWb8=; b=f1rlORNObJUUECv66quhwd3sfYhVdXhhiMCNdhJRotlDxPfh/KMGpPgjLPdVE3t3zf zC3FoTasx7gJBp/yFzg045KL7gjWP68NWUhAUTbFyh5TdBmnq97bmn0WxdUbulKFDS2x 8Sag/J267d712UaZ6aWbUIZHnGin0yk9x4nw64ScNYhPTV6E/6STJxUGzhwOTMdQYtha Kcfo6wTElQUWvERA5z+jvgBFp5cs7AH0y2WRenkzmp8NcDDYyIwj0ZB0VHhXXEFR/yOh AyHBXJyPgtoMkfna5RDmHSSCxdbDSYn7H+LuuALS+pOh2B9WBeIeweLJm6G5z8EfpiO7 DzpQ== 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 m21si5156267eds.234.2020.06.09.13.51.41; Tue, 09 Jun 2020 13:52:04 -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 S1727881AbgFIQWL (ORCPT + 99 others); Tue, 9 Jun 2020 12:22:11 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:44249 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727773AbgFIQWL (ORCPT ); Tue, 9 Jun 2020 12:22:11 -0400 X-IronPort-AV: E=Sophos;i="5.73,492,1583190000"; d="scan'208";a="351117269" Received: from abo-173-121-68.mrs.modulonet.fr (HELO hadrien) ([85.68.121.173]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jun 2020 18:22:05 +0200 Date: Tue, 9 Jun 2020 18:22:05 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Denis Efremov cc: linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr Subject: Re: [Cocci] [PATCH v2 4/4] coccinelle: api: add selfcheck for memdup_user rule In-Reply-To: <20200608150038.223747-5-efremov@linux.com> Message-ID: References: <20200608150038.223747-1-efremov@linux.com> <20200608150038.223747-5-efremov@linux.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 8 Jun 2020, Denis Efremov wrote: > Check that the rule matches vmemdup_user implementation. > memdup_user is out of scope because we are not matching > kmalloc_track_caller() function. Is this a bit over-enginered? More precisely, even if it is nice to check that the API definition has the expected behavior, does it make sense to do it in one case but not the other? julia > > 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 > > _______________________________________________ > Cocci mailing list > Cocci@systeme.lip6.fr > https://systeme.lip6.fr/mailman/listinfo/cocci >