From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755497AbbHFMRn (ORCPT ); Thu, 6 Aug 2015 08:17:43 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:46939 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753633AbbHFMRl (ORCPT ); Thu, 6 Aug 2015 08:17:41 -0400 X-AuditID: cbfec7f4-f79c56d0000012ee-47-55c35062182a From: Andrzej Hajda To: Julia Lawall Cc: Andrzej Hajda , Marek Szyprowski , Bartlomiej Zolnierkiewicz , Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr (moderated list:COCCINELLE/Semantic Patches (SmPL)), linux-kernel@vger.kernel.org Subject: [PATCH] coccinelle: memdup.cocci: fix matching rules Date: Thu, 06 Aug 2015 14:14:14 +0200 Message-id: <1438863254-19897-1-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupiluLIzCtJLcpLzFFi42I5/e/4Nd2kgMOhBgvnaFncWneO1WLjjPWs Fj82rWazmP3zEpPFsgenGS0u75rDZrH2yF12izmts9gsjr1czuTA6XHsWCuzx94tWR59W1Yx eqzfcpXF49Gy+ywenzfJBbBFcdmkpOZklqUW6dslcGV82fqDtWCTUMX/k2tZGxif8nUxcnJI CJhILLy7kQ3CFpO4cG89kM3FISSwlFHi19/vrBBOE5PEjn3zmUCq2AQ0Jf5uvgnWISKgLtG6 YRcjSBGzwFsmial3d7KCJIQFbCVudc8Aa2ARUJXYeH4lUAMHB6+As8Si6bkQ2+QkTh6bzDqB kXsBI8MqRtHU0uSC4qT0XEO94sTc4tK8dL3k/NxNjJAQ+rKDcfExq0OMAhyMSjy8D9YcChVi TSwrrsw9xCjBwawkwvtQ/3CoEG9KYmVValF+fFFpTmrxIUZpDhYlcd65u96HCAmkJ5akZqem FqQWwWSZODilGhgThZreVfZ9XzaT4ei3D0t73kk0KXDMvtx/tVvjvCn7wrOCX+4rB01ddchK xdNeaUrtp//VvX/kHuRyy8aWXE+YYLnr5Z3wtJQVh/rr3dft5ZSPszevvOHpVXtypsM2rYcL D551qjrAI3t9msDsZrmCM688Q1cuil22bN7cndLunGLfOEx/bTijxFKckWioxVxUnAgA6GH4 Fx0CAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes three things, listed in order of importance. 1. Removes matching of kmemdup from !patch rule - it is incorrect and in fact makes report mode unusable. 2. Adds unlikely to if clause. It allows to match more cases - the ones with unlikely and the ones without it. 3. Fixes report message. Signed-off-by: Andrzej Hajda --- Hi Julia, I guess 1st and 3rd changes are OK. I am not sure about 2nd change, without it I was not able to catch cases containing unlikely macro. For example fs/ntfs/dir.c:1175: ir = kmalloc(rc, GFP_NOFS); if (unlikely(!ir)) { err = -ENOMEM; goto err_out; } /* Copy the index root value (it has been verified in read_inode). */ memcpy(ir, (u8*)ctx->attr + le16_to_cpu(ctx->attr->data.resident.value_offset), rc); It seems quite strange for me, as these rules looks to me isomorphic. Is this expected behavior of coccinelle or just some bug? After this fix, cocci finds 46 places to patch, I will send patchset if this change looks OK to you. I have used: spatch version 1.0.1 with Python support and with PCRE support latest linux-next. Regards Andrzej --- scripts/coccinelle/api/memdup.cocci | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/coccinelle/api/memdup.cocci b/scripts/coccinelle/api/memdup.cocci index 3d1aa71..2297205 100644 --- a/scripts/coccinelle/api/memdup.cocci +++ b/scripts/coccinelle/api/memdup.cocci @@ -39,7 +39,7 @@ statement S; - to = \(kmalloc@p\|kzalloc@p\)(size,flag); + to = kmemdup(from,size,flag); - if (to==NULL || ...) S + if (unlikely(to==NULL) || ...) S - memcpy(to, from, size); @r depends on !patch@ @@ -49,18 +49,17 @@ statement S; @@ * to = \(kmalloc@p\|kzalloc@p\)(size,flag); - to = kmemdup(from,size,flag); - if (to==NULL || ...) S + if (unlikely(to==NULL) || ...) S * memcpy(to, from, size); @script:python depends on org@ p << r.p; @@ -coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdep") +coccilib.org.print_todo(p[0], "WARNING opportunity for kmemdup") @script:python depends on report@ p << r.p; @@ -coccilib.report.print_report(p[0], "WARNING opportunity for kmemdep") +coccilib.report.print_report(p[0], "WARNING opportunity for kmemdup") -- 1.9.1