From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757870AbaF1TNK (ORCPT ); Sat, 28 Jun 2014 15:13:10 -0400 Received: from smtprelay0253.hostedemail.com ([216.40.44.253]:53341 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754030AbaF1TNI (ORCPT ); Sat, 28 Jun 2014 15:13:08 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 48,2.914,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::,RULES_HIT:41:355:379:418:541:599:966:968:973:981:988:989:1260:1261: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:2828:3138:3139:3140:3141:3142:3352:3622:3865:3866:3867:3868:3871:4250:4321:4385:5007:7652:8603:9592:10004:10400:10848:11026:11473:11658:11914:12043:12296:12438:12517:12519:12555:12663:12740:13069:13138:13231:13311:13357: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 X-HE-Tag: card41_71e24e681771e X-Filterd-Recvd-Size: 2660 Message-ID: <1403982781.9064.33.camel@joe-AO725> Subject: Re: [PATCH] batman-adv: Use kasprintf From: Joe Perches To: Himangi Saraogi Cc: Marek Lindner , Simon Wunderlich , Antonio Quartulli , "David S. Miller" , b.a.t.m.a.n@lists.open-mesh.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, julia.lawall@lip6.fr Date: Sat, 28 Jun 2014 12:13:01 -0700 In-Reply-To: <20140628183628.GA9946@himangi-Dell> References: <20140628183628.GA9946@himangi-Dell> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.10.4-0ubuntu1 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 Sun, 2014-06-29 at 00:06 +0530, Himangi Saraogi wrote: > kasprintf combines kmalloc and sprintf, and takes care of the size > calculation itself. Nice. A small conversion to remove unnecessary initializations, avoid calling kfree with known NULL pointers, and save a few bytes of code space woud be: --- net/batman-adv/sysfs.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c index f40cb04..d6fba94 100644 --- a/net/batman-adv/sysfs.c +++ b/net/batman-adv/sysfs.c @@ -896,7 +896,7 @@ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, { int ret = -ENOMEM; struct kobject *bat_kobj; - char *uevent_env[4] = { NULL, NULL, NULL, NULL }; + char *uevent_env[3]; bat_kobj = &bat_priv->soft_iface->dev.kobj; @@ -910,22 +910,23 @@ int batadv_throw_uevent(struct batadv_priv *bat_priv, enum batadv_uev_type type, "%s%s", BATADV_UEV_ACTION_VAR, batadv_uev_action_str[action]); if (!uevent_env[1]) - goto out; + goto out0; /* If the event is DEL, ignore the data field */ if (action != BATADV_UEV_DEL) { uevent_env[2] = kasprintf(GFP_ATOMIC, "%s%s", BATADV_UEV_DATA_VAR, data); if (!uevent_env[2]) - goto out; + goto out1; } ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env); -out: - kfree(uevent_env[0]); - kfree(uevent_env[1]); kfree(uevent_env[2]); - +out1: + kfree(uevent_env[1]); +out0: + kfree(uevent_env[0]); +out: if (ret) batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "Impossible to send uevent for (%s,%s,%s) event (err: %d)\n",