Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1202519pxb; Fri, 20 Nov 2020 03:58:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjNUoAmn8BOcVfwiRLkiGVhHRpGSS1QZHrOfB3SrJj2+VD83F2kuUUjawAgSU3cfQxyrnq X-Received: by 2002:a17:906:3092:: with SMTP id 18mr32614298ejv.43.1605873527174; Fri, 20 Nov 2020 03:58:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605873527; cv=none; d=google.com; s=arc-20160816; b=YU6gM41jR4WCXrHKMPMgZpLqmhHuncKREpARFsP/1GvK1hWBFqtGUVkNT7Vj9hLMS2 su9HdTa1RGNy4Is/a9RpTIOsAeBLnAygeiSoTvRKOfsc1XxtBc50u6/QcNvMK/YQQBGW RQJepblzR1w3808qqvVyw9TslOpZ1yOLV7nDjA/Am3wT0Gb8z56mJUhxaBGPGyxNbQbl R5guWMv93IEV92SpMeyrlIg79AopUtg8R8HErz+aUKaMTD1w9U4smSe5o51ZbEfiaZ8F T6m1VQTZJ/WBKGqtTRZLwVMDJUZrmaT5uwzIwclWBfaWvoiJ5ifFCMLHQEy3rtVsFJKB TXlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date; bh=NNSzVhiqKH6kfhAn/P3h4A59+RVKw48Avqy0gdactyc=; b=XxqncsvPVbnwtFwkFWGyB5d9Cfmb8BSnv8BFvEK4MhpdkWH3n55Y587CRGoVyTs/6A sxSMrzsTamSrtpLvBWmnn/Jd1oNuIK0azPkT82I95BCBQWSd2xqqg+EY90IVRbxx4+cs 5ukSM56TS8pbQy1gYInhejzlHC9JsYk5TRcP17Shx8yLBeQTe/VhY7UEPmQvzP11HBmW /B53VJOQXLIQZiGMDx8fmwRITH2xZ+WswYk1lLorGs0fvGWj1hCtZo4dFXHUao409Uy6 +T8XQyR6sU1j6ESNLGxv7nrBqs+m0IhoVKr913jFh91yH2K2vM7H/63cxnxTfGNm1Dia Q8BA== 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 h2si1570366ejp.136.2020.11.20.03.58.24; Fri, 20 Nov 2020 03:58:47 -0800 (PST) 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 S1727897AbgKTL5G (ORCPT + 99 others); Fri, 20 Nov 2020 06:57:06 -0500 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:65376 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725824AbgKTL5G (ORCPT ); Fri, 20 Nov 2020 06:57:06 -0500 X-IronPort-AV: E=Sophos;i="5.78,356,1599516000"; d="scan'208";a="365151898" Received: from 173.121.68.85.rev.sfr.net (HELO hadrien) ([85.68.121.173]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2020 12:57:03 +0100 Date: Fri, 20 Nov 2020 12:57:03 +0100 (CET) From: Julia Lawall X-X-Sender: jll@hadrien To: Alexandru Ardelean cc: Joe Perches , Andy Shevchenko , Robo Bot , Alexandru Ardelean , LKML , cocci Subject: Re: [Cocci] Proposal for a new checkpatch check; matching _set_drvdata() & _get_drvdata() In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 20 Nov 2020, Alexandru Ardelean wrote: > On Fri, Nov 20, 2020 at 12:47 PM Julia Lawall wrote: > > > > > > > > On Thu, 19 Nov 2020, Joe Perches wrote: > > > > > On Thu, 2020-11-19 at 17:16 +0200, Andy Shevchenko wrote: > > > > On Thu, Nov 19, 2020 at 4:09 PM Alexandru Ardelean > > > > wrote: > > > > > > > > > > Hey, > > > > > > > > > > So, I stumbled on a new check that could be added to checkpatch. > > > > > Since it's in Perl, I'm reluctant to try it. > > > > > > > > > > Seems many drivers got to a point where they now call (let's say) > > > > > spi_set_drvdata(), but never access that information via > > > > > spi_get_drvdata(). > > > > > Reasons for this seem to be: > > > > > 1. They got converted to device-managed functions and there is no > > > > > longer a remove hook to require the _get_drvdata() access > > > > > 2. They look like they were copied from a driver that had a > > > > > _set_drvdata() and when the code got finalized, the _set_drvdata() was > > > > > omitted > > > > > > > > > > There are a few false positives that I can notice at a quick look, > > > > > like the data being set via some xxx_set_drvdata() and retrieved via a > > > > > dev_get_drvdata(). > > > > > > > > I can say quite a few. And this makes a difference. > > > > So, basically all drivers that are using PM callbacks would rather use > > > > dev_get_drvdata() rather than bus specific. > > > > > > > > > I think checkpatch reporting these as well would be acceptable simply > > > > > from a reviewability perspective. > > > > > > > > > > I did a shell script to quickly check these. See below. > > > > > It's pretty badly written but it is enough for me to gather a list. > > > > > And I wrote it in 5 minutes :P > > > > > I initially noticed this in some IIO drivers, and then I suspected > > > > > that this may be more widespread. > > > > > > > > It seems more suitable for coccinelle. > > > > > > To me as well. > > > > To me as well, since it seems to involve nonlocal information. > > > > I'm not sure to understand the original shell script. Is there > > something interesting about pci_set_drvdata? > > Ah, it's a stupid script I wrote in 5 minutes, so I did not bother to > make things smart. > In the text-matching I did in shell, there are some entries that come > from comments and docs. > It's only about 3-4 entries, so I just did a visual/manual ignore. > > In essence: > The script searches for all strings that contain _set_drvdata. > The separators are whitespace. > It creates a list of all xxxx_set_drvdata functions. > For each xxxx_set_drvdata function: > It checks all files that have a xxxx_set_drvdata entry, but no > xxxx_get_drvdata OK, but I have the impression that you want to ignore pci_set_drvdata for some reason? Or did I misunderstand? julia > > I piped this output into a file and started manually checking the drivers. > There is one [I forget which function] that is xxxx_set_drvdata() but > equivalent is xxxx_drvdata() > > As Andy said, some precautions must be taken in places where > xxxx_set_drvdata() is called but dev_get_drvdata() is used. > Cases like PM suspend/resume calls. > And there may be some cases outside this context. > > > > > > julia >