From mboxrd@z Thu Jan 1 00:00:00 1970 From: Joe Perches Date: Tue, 23 May 2017 14:02:13 +0000 Subject: Re: [PATCH] tipc: Delete error messages for failed memory allocations in three functions Message-Id: <1495548133.2093.58.camel@perches.com> List-Id: References: <7ac9d513-6f9f-a096-e68f-81a722c2723c@users.sourceforge.net> In-Reply-To: <7ac9d513-6f9f-a096-e68f-81a722c2723c@users.sourceforge.net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: SF Markus Elfring , tipc-discussion@lists.sourceforge.net, netdev@vger.kernel.org, "David S. Miller" , Jon Maloy , Ying Xue Cc: LKML , kernel-janitors@vger.kernel.org On Tue, 2017-05-23 at 15:07 +0200, SF Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 23 May 2017 14:45:25 +0200 > > Omit four extra messages for memory allocation failures in these functions. This is fine but you should look to optimize or figure out whether optimization is desirable for the effective realloc. > diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c [] > @@ -270,11 +268,9 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net, > if (nseq->first_free = nseq->alloc) { > struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2); > > - if (!sseqs) { > - pr_warn("Cannot publish {%u,%u,%u}, no memory\n", > - type, lower, upper); > + if (!sseqs) > return NULL; > - } > + > memcpy(sseqs, nseq->sseqs, > nseq->alloc * sizeof(struct sub_seq)); tipc_subseq_alloc does a kcalloc (memset to 0), half of which is immediately overwritten. In other words, don't just blindly remove stuff, understand what it does and improve it. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968053AbdEWOCX (ORCPT ); Tue, 23 May 2017 10:02:23 -0400 Received: from smtprelay0068.hostedemail.com ([216.40.44.68]:60404 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933134AbdEWOCW (ORCPT ); Tue, 23 May 2017 10:02:22 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::,RULES_HIT:41:355:379:541:599:960:966:968: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:2553:2559:2562:2692:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3868:3870:3871:3872:3873:4321:4385:4605:5007:7576:10004:10400:10848:10967:11026:11232:11658:11914:12043:12048:12296:12438:12740:12760:12895:13069:13255:13311:13357:13439:14659:14721:21080:21212:21433:21451:21627:30054: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:3,LUA_SUMMARY:none X-HE-Tag: cook23_13c8726bf161f X-Filterd-Recvd-Size: 2094 Message-ID: <1495548133.2093.58.camel@perches.com> Subject: Re: [PATCH] tipc: Delete error messages for failed memory allocations in three functions From: Joe Perches To: SF Markus Elfring , tipc-discussion@lists.sourceforge.net, netdev@vger.kernel.org, "David S. Miller" , Jon Maloy , Ying Xue Cc: LKML , kernel-janitors@vger.kernel.org Date: Tue, 23 May 2017 07:02:13 -0700 In-Reply-To: <7ac9d513-6f9f-a096-e68f-81a722c2723c@users.sourceforge.net> References: <7ac9d513-6f9f-a096-e68f-81a722c2723c@users.sourceforge.net> 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 15:07 +0200, SF Markus Elfring wrote: > From: Markus Elfring > Date: Tue, 23 May 2017 14:45:25 +0200 > > Omit four extra messages for memory allocation failures in these functions. This is fine but you should look to optimize or figure out whether optimization is desirable for the effective realloc. > diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c [] > @@ -270,11 +268,9 @@ static struct publication *tipc_nameseq_insert_publ(struct net *net, > if (nseq->first_free == nseq->alloc) { > struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2); > > - if (!sseqs) { > - pr_warn("Cannot publish {%u,%u,%u}, no memory\n", > - type, lower, upper); > + if (!sseqs) > return NULL; > - } > + > memcpy(sseqs, nseq->sseqs, > nseq->alloc * sizeof(struct sub_seq)); tipc_subseq_alloc does a kcalloc (memset to 0), half of which is immediately overwritten. In other words, don't just blindly remove stuff, understand what it does and improve it.