Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751664AbbEQQUh (ORCPT ); Sun, 17 May 2015 12:20:37 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:36093 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750777AbbEQQU3 (ORCPT ); Sun, 17 May 2015 12:20:29 -0400 MIME-Version: 1.0 In-Reply-To: References: <1431821187-21648-1-git-send-email-dmitry.kalinkin@gmail.com> Date: Sun, 17 May 2015 19:20:28 +0300 Message-ID: Subject: Re: [PATCH] coccinelle: api: add vma_pages.cocci From: Dmitry Kalinkin To: Julia Lawall Cc: linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr, Gilles Muller , Nicolas Palix , Michal Marek Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2258 Lines: 51 On Sun, May 17, 2015 at 4:39 PM, Julia Lawall wrote: >> +@r_patch2 depends on !context && patch && !org@ >> +struct vm_area_struct *vma; >> +@@ >> + >> +- (vma->vm_end - vma->vm_start) >> PAGE_SHIFT >> ++ vma_pages(vma) > > This rule is not needed. An isomorphism will allow tha case with () > around the whole thing to match the case where those parentheses are > absent. So coccinelle is a real semantic tool and sees the difference between (vma->vm_end - vma->vm_start) >> PAGE_SHIFT + 3 and (vma->vm_end - vma->vm_start) >> PAGE_SHIFT & 3 Cool. Didn't realize that. > It may be good to put below the keywords: > > // Comments: > // Options: --all-includes > > This rule relies on type information, ie knowing whether something has > type struct vm_area_struct *, so having more include files available may > make that more apparent. On the other hand, if you think the referenced > thing will always be a local variable (as opposed to a structure field), > then just using the current C file should be good enough, and it will be > faster without the --all-includes option. There probably won't be any benefit in doing that. The statement is long enough already long enough as it is. So it is unlikely that any code like (dev->priv->vma->vm_end@p - dev->priv->vma->vm_start) >> PAGE_SHIFT is to appear. I also just checked and saw that using --all-includes doesn't produce additional triggers anywhere on the current code (except for false fire on mm.h at vma_pages() itself). > > I tried the rule replacing struct vm_area_struct *vma; by expression vma > and got a couple of results on other types. One could wonder if that code > could be improved in some way. Indeed, there are such cases. I checked a couple manually and they turned out to be some different third party structures having fields called vm_end and vm_start used for vma-related accounting. These may or may not be a justifiable uses. We could report them, but not propose an automatic patch Kind regards, Dmitry -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/