From nobody Fri Oct 2 10:09:09 2026 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10559311958 for ; Sun, 2 Aug 2026 19:30:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.134.164.104 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785699017; cv=none; b=GLA1xJESjG4wLCP9vpUV6Riij37IjIjjWboxFiwimbErPt2Mf2nI8DfmQhwQmBI+Mob3GVIKW4R2ArEdlHhiPmW5E2ZQcx0vew88gGPZnY1t/z2JsG50G8EeMG+qIqX3IWarQk9rw9574yJG8xnVTu8mD/ZGE9Jj8j5N59iBBxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785699017; c=relaxed/simple; bh=yTH3hdNvAlhrSNqxjA+3YP+tuC8uUbgPi93okHyttJw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=n7SajV/s/INeqOQNfxzVQ5CXlh4Gy8+kf4SlIWEld6ok3tkXZR74ko+UNL5RthRJLXna/YrCsU9O77NEVCnBwmvs796+sFh+oeU4foM3SIOu8x+PEaSMQ4Xild7hhBkOIxCJ6IOP7WT3NFWngupgC/jK21kQ3hgmFlxF0Gey8j8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr; spf=pass smtp.mailfrom=inria.fr; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b=pecm6ErX; arc=none smtp.client-ip=192.134.164.104 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=inria.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=inria.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=inria.fr header.i=@inria.fr header.b="pecm6ErX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=qZqViyDfghPjBb7mCZQVi4QVxyhF8GzsIG5qzzolxs8=; b=pecm6ErXYwtN+P4zzMzu1SjE4L/pVuMxHEVeQfhKXT7f+xoFJtJh/pN9 VUIA+y+hOFmokcMFL+c4sHomxdK/PvAXCsQbc/w2pAMcTnNy/eKXKrTCh v70KQvI1+2uoyCg8S/3LtkX6pTz8t8Ggz/S38cazKpJbruqe7DL5djm35 k=; X-CSE-ConnectionGUID: neFT/PIpQLuj6UReWZhOVg== X-CSE-MsgGUID: CNHspn7IRFqF011QcCYnGA== Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Julia.Lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.25,201,1779141600"; d="scan'208";a="153479549" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.102.196]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Aug 2026 21:30:10 +0200 From: Julia Lawall To: Julia Lawall Cc: rostedt@goodmis.org, Nicolas Palix , cocci@inria.fr, linux-kernel@vger.kernel.org Subject: [PATCH] Coccinelle: alloc_cast: coccinelle: api: check for macro context Date: Sun, 2 Aug 2026 21:29:57 +0200 Message-Id: <20260802192957.1425245-1-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.39.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A cast on a call to an allocation function that is the body of a macro can be useful, as it ensures tha the macro is used for allocating objects of the right type. Add two new rules to ignore the macro case. Suggested-by: Steven Rostedt Signed-off-by: Julia Lawall --- scripts/coccinelle/api/alloc/alloc_cast.cocci | 23 +++++++++++++++++++++= -- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/coccinelle/api/alloc/alloc_cast.cocci b/scripts/coccin= elle/api/alloc/alloc_cast.cocci index f6f0ccdb6409..958c914f8ba6 100644 --- a/scripts/coccinelle/api/alloc/alloc_cast.cocci +++ b/scripts/coccinelle/api/alloc/alloc_cast.cocci @@ -20,6 +20,24 @@ virtual patch virtual org virtual report =20 +@m1@ +identifier i; +expression e; +type T; +position p1; +@@ + +#define i (T@p1 *)e + +@m2@ +identifier i; +expression e; +type T; +position p2; +@@ + +#define i(...) (T@p2 *)e + @initialize:python@ @@ import re @@ -28,9 +46,10 @@ m =3D re.compile(pattern) =20 @r1 depends on context || patch@ type T; +position p !=3D {m1.p1,m2.p2}; @@ =20 - (T *) + (T@p *) \(kmalloc\|kzalloc\|kcalloc\|kmem_cache_alloc\|kmem_cache_zalloc\| kmem_cache_alloc_node\|kmalloc_node\|kzalloc_node\|vmalloc\|vzalloc\| dma_alloc_coherent\|devm_kmalloc\|devm_kzalloc\| @@ -90,7 +109,7 @@ type r1.T; =20 @r2 depends on org || report@ type T; -position p; +position p !=3D {m1.p1,m2.p2}; @@ =20 (T@p *)