Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7033098pxb; Wed, 17 Feb 2021 22:35:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJyOdCDDQZpUwbgxITkeSJE2Be6lXZQiXUZNspBJ4e5uUIxNzGCHRzQ5FII3SZk7IYou6odd X-Received: by 2002:a17:907:11c1:: with SMTP id va1mr2651029ejb.352.1613630137472; Wed, 17 Feb 2021 22:35:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613630137; cv=none; d=google.com; s=arc-20160816; b=lfdcbEZukVQYQiYMaooT3iEiL8Ts4vi5QdhaBC0pGq3VLUZJEjLYKZpLqi4h0CBumv TVnju2LOZzRWqtwAOdJF0xxG0pQHvrp7dpPfh7S6YQ3wIwlgkd5q3Jt/vrGNKEYG2Lli QTLAzQDoQW06vk1fjYrBi/+aGYc5pEYYzaWEfbBFrRMznEHLvpMErX70nWQlC2ILOyFd zWqOAkbBF8n6/rGcUosWQ8IngH5I9KUJQ8tS3Jx/A4IYwvloK6XCklwzbMX40eTulJkK L2M1AHR3TzsApz2PToEl85Bp9TKDTFr9Vx00KLqsy/48BQ74RMR6bPMagDl5musMkehi dlMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=Ku7YQtFhkBJUbVK7xDsoiVrZBy6WIabI7rYkriW0fdA=; b=emWvRjoWmfBPEysog0b12tS3HiHVKZxZ8jI1fNmyAaN7nYHCIoK4NyarNAVmk4OdsG zDVDyyECadTEN1A5nrsF4Cbuo81QcqPyTaCmwr9R7uLg4bGXAP8iy3YlG8OPdyaoZHQ1 XY1h51s8SgoEsVKibJSog+omyVoetNAHfwSxMfNqHWlIbUzonD/xv7m19TbY4s3m/wFx NML9XgWK/zTTk2RivOKGEmeHm/2wYv3DkSvzKS1G3jKSzuhbtMktbAEro6r6QFvCTbGd 1gTb8vXw4FWUwhkAaNMfdJtgmpe++Z8QkAdQhtTuyvTkSByX5ehgHaCkhiUsi7OlJEiu eHwg== 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 ku3si3130400ejc.497.2021.02.17.22.35.13; Wed, 17 Feb 2021 22:35:37 -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 S231312AbhBRGaF (ORCPT + 99 others); Thu, 18 Feb 2021 01:30:05 -0500 Received: from mail-lj1-f180.google.com ([209.85.208.180]:45376 "EHLO mail-lj1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231124AbhBRGOP (ORCPT ); Thu, 18 Feb 2021 01:14:15 -0500 Received: by mail-lj1-f180.google.com with SMTP id c8so1886641ljd.12 for ; Wed, 17 Feb 2021 22:13:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Ku7YQtFhkBJUbVK7xDsoiVrZBy6WIabI7rYkriW0fdA=; b=C22ZMwY/WAIkbxwRFOgxMRI9RgHburtPwTiYaSQqiLv4B80UrmHRJqX1PBXtDswxfM azuWvyzwVvP8+N/XR8vDT3OAzcIufKJb/TpLKFSZ6k6FGR13dYZpjqlpsYipQL4Tt43x bKq+4G/qInujtOpCzEJH7PKdhYHAcV8M+Odlc6e5h11CBu58/etprPxu4hqpVPPrFEiu QR4rSahgxR4rJp08sW2imeXEiNJQOWmoPxy2aw4D59ldPm759zTRyoFIbAPUaogAtb5x lUXjDcymjtz5EapPhNPR/5CS0UXj5/dWU1NyyLatvEBJOXzGJry/rJPW7pPxu7KK5HGW cd3A== X-Gm-Message-State: AOAM533xa+K3GKGPULLRP61etJ4b9YbdL0BWBcQM74z97GOc0K2gpfgo VoJLeyHgfVTAf2jNV1pxl4Vjn3OnHxom9g== X-Received: by 2002:a2e:8804:: with SMTP id x4mr1691482ljh.252.1613628808721; Wed, 17 Feb 2021 22:13:28 -0800 (PST) Received: from [10.68.32.147] (broadband-188-32-236-56.ip.moscow.rt.ru. [188.32.236.56]) by smtp.gmail.com with ESMTPSA id j137sm493480lfj.55.2021.02.17.22.13.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Feb 2021 22:13:28 -0800 (PST) Subject: Re: [PATCH] coccinelle: misc: add swap script To: Julia Lawall Cc: cocci@systeme.lip6.fr, linux-kernel@vger.kernel.org References: <20210216080133.455456-1-efremov@linux.com> From: Denis Efremov Message-ID: Date: Thu, 18 Feb 2021 09:13:34 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/18/21 12:31 AM, Julia Lawall wrote: >> +@depends on patch@ >> +identifier tmp; >> +expression a, b; >> +type T; >> +@@ >> + >> +( >> +- T tmp; >> +| >> +- T tmp = 0; >> +| >> +- T *tmp = NULL; >> +) >> +... when != tmp >> +- tmp = a; >> +- a = b; >> +- b = tmp; >> ++ swap(a, b); >> +... when != tmp > > In this rule and the next one, if you remove the final ; from the b = tmp > line and from the swap line, and put it into context code afterwards, them > the generated code looks better on cases like fs/xfs/xfs_inode.c in the > function xfs_lock_two_inodes where two successive swap calls are > generated. > > There are also some cases such as drivers/net/wireless/ath/ath5k/phy.c in > the function ath5k_hw_get_median_noise_floor where the swap code makes up > a whole if branch. > In this cases it would be good to remove the {}. How this can be handled? If I use this pattern: @depends on patch@ identifier tmp; expression a, b; @@ ( if (...) - { - tmp = a; - a = b; - b = tmp + swap(a, b) ; - } | - tmp = a; - a = b; - b = tmp + swap(a, b) ; ) The tool fails with error: EXN: Failure("rule starting on line 58: already tagged token:\nC code context\nFile \"drivers/net/wireless/ath/ath5k/phy.c\", line 1574, column 4, charpos = 41650\n around = 'sort',\n whole content = \t\t\t\tsort[j - 1] = tmp;") in drivers/net/wireless/ath/ath5k/phy.c Thanks, Denis