From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 515013C0608 for ; Sat, 25 Jul 2026 11:35:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784979340; cv=none; b=MkF28Myb9XetU8ziNSFeS5ViiMBY52t1j0OF0b5jUazRwuw5ZW49f2JWhl2XB1XTysCOIk3Ki+wt6mw32EjCKtu+r2wJDZO8pq4mmmlFEjBTrseu4OJOKnj69DklvyTGsc3/rU5PiJ55nJ/KF07lHcBFqx9iLgNJp52zQzYe6+4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784979340; c=relaxed/simple; bh=TMAvT1bQIxy0abaqqqm5vUfMOE9XtW4X7/4SncUse7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=etcxTqdl6nMar7gEHTNZmt+3zSdfYwpOeSrRRuLhyUWGh7vGfA3ilrIYbc1knDsUU7HCdTiIumeVysq2qW4UUxI9/H2q7efFpldE/iWcEZibVBiUU8G3EMRDxr7W2PxO8hGXTyBM6icr+TD1n/JdQrFuybobpVeE6W9Vu60bFHw= 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=Jj7FeVbZ; arc=none smtp.client-ip=209.85.216.49 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="Jj7FeVbZ" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3856d6fbcb3so950666a91.2 for ; Sat, 25 Jul 2026 04:35:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784979339; x=1785584139; 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=AXIwBDXgHdbOW1IakbnrDMGsgn739j8hqGA9qy4lB8M=; b=Jj7FeVbZzlmF3e6GOiqIsmdCJj6c8oB2wkSna34lZ7LOIi2OblahFm30+i7l2msAK4 ogDSAYlmhkf5ixQSVi9uxftH0QESSG94rVm8axOx4G7YRiXnqzENlNbAtpzpgANc1t7Z f20MXb9E/KGrNONdlXiRX+86S3KemVOThYtTRgXSiT0zb0CnsuDof4jPu/ZEmeDpRCly ORCbVKhRBwvWRa9WI0sDUFrdFrV+8Jx90q+QEg/zCyV+C+1injoJa8sBDD4GeYRLFRf7 wNYZqcHDu318uqFcWW7ESGU443ZNn5gpkcjAVeuT9G5ugL9wb//nHjSZC1WEdenvsdZ3 2EgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784979339; x=1785584139; 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=AXIwBDXgHdbOW1IakbnrDMGsgn739j8hqGA9qy4lB8M=; b=ivzM9aL7Ky0sO7ZpVt/Md0pa67XxMaIRfjJpS+v2NrSpUb7yiH6inO8bhPx6N1C6Uh yE3vTPUgljCpGb0g7eYaBjkOb8d4F2iJF2q2cHnuxdqoH9zLoK+LIodfW25BFQE0z2K2 te9tQ4lOo0Uoa7487R/6HumwbEiSNAavr6Ts2BUIf0ZvL1gH/b7cOWltBR1DIPz1ZOlS OQ030osMeQPF5Ktdinee5ONI/M1+fcdiiY4fmoxBotS2U/oxOCjCIMaEr+nu9e2VJGKa 73RRZTllyicjnOCxvBuU0yXMdh20peNJ1UXGsNhqxv0/pWFdRjherCVYdCSzsRuFPGyk OPWA== X-Forwarded-Encrypted: i=1; AHgh+RryAU2WMy48A300Fp6D+NjH26AyPzXK5PlFb0aRIWWBcU9WmV/YYrG8BMqu+0ALyn/chfsEnS08azFv3sA=@vger.kernel.org X-Gm-Message-State: AOJu0YzfYA1/EJa3FNMtrOawfASqU2f/iFg7uitXPhh6SMKCdkqPwAGO s9+vJvWKi/ucEZKJRT+h7vFHBm6imh8U6Z7U64gtoPfVSJ5NuOOyHRgL X-Gm-Gg: AR+sD12AqMTYPPzJRjlPZZc8iBK2mXX+Xcjt7i5qolNQc7OP4P5HIPwGHaRgfpPO+xi F3CJIVvlt1NaafViYSxYigoDYvUHo4F33e0QCBi8CeSRzl/2RfmzxBe39MrjSyt0JjlvVR3yb70 wnae+7hjEQbR6IgnPLiBKL+dC1NWkrHfdFPePW9ewXI1iDqNXnqBa4ovWCQJJgHSk/FvPKoCKmR lRIrswKi3VGmHWPgE7xfG07AAj4aSNx2CoNxG6EhqOVAYVKVsQiWrmLutkoPSzi1uQmMUTHBQgx EaA4xzKrjcSWzQhnJmxvAA/JMac7DFfYxEtWsiXbFpLzQYAb7tEljkr4gAoYHk9unSiis0c7S3J tXOI8RVw/WWbui3U5fnNTB/9T2y1n4wy5MQAb3FVpthY8PyQtikRd9mfNBM+J2dFR50NckjWI X-Received: by 2002:a17:90b:3c8e:b0:38e:69ae:7148 with SMTP id 98e67ed59e1d1-38f2960cb21mr2041956a91.24.1784979338624; Sat, 25 Jul 2026 04:35:38 -0700 (PDT) Received: from ubuntu.. ([110.9.142.4]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-38f08ae3079sm1539083a91.3.2026.07.25.04.35.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jul 2026 04:35:37 -0700 (PDT) From: Sang-Heon Jeon To: Julia Lawall , Nicolas Palix Cc: cocci@inria.fr, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] coccinelle: misc: minmax: improve performance when no candidate exists Date: Sat, 25 Jul 2026 20:32:41 +0900 Message-ID: <20260725113303.691676-4-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 rules that report an opencoded min() or max() search every function body, even when the file contains nothing to find. To avoid this, collect the candidates first and run the search only when one exists. A candidate is any conditional expression whose condition is a comparison. Every opencoded min() or max() is also a candidate, so the same opportunities are reported 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/misc/minmax.cocci | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/coccinelle/misc/minmax.cocci b/scripts/coccinelle/misc/minmax.cocci index ca4830ae3042..93c074b9439f 100644 --- a/scripts/coccinelle/misc/minmax.cocci +++ b/scripts/coccinelle/misc/minmax.cocci @@ -17,7 +17,21 @@ virtual org virtual context virtual patch -@rmax depends on !patch@ +@max_candidate@ +expression E1, E2, E3, E4; +binary operator cmp = {>, >=}; +@@ + + (E1 cmp E2 ? E3 : E4) + +@min_candidate@ +expression E1, E2, E3, E4; +binary operator cmp = {<, <=}; +@@ + + (E1 cmp E2 ? E3 : E4) + +@rmax depends on !patch && max_candidate@ identifier func; expression x, y; binary operator cmp = {>, >=}; @@ -51,7 +65,7 @@ func(...) } // Ignore errcode returns. -@errcode@ +@errcode depends on min_candidate@ position p; identifier func; expression x; @@ -65,7 +79,7 @@ func(...) ...> } -@rmin depends on !patch@ +@rmin depends on !patch && min_candidate@ identifier func; expression x, y; binary operator cmp = {<, <=}; @@ -98,7 +112,7 @@ func(...) ...> } -@pmax depends on patch@ +@pmax depends on patch && max_candidate@ identifier func; expression x, y; binary operator cmp = {>=, >}; @@ -131,7 +145,7 @@ func(...) ...> } -@pmin depends on patch@ +@pmin depends on patch && min_candidate@ identifier func; expression x, y; binary operator cmp = {<=, <}; -- 2.43.0