From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934956AbdEVVn1 (ORCPT ); Mon, 22 May 2017 17:43:27 -0400 Received: from smtprelay0101.hostedemail.com ([216.40.44.101]:39089 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933917AbdEVVnY (ORCPT ); Mon, 22 May 2017 17:43:24 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:69:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1431:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2199:2393:2553:2559:2562:2693:2828:2892:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3874:4031:4250:4321:4362:5007:6119:7514:7903:7904:8603:10004:10400:10848:11232:11658:11914:12043:12114:12555:12740:12760:12895:12986:13069:13255:13311:13357:13439:13869:13870:14096:14097:14181:14659:14721:14777:21080:21433:21451:21627:30005:30029:30054:30056:30070:30075:30083: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:2,LUA_SUMMARY:none X-HE-Tag: sense29_3a39d72813940 X-Filterd-Recvd-Size: 2648 Message-ID: <1495489398.2093.48.camel@perches.com> Subject: Re: [PATCH] CodingStyle: delete "kmalloc(sizeof(*var))" as preferred allocation form From: Joe Perches To: Alexey Dobriyan , akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org Date: Mon, 22 May 2017 14:43:18 -0700 In-Reply-To: <20170522213837.GA13861@avx2> References: <20170522213837.GA13861@avx2> 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 Tue, 2017-05-23 at 00:38 +0300, Alexey Dobriyan wrote: > There are valid reasons for > > malloc(sizeof(struct S)) > > form: > > * struct S acts as an anchor for ctags quickly reminding which type is > in focus > > * argument re changing name prevents bugs is semi bogus: > such changes are rare, > "void *" cast gives both forms equal opportunity to be screwed up > > * proper way to fix those rare misallocation bugs (which indeed happened) > is type safe allocation macros (see tmalloc from Samba). > > However amount of disruption will be so high so it may never be done. > > * 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. > > The winning move is to not play and not encourage people send trivial stuff. > > Signed-off-by: Alexey Dobriyan > --- > > Documentation/process/coding-style.rst | 10 ---------- > 1 file changed, 10 deletions(-) > > --- a/Documentation/process/coding-style.rst > +++ b/Documentation/process/coding-style.rst > @@ -808,16 +808,6 @@ kmalloc(), kzalloc(), kmalloc_array(), kcalloc(), vmalloc(), and > vzalloc(). Please refer to the API documentation for further information > about them. > > -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. > - > Casting the return value which is a void pointer is redundant. The conversion > from void pointer to any other pointer type is guaranteed by the C programming > language. Thanks. I agree with this deletion.