From patchwork Sat Jun 28 20:11:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Perches X-Patchwork-Id: 4081 X-Patchwork-Delegate: mareklindner@neomailbox.ch Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=216.40.44.82; helo=smtprelay.hostedemail.com; envelope-from=joe@perches.com; receiver=b.a.t.m.a.n@lists.open-mesh.org Received: from smtprelay.hostedemail.com (smtprelay0082.hostedemail.com [216.40.44.82]) by open-mesh.org (Postfix) with ESMTP id AFD7E600B8E for ; Sat, 28 Jun 2014 22:11:40 +0200 (CEST) Received: from filter.hostedemail.com (ff-bigip1 [10.5.19.254]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id 7C3316A4C7; Sat, 28 Jun 2014 20:11:39 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 48, 2.914, 0, , d41d8cd98f00b204, joe@perches.com, :::::::::::::::::, RULES_HIT:41:355:379:418:541:599:966:973:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2110:2196:2198:2199:2200:2393:2559:2562:2689:2828:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:4321:4385:5007:6119:7652:7903:8603:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12438:12517:12519:12555:12663:12740:13071:13138:13141:13230:13231:21060:21080, 0, RBL:none, CacheIP:none, Bayesian:0.5, 0.5, 0.5, Netcheck:none, DomainCache:0, MSF X-HE-Tag: slope03_2b5aedbfe6b63 X-Filterd-Recvd-Size: 3845 Received: from [192.168.1.162] (pool-71-103-235-196.lsanca.fios.verizon.net [71.103.235.196]) (Authenticated sender: joe@perches.com) by omf06.hostedemail.com (Postfix) with ESMTPA; Sat, 28 Jun 2014 20:11:37 +0000 (UTC) Message-ID: <1403986296.9064.45.camel@joe-AO725> From: Joe Perches To: Antonio Quartulli Date: Sat, 28 Jun 2014 13:11:36 -0700 In-Reply-To: <53AF1C42.6000108@meshcoding.com> References: <20140628183628.GA9946@himangi-Dell> <1403982781.9064.33.camel@joe-AO725> <53AF1C42.6000108@meshcoding.com> X-Mailer: Evolution 3.10.4-0ubuntu1 Mime-Version: 1.0 Cc: Marek Lindner , netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org, julia.lawall@lip6.fr, Himangi Saraogi , "David S. Miller" Subject: Re: [B.A.T.M.A.N.] [PATCH] batman-adv: Use kasprintf X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Jun 2014 20:11:41 -0000 On Sat, 2014-06-28 at 21:49 +0200, Antonio Quartulli wrote: > Hi all, > > On 28/06/14 21:13, Joe Perches wrote: > > diff --git 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]; > > > Joe, why are you shortening this? kobject_uevent_env() expect a > NULL-terminating array (that is the forth cell). Hi Antonio, sorry, I didn't know about the last NULL being required. It looked to me more like an oversight in the code instead of a required NULL. > And how is this change reducing the code space? Removing unnecessary initializations reduces object code size. > For what concerns the labels, we use this pattern mostly all over the > code: one single label/exit-point with the related NULL checks. Do you > think that we can improve something by changing this? (I am not talking > about the fastpath here). Not calling known unnecessary kfree calls helps a little. Certainly, it'd be more valuable in any fast path area. Other than that, it was an unsigned suggestion not a formal patch submission. Ignore it or improve it as you see fit. cheers, Joe Maybe: --- net/batman-adv/sysfs.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/net/batman-adv/sysfs.c b/net/batman-adv/sysfs.c index f40cb04..90c245e 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[4]; bat_kobj = &bat_priv->soft_iface->dev.kobj; @@ -910,22 +910,26 @@ 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; } + uevent_env[3] = NULL; + ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env); -out: - kfree(uevent_env[0]); - kfree(uevent_env[1]); - kfree(uevent_env[2]); + 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",