From: Paolo Bonzini Date: Mon, 29 Aug 2016 16:38:53 +0000 Subject: Re: [PATCH 1/2] sparc: Use kmalloc_array() in three functions Message-Id: List-Id: References: <0ca0235c-ddb9-0534-3bde-b4aaa48da92e@users.sourceforge.net> <4475e65d-415d-9cde-1fe1-c17e120849c4@redhat.com> <57C42335.5000106@bfs.de> In-Reply-To: <57C42335.5000106@bfs.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: wharms@bfs.de Cc: SF Markus Elfring , sparclinux@vger.kernel.org, "David S. Miller" , LKML , kernel-janitors@vger.kernel.org, Julia Lawall On 29/08/2016 13:57, walter harms wrote: > > > - buf = kmalloc(sizeof(char) * (count + 1), GFP_KERNEL); > > > + buf = kmalloc_array(count + 1, sizeof(*buf), GFP_KERNEL); > > > if (!buf) > > > return -ENOMEM; > > > > > > > Here it's probably best to just remove sizeof(char) completely, as it's > > 1 by definition. > > I would not do so, if you ever change buf to something else it would break, > having a sizeof(*buf) here is harmless and a known pattern. Fair enough, it's not code I maintain. Paolo