Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755172AbdGWCbY (ORCPT ); Sat, 22 Jul 2017 22:31:24 -0400 Received: from gateway34.websitewelcome.com ([192.185.148.109]:16316 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751549AbdGWCbW (ORCPT ); Sat, 22 Jul 2017 22:31:22 -0400 From: "Gustavo A. R. Silva" Subject: Re: [PATCH] EDAC: remove unnecessary static in edac_fake_inject_write() To: Borislav Petkov , Julia Lawall References: <20170704214440.GA9462@embeddedgus> <20170717083946.GB23129@nazgul.tnic> <20170722063602.GB2050@nazgul.tnic> <638a94de-5eb4-eba4-7c28-4b4eb4bf8dbf@embeddedor.com> Cc: Mauro Carvalho Chehab , linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr, "Gustavo A. R. Silva" Message-ID: <7209d11a-c2f7-ca65-94d8-56f996133013@embeddedor.com> Date: Sat, 22 Jul 2017 21:31:13 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <638a94de-5eb4-eba4-7c28-4b4eb4bf8dbf@embeddedor.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.152.147.47 X-Exim-ID: 1dZ6fv-0027Of-Sw X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.1.71]) [189.152.147.47]:34594 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1502 Lines: 86 Hi Julia, Borislav, On 07/22/2017 11:22 AM, Gustavo A. R. Silva wrote: > Hi all, > > On 07/22/2017 01:36 AM, Borislav Petkov wrote: >> On Fri, Jul 21, 2017 at 10:08:12PM +0200, Julia Lawall wrote: >>> Someone pointed out that the rule is probably not OK when the address of >>> the static variable is taken, because then it is likely being used as >>> permanent storage. >> >> Makes sense to me. >> >>> An improved rule is: >> >> Do you think it is worth having it in scripts/coccinelle/ ? >> >> I don't think Gustavo would mind putting it there :) >> > > Absolutely, I'd be glad to help out. :) > I've been working on this issue today and, in my opinion, this script is even better: @bad exists@ position p; identifier x; expression e; type T; @@ static T x@p; ... when != x = e x = <+...x...+> @worse1 exists@ position p; identifier x; type T; @@ static T x@p; ... return &x; @worse2 exists@ position p; identifier x; type T; @@ static T *x@p; ... return x; @@ identifier x; expression e; type T; position p != {bad.p,worse1.p,worse2.p}; @@ -static T x@p; ... when != x when strict ?x = e; It ignores all the cases in which the address of the static variable is returned to the caller function. Also, there are some cases in which the maintainer can argue something like the following: https://lkml.org/lkml/2017/7/19/1381 but that depends on the particular conditions in which the code is intended to be executed. What do you think? Thank you -- Gustavo A. R. Silva