Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp516099pxa; Fri, 21 Aug 2020 13:13:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj1nfwNFUN2xBy9kacQd7gvFXhPSgUIi+JMPLpMf6lhh29yh8+iIEvO8cOuW9PW/BqALid X-Received: by 2002:a17:906:b2d0:: with SMTP id cf16mr4553092ejb.514.1598040797331; Fri, 21 Aug 2020 13:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598040797; cv=none; d=google.com; s=arc-20160816; b=Eex20YWP9bBvZ82zKjYLHziJUWein8xJ7ZqAdVagrp1Al/ZRRkNhet0xGSBJMA1pNE VyZWYKzEeGfEOduyViLmFfKXh03ZNMoVn+ciW9AcX0Z3129O7nwHX6zRFH6AsKS99ZP3 nwe+o5yBj9CCHYG4/Da+Vf9PCPQZSZzyT3nEVxmt7V5ZgwkNi1RcrziSm1kt8pC1uzCk cptz3OrRrtrt0l0d9IbNhGBH0qSmHeVXNpMGi9GroMw3ZXhvEBUNe66puhUIwGtQEsP1 N9hdIBVZ69/Pg+5qJX8wDi6XIjalD6kdJ2VfpcnaNEvmUTPdyZpPpjFVAe9dK2ZaZpat ETjA== 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=LyeWE+LKBU/Cc6jZ0EOliLucORAUIo1fVngoaszDbjk=; b=KwkCSrsjNoyaYTUZ5cSiX/pNj3kvF4oWLFG0/Y4XwklvlyKhAmweaJLZv7+SbiibHz 8maZoQy64yJZ+WZ9VZdlg800SPd8Px6ZQYWVwa9bV631lDVetnS7mU2XNc61LEkoO8Rm wN+xx8CrWOs78zrcf3dsG97IX5WqbmRJQ44BhBKpnhyG815kOHmFBcK3YS4kC+R0cb+j 96lRT+iddmDMmzysNd59JvqJp8GJzs2wx0r/r7ZU2ZbA75etFYR4X6I4OzwX7fB822rg vUx3hS3DDsN7ZY6V97y02F+wcADC9GQEtBnccaJh+flmhqP6ayLN9yWkN1sGLi7Y8B0Z Uogw== 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 u6si1953009eje.234.2020.08.21.13.12.53; Fri, 21 Aug 2020 13:13:17 -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 S1726593AbgHUUMF (ORCPT + 99 others); Fri, 21 Aug 2020 16:12:05 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:40538 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbgHUUMF (ORCPT ); Fri, 21 Aug 2020 16:12:05 -0400 Received: by mail-lj1-f194.google.com with SMTP id 185so3178517ljj.7 for ; Fri, 21 Aug 2020 13:12:03 -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=LyeWE+LKBU/Cc6jZ0EOliLucORAUIo1fVngoaszDbjk=; b=OYgNc7HbASF8O5UCqWAcjBQySKnwXu5iR2+HOj5P8ANdgeEa2glHwJc3Px9xnEP+bH hvL8a7znqMf3sYj2ohLkmsmlimwejhzdkTesxtP0+6o9YXqnxi2Ed/FymGEQxfjZ4eKO VMIZrQBI4QxxELKUDldyi1b3jXA45WEW11985ADmDt+qLAG7RiLWMWqCj5QzKHEF6AsF 6jAU4r+87rfoQU2WLLw0qSd/aBt5IhAmkReJDUplclKtjUOUq53nuVBCsAbizm0t1Cof harHQfL+ABubgtF+FOBVNEcvQBtV03tqCzDPv97ouIDmvEAX3lJFJcf54cwCVoGoOZXR N3jg== X-Gm-Message-State: AOAM533ylRRYDrLrQNYtF3cXaaSx5kFAATOB84iHnsEB9VZumocxMHv1 qDNEPLjeFcercrh0qk9XQpE= X-Received: by 2002:a2e:b0db:: with SMTP id g27mr2422415ljl.69.1598040722687; Fri, 21 Aug 2020 13:12:02 -0700 (PDT) Received: from localhost.localdomain ([213.87.151.123]) by smtp.googlemail.com with ESMTPSA id v1sm572695ljg.60.2020.08.21.13.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 13:12:01 -0700 (PDT) From: Denis Efremov To: Julia Lawall Cc: Denis Efremov , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: [PATCH v2] coccinelle: api: add kobj_to_dev.cocci script Date: Fri, 21 Aug 2020 23:11:37 +0300 Message-Id: <20200821201137.446423-1-efremov@linux.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200821153100.434332-1-efremov@linux.com> References: <20200821153100.434332-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 Use kobj_to_dev() instead of container_of(). Signed-off-by: Denis Efremov --- Changes in v2: - "symbol kobj;" added to the rule r scripts/coccinelle/api/kobj_to_dev.cocci | 45 ++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/coccinelle/api/kobj_to_dev.cocci diff --git a/scripts/coccinelle/api/kobj_to_dev.cocci b/scripts/coccinelle/api/kobj_to_dev.cocci new file mode 100644 index 000000000000..cd5d31c6fe76 --- /dev/null +++ b/scripts/coccinelle/api/kobj_to_dev.cocci @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// +/// Use kobj_to_dev() instead of container_of() +/// +// Confidence: High +// Copyright: (C) 2020 Denis Efremov ISPRAS +// Options: --no-includes --include-headers +// +// Keywords: kobj_to_dev, container_of +// + +virtual context +virtual report +virtual org +virtual patch + + +@r depends on !patch@ +expression ptr; +symbol kobj; +position p; +@@ + +* container_of(ptr, struct device, kobj)@p + + +@depends on patch@ +expression ptr; +@@ + +- container_of(ptr, struct device, kobj) ++ kobj_to_dev(ptr) + + +@script:python depends on report@ +p << r.p; +@@ + +coccilib.report.print_report(p[0], "WARNING opportunity for kobj_to_dev()") + +@script:python depends on org@ +p << r.p; +@@ + +coccilib.org.print_todo(p[0], "WARNING opportunity for kobj_to_dev()") -- 2.26.2