From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4781F3BBFD2 for ; Sat, 25 Jul 2026 11:35:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784979337; cv=none; b=OYO7ItyMFWlKiw3uKw4yoM5I8wynkgoeYnN4FZCFrJ3Xtr3Wys2GlTBUTpRTB+fLET604bBvZEK6m8oMmXVKt76KwiOeWwbnF3nIukhRVb5Gbfc1s4H7MMDDLWG8k+1aR5WQcD5aDrM/GlufQZI6TO26srTPEUXsITNlaRgiPwE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784979337; c=relaxed/simple; bh=M8GG068mUZxz202aQVWpZvBaI9d4AMGzWKEmFptE6oQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KBlaaoGvJHngBQOorFXlFudxjUjLjjb+7S73dOEmgeZ8LfdHo7dQyzmyCkpD1IEqF+cz64Un5yv/Zjxc8q9jflFqi377WgFaMKM7FE57sa1WHRE8St+BiXUTyhb9roVpzTiLPp6yTeA5TZzKIQqa0WcSVJyBFChsedy6mY1aqkE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S8SKjR52; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S8SKjR52" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-38e88b60121so1047278a91.3 for ; Sat, 25 Jul 2026 04:35:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784979336; x=1785584136; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Eq7DVzYHyMqOagO/PFvTOoCKowMxqeglDmPdQ8+nQ8k=; b=S8SKjR52GPiXkulwmzpfQ0DhNEEz/pPSglKZ3ljl6KSX0A1B+5bWUHxbU7Ekcf9Vnp 5+9oghGowc4Pmq+Z00OqDcWwtRLpryNMfsgJnGXkTfebELb5sTB9F2Mr24W7Y/0iYWE+ hxkm+5AuVDYMXu8gPQMDSe1NV0hz+u/WnJYJwXvyLWM9zLDvUzwwuNAKdA58YKlv+ecw TzDYLvpSneNSIA1DQ9VVsxSIbD2/3YwL97rfrOKhg/1jm/sHtjbX1EmyLENGn3/kWk0f r6G7Z318jS4b/qmwwRZ3+XLKAkMH4LVqjAI11hVKbYJYbBbCZx91u5muOWMCAgFni4/l eACA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784979336; x=1785584136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Eq7DVzYHyMqOagO/PFvTOoCKowMxqeglDmPdQ8+nQ8k=; b=Da6YP+Ep+gPq7yKUchHsD1V/c3OWm+0wW927xDyqmDALVLQy6t16+UQusjl9SSswY2 1l7vRfzVRmHcCRvo7H49WD+aIgDmROr47IqJpsxBDBu6kCOF08kPTRBbYO3YD8ecx2iK RPKkUEE6VJeCxF1Lv60c56PZ/qzM7nSgJsiRsLeA/cqE7yyT05YCvqGF8STG1wVDyREx vJGWVrv+oNlftUprjwanILoOjEVWvUaCGPLJMgEkd5JGN8zRmIVznKacEtkvHViIpTxu fS0zqcnZ1OLVipt3gLuTXj02XBYlw0wdt87LocNvyFlcPPiYrgbq7hoevKk34DwaPQh/ 9O0g== X-Forwarded-Encrypted: i=1; AHgh+RqCLeX7XklFCpUtY6ebvpZ1QFWI7IsghYb17vYPx9nIFgPXD49gaZI+LTlsxE0viX6KT1/PltnZGVGZA9I=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9UfzPoVGgenbprLmGCGiWxboBBdEVhPXsNaONK1GYrgvkRIP4 eJTdVKLyZTQNoiWWpHTycU9wDfsSzXbylZVrwYVCkmhxVYzfZlDm51E/ X-Gm-Gg: AR+sD10KPnIYqyMr531uFbi8eFW699jreNm3uudyPX7RN6WZckVlxrGbK/gJNBr6KGu KEO7c/XnA9AP/WNQH1wrg7c5K0nnsPbKPX6Q98SCGnSMeXo76y8SPzopAbmtuyZV0SLsc1StzZL QaqS9HNbsZ7JadvFs22SuGmPLBKiAHDTy67z0NKOJUCXo7QLAq1P5+58O/Esiat1lXVUx+W14Wq 04uxxlRvADyNiOPNtBvBXrn6QU/jaK7OOiaPgVEM9MnVXzfmLl40tJGt/GL9W4NJUebEwLvzVR8 PuapN1+T5gHnSZrHFyjKhO7BZFGV8kkq37qb6PE+4yGRFLvQdMLRpA26K0GU1hggocqlXkhfXL9 NJaI4c2Bo2Qtx0dv+qJ0OBPfcPsg5rvxzCKNfF4kk0GHSD8pY7YAG+hv13QfNTdN194UhxBKc X-Received: by 2002:a17:90b:4a51:b0:380:105f:8ffd with SMTP id 98e67ed59e1d1-38f295145c9mr2201065a91.16.1784979335666; Sat, 25 Jul 2026 04:35:35 -0700 (PDT) Received: from ubuntu.. ([110.9.142.4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38f08ae3079sm1539083a91.3.2026.07.25.04.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2026 04:35:34 -0700 (PDT) From: Sang-Heon Jeon To: Julia Lawall , Nicolas Palix Cc: cocci@inria.fr, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] coccinelle: double_lock: improve performance when no double lock exists Date: Sat, 25 Jul 2026 20:32:40 +0900 Message-ID: <20260725113303.691676-3-ekffu200098@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260725113303.691676-1-ekffu200098@gmail.com> References: <20260725113303.691676-1-ekffu200098@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The 'balanced' rule collects the locks that are taken and released under the same condition, to prevent them from being reported as a double lock. It runs on every file that contains a lock call. To avoid this, collect the double-lock candidates first, so that 'balanced' runs only when one exists. The report then excludes what 'balanced' found. Every double lock that can be reported is also a candidate, so the same reports are made as before and the output does not change. A report-mode run over every .c file in the tree produces identical output. Signed-off-by: Sang-Heon Jeon --- scripts/coccinelle/locks/double_lock.cocci | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/scripts/coccinelle/locks/double_lock.cocci b/scripts/coccinelle/locks/double_lock.cocci index 619cfc714409..381060849a7b 100644 --- a/scripts/coccinelle/locks/double_lock.cocci +++ b/scripts/coccinelle/locks/double_lock.cocci @@ -38,7 +38,20 @@ write_lock@p1 write_trylock@p1 ) (E1@p,...); -@balanced@ +@r_candidate exists@ +expression x <= locked.E1; +expression locked.E1; +expression E2; +identifier lock; +position locked.p,p1,p2; +@@ + +lock@p1 (E1@p,...); +... when != E1 + when != \(x = E2\|&x\) +lock@p2 (E1,...); + +@balanced depends on r_candidate@ position p1 != locked.p1; position locked.p; identifier lock,unlock; -- 2.43.0