From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753005AbbCXU5S (ORCPT ); Tue, 24 Mar 2015 16:57:18 -0400 Received: from smtprelay0214.hostedemail.com ([216.40.44.214]:58636 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752146AbbCXU5P (ORCPT ); Tue, 24 Mar 2015 16:57:15 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::,RULES_HIT:41:355:379:541:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2692:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3870:3871:3874:4184:4250:4321:4385:5007:6261:7875:7901:7903:7904:8603:8660:10004:10400:10848:11232:11658:11914:12043:12517:12519:12663:12740:13069:13148:13161:13229:13230:13311:13357:14096:14097:21060:21080,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: thumb49_5ae22a7c8832f X-Filterd-Recvd-Size: 2734 Message-ID: <1427230622.12126.13.camel@perches.com> Subject: Re: [PATCH] [RESEND] aic7xxx: replace kmalloc/memset by kzalloc From: Joe Perches To: Michael Opdenacker Cc: Hannes Reinecke , JBottomley@parallels.com, Elliott@hp.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 24 Mar 2015 13:57:02 -0700 In-Reply-To: <5511CD10.6040709@free-electrons.com> References: <94D0CD8314A33A4D9D801C0FE68B40295930E577@G4W3296.americas.hpqcorp.net> <1427041891-2694-1-git-send-email-michael.opdenacker@free-electrons.com> <550FB9BE.5010801@suse.de> <5511CD10.6040709@free-electrons.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.10-0ubuntu1~14.10.1 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, 2015-03-24 at 13:46 -0700, Michael Opdenacker wrote: > Hi, > > On 03/22/2015 11:59 PM, Hannes Reinecke wrote: > > On 03/22/2015 05:31 PM, Michael Opdenacker wrote: > >> This replaces kmalloc + memset by a call to kzalloc > >> (or kcalloc when appropriate, which zeroes memory too) > >> > >> This also fixes one checkpatch.pl issue in the process. > >> > >> This improvement was suggested by "make coccicheck" > >> > >> Signed-off-by: Michael Opdenacker > > Reviewed-by: Hannes Reinecke > > I'm sending a version that reverts the use of kcalloc() instead of > kzalloc(). For reasons I don't understand, I didn't see the end of > Robert Elliott's comment that the use of kcalloc() could prevent the > compiler from detecting an overflow. I'm confused. I don't see that comment either, but the entire point of kcalloc is to prevent overflows by returning NULL when an overflow might occur. from include/linux/slab.h: /** * kmalloc_array - allocate memory for an array. * @n: number of elements. * @size: element size. * @flags: the type of memory to allocate (see kmalloc). */ static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) { if (size != 0 && n > SIZE_MAX / size) return NULL; return __kmalloc(n * size, flags); } /** * kcalloc - allocate memory for an array. The memory is set to zero. * @n: number of elements. * @size: element size. * @flags: the type of memory to allocate (see kmalloc). */ static inline void *kcalloc(size_t n, size_t size, gfp_t flags) { return kmalloc_array(n, size, flags | __GFP_ZERO); }