Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp340276pxa; Fri, 21 Aug 2020 08:35:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkoLj3U7vUide9W2YuByKJfDzPBwuGmHK29oDBl+GwlxfB8TDojPGKJc92dBqhb739BU2q X-Received: by 2002:a17:906:3ac4:: with SMTP id z4mr3216733ejd.65.1598024103825; Fri, 21 Aug 2020 08:35:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598024103; cv=none; d=google.com; s=arc-20160816; b=pdb7O+6fliYyzaMFhn00ww2oqExju2sZ2B5WqUKrnh3x7M6TEgO46txatzTxlXxgS2 hmGo1K4KyacQvkrQCsGqeG/1NsSnVWR4fGTeBz2s8NPV6ba8uqdDIRbcP1QvfnqXvaxK i/nKgzKmFHzjryt1eQzWB2p874szd2gequUAV+K+MHsp6Ymrd2f4A7wt/uZkO2spoePM xdFsTyE4HVBimWi5kqNfuaObSp7K+WsKEeub9ZjZ4wkVwSEXwjbE3Pa7a0GhVn0la9Jt 8m7lj2wUwopYzQj/lTeF9MEyqVXRfrACy7LyEhO+ZngO+CDEPeahtg39JAXse4fnq4rk Xhog== 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 :message-id:date:subject:cc:to:from; bh=RiowHVIdXmdWQw4sb/h6lAEadFKHLzL7PqwIIimzsFs=; b=Z+98EpuvqT5geLs41W2LQVaVsZQNlYIXgIqKgTPLu29vRQUkxXZ8NaXDn/1YHZ3FFJ NXGsWjz+FVB0ECxPuLynMIEc2NaTt5MbsFwTYD2JOXMtpvALHMiRSQ774R7fmq1d2wN7 PUzPaTIfLN3UXJuy4XDDc6Zo3GKlt6wwaSE82JAKQ7k188jPELXlTRxcstttjlY5SSoM yCgHqNHd3VRBPQC6Dw1Zy5lkZJiNthnpcPqIOK1ohRA53vNUORHpuRwrDRmtjTHZc83O paoka93QzrpdC4gYH/0xH/8ZzYcra6T61qDAhMgptVar0rhTACHf5hGo9lMBTEPztF2p iAew== 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 v6si1318878edx.215.2020.08.21.08.34.39; Fri, 21 Aug 2020 08:35:03 -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 S1727993AbgHUPbf (ORCPT + 99 others); Fri, 21 Aug 2020 11:31:35 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:43212 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727882AbgHUPbd (ORCPT ); Fri, 21 Aug 2020 11:31:33 -0400 Received: by mail-lj1-f195.google.com with SMTP id v12so2281727ljc.10 for ; Fri, 21 Aug 2020 08:31:31 -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:mime-version :content-transfer-encoding; bh=RiowHVIdXmdWQw4sb/h6lAEadFKHLzL7PqwIIimzsFs=; b=N8LZfZy/tlqq0o1y729wdePWv3U9Dkqh8D1VZJdY40jOKCI7UCQ3c5srsjuRdQEcs2 C/nZEQ/8LJnANsS1cuJsvEh3pzZytlSeAzPHLHVbwc2eVBCpzGnmJtXaYGoVtFiat4tG QrO4IwLLeLcNlF3tDDrqZn5+oyrJGayXf6dVTipQQTLCfpadGrGYmkSU0Y/WQb4yU5Vg VVrVaTN2OOzKCJ+g2Z6zIUaRbCNUn9hdMbsxwlyDGPSEL+mMNh9PLQPCHcFAIfUfKsKP T4puG4eOxDQN2EHva3bK1p3vrhKsfrus01pxD51fpDTQkK/xvE9uEvxBF8Bkd/cdlGYv Vc9g== X-Gm-Message-State: AOAM532v/GQjoEVH9f54jqCKqkBMEs63mrjEiv9lkI/7Nq7TsDHJoj0Y hJGsZzWiWpfgeE9WdjSv8d+pCGnOe4E= X-Received: by 2002:a2e:9003:: with SMTP id h3mr1868250ljg.185.1598023890775; Fri, 21 Aug 2020 08:31:30 -0700 (PDT) Received: from localhost.localdomain ([213.87.151.123]) by smtp.googlemail.com with ESMTPSA id w11sm446050lff.62.2020.08.21.08.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2020 08:31:28 -0700 (PDT) From: Denis Efremov To: Julia Lawall Cc: Denis Efremov , cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org Subject: [PATCH] coccinelle: api: add kobj_to_dev.cocci script Date: Fri, 21 Aug 2020 18:31:00 +0300 Message-Id: <20200821153100.434332-1-efremov@linux.com> X-Mailer: git-send-email 2.26.2 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 --- Examples of such patches: 893c3d82b425 watchdog: Use kobj_to_dev() API 23fd63a44460 hwmon: (nct6683) Replace container_of() with kobj_to_dev() 224941c9424f power: supply: use kobj_to_dev a9b9b2af40c7 backlight: lm3533_bl: Use kobj_to_dev() instead 0acb47a3a093 qlcnic: Use kobj_to_dev() instead 97cd738c44c8 gpiolib: sysfs: use kobj_to_dev d06f9e6c8960 hwmon: (nct7802) Replace container_of() API 036855a4c3b3 hwmon : (nct6775) Use kobj_to_dev() API baf1d9c18293 driver/base/soc: Use kobj_to_dev() API ae243ef0afbc rtc: sysfs: use kobj_to_dev 6b060d8a09e9 i2c: use kobj_to_dev() API 9e7bd945b9a9 scsi: core: use kobj_to_dev 0d730b57b95f s390/cio: use kobj_to_dev() API 0616ca73fd35 usb: use kobj_to_dev() API 8c9b839c0b80 alpha: use kobj_to_dev() 016c0bbae1d1 netxen: Use kobj_to_dev() 6908b45eafc4 GenWQE: use kobj_to_dev() 85f4f39c80e9 pch_phub: use kobj_to_dev() 47679cde604d misc: c2port: use kobj_to_dev() 85016ff33f35 misc: cxl: use kobj_to_dev() 092462c2b522 misc: eeprom: use kobj_to_dev() a9c9d9aca4e7 zorro: Use kobj_to_dev() a253f1eee6c4 rapidio: use kobj_to_dev() e3837b00b6bb drm/radeon: use kobj_to_dev() cc29ec874b37 drm/amdgpu: use kobj_to_dev() d122cbf1a310 drm/sysfs: use kobj_to_dev() 657fb5fbadb3 drm/i915: use kobj_to_dev() 554a60379aaa PCI: Use kobj_to_dev() instead of open-coding it 2cf83833fc9c HID: use kobj_to_dev() aeb7ed14fe5d bridge: use kobj_to_dev instead of to_dev 8e3829c61b48 staging:iio:adis16220: Use kobj_to_dev instead of open-coding it b0d1f807f340 driver-core: Use kobj_to_dev instead of re-implementing it scripts/coccinelle/api/kobj_to_dev.cocci | 44 ++++++++++++++++++++++++ 1 file changed, 44 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..e2cdd424aeca --- /dev/null +++ b/scripts/coccinelle/api/kobj_to_dev.cocci @@ -0,0 +1,44 @@ +// 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; +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