Received: by 10.223.164.202 with SMTP id h10csp165726wrb; Fri, 10 Nov 2017 04:25:55 -0800 (PST) X-Google-Smtp-Source: AGs4zMbo9OrMT+Ue65foXqFqBz8uqUa5FhM8i+dBuGJbyYyOxA5xbvqs9UI+OQc+l+7nc8NTjh/t X-Received: by 10.98.35.18 with SMTP id j18mr180398pfj.37.1510316755718; Fri, 10 Nov 2017 04:25:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510316755; cv=none; d=google.com; s=arc-20160816; b=CfWeN6G8MLtOS/ZH+vNut+XycJ3Q9TCo200KT7BkGJkCQhYN7DgjjU/h1M+AuMABSG dEjh94VPjndJvzdZVagATJ+bAPfg8EqhqGTpkkUJpuuOtsfPfB+3PelWqmx76NN6j7bT g17gaSImQCNA4cWeX42GtmdD/gtq2yOSyVKp/Iv//Nm95fPhEUfAcmyAhI8bcY3T/rR9 UpSrAAGGr3CD347zn9GDWvg6J0l2Lenvnp82qfjaIm62t5wKPrRu7YOwgx5Y091olZgp p4tS7h+B4ekE3Ud5Oug+KSvzpT10da1YExMSmGAG8CSKdodU63HQq3RkMbXi1QmQgI3t 1gfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=Rwb+Bl0enyxLbbq99y1qt0Zd0O0dXMENjUvWGOgVhYU=; b=x/KMkxMl8bbVfEsEe3zeUO1YH9W0BT1SMHdDE4MosYH09yauy9NJV6bdt73cEu+gfk vY9yIZ7xeGQC4P/nUkK1jmi+E0zqu/ioJC/4RXf5V9QrUEVBEy4Lw4YkPw1SsSTqdWfR h5ihkpeIRbpdW00BMeoDi3FkQLWalB13DwVQBuAPKhvU+K8GstK7206lYHAEJqq+ViIZ vhNDztWSio3YvfMF5QGjbx7rTmFRPv8PKwmbS06FffyqQWn+Bby/8+fluCEy8cGjVQjr GIYbSL6hVNGecfBDYo1v8/UHkd5EsHhp7EJ7TIYN4gwwSDEbRNsfiKXUWqQFgSzmSWQe mtag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Xu3Wg6DW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f68si9331984pfb.395.2017.11.10.04.25.44; Fri, 10 Nov 2017 04:25:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Xu3Wg6DW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752257AbdKJMZH (ORCPT + 82 others); Fri, 10 Nov 2017 07:25:07 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:56872 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751024AbdKJMZG (ORCPT ); Fri, 10 Nov 2017 07:25:06 -0500 Received: by mail-pg0-f65.google.com with SMTP id z184so1880104pgd.13 for ; Fri, 10 Nov 2017 04:25:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Rwb+Bl0enyxLbbq99y1qt0Zd0O0dXMENjUvWGOgVhYU=; b=Xu3Wg6DWyNePPwUnvNvKtOdhiL80DN0FOL0/XjS3G4UbBEpurwyWcAPQwiaXY5Afsa C0bhP+hTJf26OEvY8rRqUckDhFksB4gqO6Wt0sWORtTimvNWvHfPzdNCJE7tTrdCSQGu sjje1zdKLdyxqNfq5cGzI9S5x+BCbKPk4dW0P6w8RXBSdncfjZqMtY5sLk12yxYgcHde vU4kUTJoO6B7I4nLnBQR749K5RKmOZRkz2X7vdvjyExJl7BVrd/3jsXPUkgUzKFRyVlX 9A1sGsf158+zCI811Jv0RDF1Q0ZR7dpNgqlmPrKvtE+w8YKpKrCPFJSzzBqgAIW/q2MW Ivlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Rwb+Bl0enyxLbbq99y1qt0Zd0O0dXMENjUvWGOgVhYU=; b=FI33bQtIYwTWYQUoiiKNWAFjTNf/O1H3oqd8LiCkpk683UNdNWALP5M9xYW6RjB9KE qxCazUH6MndmBQ1YwC9lPoNfAwD1omQvy95Q0qD2sSAZONToE94UGKkj1irfcPXvTl5U sarankBdXKLOoJVYWTLnLIMaswgoJ8GY6qH4wRQT46wgKS7AiiJCzPUT3SQey87DLJXZ uWrZX9pE5zHqQ4ymkwgGrlfIbNttFGJaAY2Sw1aBj4XT6mK84QyGTiQ0OgMOFadM1xB+ N1eC+UAOuPv1Cs3A9VKjrJIdqCMJad1Q8+Kqwz+NNcthDxYTpvtuySVCKxY5zkzuZ2rr ssww== X-Gm-Message-State: AJaThX5ORXcGQP6mj1mtHOVG7hp4vMLbDoFD+tODaLaPX2RHG4ncSRMM KRFu/P61ssl8PQPnqsI5Cs8= X-Received: by 10.101.65.6 with SMTP id w6mr146932pgp.365.1510316705722; Fri, 10 Nov 2017 04:25:05 -0800 (PST) Received: from localhost.localdomain ([103.46.195.130]) by smtp.gmail.com with ESMTPSA id w1sm3404803pgq.34.2017.11.10.04.25.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Nov 2017 04:25:04 -0800 (PST) From: Himanshu Jha To: Julia.Lawall@lip6.fr Cc: Gilles.Muller@lip6.fr, nicolas.palix@imag.fr, michal.lkml@markovi.net, linux-kernel@vger.kernel.org, cocci@systeme.lip6.fr, mcgrof@kernel.org, Himanshu Jha Subject: [PATCH] Coccinelle: Add scripts/coccinelle/alloc/vzalloc-simple.cocci Date: Fri, 10 Nov 2017 17:54:47 +0530 Message-Id: <1510316687-5741-1-git-send-email-himanshujha199640@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use vzalloc rather than vmalloc followed by memset with region of memory filled with 0 value. It considers only simple cases. 0-day tested without any issues. Signed-off-by: Himanshu Jha --- scripts/coccinelle/api/alloc/vzalloc-simple.cocci | 75 +++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 scripts/coccinelle/api/alloc/vzalloc-simple.cocci diff --git a/scripts/coccinelle/api/alloc/vzalloc-simple.cocci b/scripts/coccinelle/api/alloc/vzalloc-simple.cocci new file mode 100644 index 0000000..c9c3b20 --- /dev/null +++ b/scripts/coccinelle/api/alloc/vzalloc-simple.cocci @@ -0,0 +1,75 @@ +/// +/// Use vzalloc instead of vmalloc followed by memset 0 +/// +// Confidence: High +// Copyright: (C) 2017 Himanshu Jha GPLv2. +// Options: --no-includes --include-headers +// +// Keywords: vzalloc, vmalloc +// + +virtual context +virtual patch +virtual org +virtual report + +//---------------------------------------------------------- +// For context mode +//---------------------------------------------------------- + +@depends on context@ +type T, T1; +expression x,E1; +statement S; +@@ + +* x = (T)vzalloc(E1); + if ((x == NULL) || ...) S +* memset((T1)x, 0, E1); + +//---------------------------------------------------------- +// For patch mode +//---------------------------------------------------------- + +@depends on patch@ +type T, T1; +expression x,E1; +statement S; +@@ + +- x = (T)vmalloc(E1); ++ x = vzalloc(E1); + if ((x == NULL) || ...) S +- memset((T1)x, 0, E1); + +//---------------------------------------------------------- +// For org mode and report mode +//---------------------------------------------------------- + +@r depends on org || report@ +type T, T1; +expression x,E1; +statement S; +position p; +@@ + + x = (T)vmalloc@p(E1); + if ((x==NULL) || ...) S + memset((T1)x, 0, E1); + +@script:python depends on org@ +p << r.p; +x << r.x; +@@ + +msg="%s" % (x) +msg_safe=msg.replace("[","@(").replace("]",")") +coccilib.org.print_todo(p[0], msg_safe) + +@script:python depends on report@ +p << r.p; +x << r.x; +@@ + +msg="WARNING: vzalloc should be used for %s, instead of vmalloc/memset" % (x) +coccilib.report.print_report(p[0], msg) -- 2.7.4 From 1584149884103114803@xxx Wed Nov 15 16:24:17 +0000 2017 X-GM-THRID: 1584149884103114803 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread