Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754661AbbFWKvz (ORCPT ); Tue, 23 Jun 2015 06:51:55 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:10571 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754652AbbFWKvs (ORCPT ); Tue, 23 Jun 2015 06:51:48 -0400 X-IronPort-AV: E=Sophos;i="5.13,665,1427752800"; d="scan'208";a="137478986" Date: Tue, 23 Jun 2015 12:51:45 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Dan Carpenter cc: Julia Lawall , "devel@driverdev.osuosl.org" , "Dilger, Andreas" , Greg Kroah-Hartman , "kernel-janitors@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "Drokin, Oleg" , "lustre-devel@lists.lustre.org" Subject: Re: [PATCH 01/12] staging: lustre: fid: Use !x to check for kzalloc failure In-Reply-To: <20150623095704.GO28762@mwanda> Message-ID: References: <1434819550-3193-1-git-send-email-Julia.Lawall@lip6.fr> <1434819550-3193-2-git-send-email-Julia.Lawall@lip6.fr> <20150623092303.GN28762@mwanda> <20150623095704.GO28762@mwanda> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2083 Lines: 75 On Tue, 23 Jun 2015, Dan Carpenter wrote: > Yes. I know Al's thoughts and kernel style. > > But Alan Cox and Andreas have both said they think (x == NULL) can help > you avoid some kind of boolean vs pointer bugs. I've had co-workers who > did massive seds changing !foo to foo == NULL on our code base. But > I've never seen a real life example of a bug this fixes. > > To be honest, I've never seen a real life proof that (!foo) code is less > buggy. I should look through the kbuild mailbox... Hm... But my other > idea of setting up code style readability testing website is also a good > one. > > Linux kernel style is based on Joe Perches finding that 80% of the code > prefers one way or the other. That's a valid method for determining > code style. I bet it normally picks the more readable style but it > would be interesting to measure it more formally. On today's linux-next, I find 3218 tests on the result of kmalloc etc using NULL and 14429 without, making 82% without. The complete semantic patch is shown below. julia @initialize:ocaml@ @@ let withnull = ref 0 let withoutnull = ref 0 @r1 disable is_null, isnt_null1 exists@ expression x,e; position p; statement S1,S2; @@ x = \(kmalloc\|kzalloc\|kcalloc\|devm_kmalloc\|devm_kzalloc\)(...) ... when != x = e when != &x if@p (<+...\(x == NULL\|x != NULL\|NULL == x\|NULL != x\)...+>) S1 else S2 @r2 disable not_ptr1, not_ptr2 exists@ expression x,e; position p; statement S1,S2; @@ x = \(kmalloc\|kzalloc\|kcalloc\|devm_kmalloc\|devm_kzalloc\)(...) ... when != x = e when != &x if@p (<+...\(!x\|x && ...\|x || ...\)...+>) S1 else S2 @script:ocaml@ _p << r1.p; @@ withnull := !withnull + 1 @script:ocaml@ _p << r2.p; @@ withoutnull := !withoutnull + 1 @finalize:ocaml@ @@ Printf.printf "withnull %d withoutnull %d\n" !withnull !withoutnull -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/