From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759481AbdEVWlr (ORCPT ); Mon, 22 May 2017 18:41:47 -0400 Received: from smtprelay0157.hostedemail.com ([216.40.44.157]:43980 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750715AbdEVWlq (ORCPT ); Mon, 22 May 2017 18:41:46 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2553:2559:2562:2828:2911:3138:3139:3140:3141:3142:3353:3622:3653:3865:3866:3867:3868:3870:3871:3873:3874:4031:4321:4425:5007:7903:7904:8603:9040:10004:10400:10848:10967:11232:11658:11914:12043:12049:12114:12555:12740:12760:12895:12986:13069:13255:13311:13357:13439:13869:13870:14096:14097:14181:14659:14721:21080:21433:21627:30005:30012:30029:30054:30056:30070:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: beef01_839495b04f53f X-Filterd-Recvd-Size: 2149 Message-ID: <1495492902.2093.54.camel@perches.com> Subject: Re: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as preferred allocation form From: Joe Perches To: Andrew Morton Cc: Alexey Dobriyan , linux-kernel@vger.kernel.org Date: Mon, 22 May 2017 15:41:42 -0700 In-Reply-To: <20170522152227.52a9a7c48e8141056fc612c4@linux-foundation.org> References: <20170522213837.GA13861@avx2> <1495489398.2093.48.camel@perches.com> <20170522152227.52a9a7c48e8141056fc612c4@linux-foundation.org> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2017-05-22 at 15:22 -0700, Andrew Morton wrote: > On Mon, 22 May 2017 14:43:18 -0700 Joe Perches wrote: > > On Tue, 2017-05-23 at 00:38 +0300, Alexey Dobriyan wrote: > > > * ratio of allocation styles is ~6400:12000 which is about 1:2 > > > so the amount of churn to maintain this rule is pretty high in theory. I got: $ git grep -E "alloc.*\bsizeof\s*\(\s*[^\*]" | wc -l 8114 $ git grep -E "alloc.*\bsizeof\s*\(\s*[\*]" | wc -l 12198 > > > -The preferred form for passing a size of a struct is the following: > > > - > > > -.. code-block:: c > > > - > > > - p = kmalloc(sizeof(*p), ...); > > > - > > > -The alternative form where struct name is spelled out hurts readability and > > > -introduces an opportunity for a bug when the pointer variable type is changed > > > -but the corresponding sizeof that is passed to a memory allocator is not. > > > - > > > > Thanks. I agree with this deletion. > > I don't. Every damn time I see a p = kmalloc(sizeof struct foo) I have > to hunt around to check the type of p. And I review a lot of code! Yeah, I read a lot of patches with you. But there are real reasons to use sizeof(type) too. And changing existing uses is pretty pointless.