Return-path: Received: from mail.net.t-labs.tu-berlin.de ([130.149.220.252]:60064 "EHLO mail.net.t-labs.tu-berlin.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754304Ab2F2NPp (ORCPT ); Fri, 29 Jun 2012 09:15:45 -0400 Message-ID: <4FEDAA6A.3000902@net.t-labs.tu-berlin.de> (sfid-20120629_151548_536674_A88F4C50) Date: Fri, 29 Jun 2012 06:15:22 -0700 From: thomas MIME-Version: 1.0 To: Schrober CC: Julian Calaby , linux-wireless@vger.kernel.org, johannes@sipsolutions.net, nbd@openwrt.org Subject: Re: [PATCH] mac80211: correct size the argument to kzalloc in minstrel_ht References: <1340926085-54416-1-git-send-email-thomas@net.t-labs.tu-berlin.de> <4FED3679.4080107@net.t-labs.tu-berlin.de> <1487602.AtWAA39W7Q@bentobox> In-Reply-To: <1487602.AtWAA39W7Q@bentobox> Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-wireless-owner@vger.kernel.org List-ID: Schrober schrieb: > On Thursday 28 June 2012 22:00:41 thomas wrote: >> Hi Julian, >> >> Compiler wise both of our suggestions will lead to the same machine code. >> So beside the matter of taste, I just followed the other overall usage >> pattern of kzalloc in minstrel_ht. >> And it seems to be explicitly using the struct type. > > http://lxr.linux.no/linux/Documentation/CodingStyle > > Chapter 14: Allocating memory > > The kernel provides the following general purpose memory allocators: > kmalloc(), kzalloc(), 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: > > 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. Good to have this clarified. I will send a version 2. Thx Thomas