From patchwork Fri Sep 2 08:07:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 113058 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 96677B73ED for ; Fri, 2 Sep 2011 18:09:58 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758098Ab1IBIJu (ORCPT ); Fri, 2 Sep 2011 04:09:50 -0400 Received: from mail-pz0-f42.google.com ([209.85.210.42]:60974 "EHLO mail-pz0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758143Ab1IBIJq (ORCPT ); Fri, 2 Sep 2011 04:09:46 -0400 Received: by pzk37 with SMTP id 37so4230534pzk.1 for ; Fri, 02 Sep 2011 01:09:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=A0RX5DEIW7MfaNk0ytNXd1taLtAOXAq1naHrZiCeKkY=; b=CHANxDPFOUqPSlR1GozNChRPXJXOx8AsqAlTitEaTfpzjf662sZdNNiDHax8WSH2jB GISCpg1vhMpLNt8iOf2k2q0Z5l0qQfpOpe2Qhm5QL4t8jwm6YUMOv4K95iZN1WEYilCU GtsGn1W6fGlOi2yvp1GzcUIxdyuobbSM2ktLE= Received: by 10.68.14.68 with SMTP id n4mr1502743pbc.254.1314950986553; Fri, 02 Sep 2011 01:09:46 -0700 (PDT) Received: from shale.localdomain ([41.139.221.94]) by mx.google.com with ESMTPS id t6sm8563289pbg.4.2011.09.02.01.09.34 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 02 Sep 2011 01:09:45 -0700 (PDT) Date: Fri, 2 Sep 2011 11:07:16 +0300 From: Dan Carpenter To: Sjur Braendeland Cc: "David S. Miller" , "open list:CAIF NETWORK LAYER" , kernel-janitors@vger.kernel.org Subject: [patch -next] caif: add error handling for allocation Message-ID: <20110902080716.GF2430@shale.localdomain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The allocation could fail so we should check, or other errors could happen and we should free the "phyinfo" variable. Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/caif/cfcnfg.c b/net/caif/cfcnfg.c index f07ab8c..b213b53 100644 --- a/net/caif/cfcnfg.c +++ b/net/caif/cfcnfg.c @@ -467,7 +467,7 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type, { struct cflayer *frml; struct cflayer *phy_driver = NULL; - struct cfcnfg_phyinfo *phyinfo; + struct cfcnfg_phyinfo *phyinfo = NULL; int i; u8 phyid; @@ -482,23 +482,25 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type, goto got_phyid; } pr_warn("Too many CAIF Link Layers (max 6)\n"); - goto out; + goto out_err; got_phyid: phyinfo = kzalloc(sizeof(struct cfcnfg_phyinfo), GFP_ATOMIC); + if (!phyinfo) + goto out_err; switch (phy_type) { case CFPHYTYPE_FRAG: phy_driver = cfserl_create(CFPHYTYPE_FRAG, phyid, stx); if (!phy_driver) - goto out; + goto out_err; break; case CFPHYTYPE_CAIF: phy_driver = NULL; break; default: - goto out; + goto out_err; } phy_layer->id = phyid; phyinfo->pref = pref; @@ -512,10 +514,8 @@ got_phyid: frml = cffrml_create(phyid, fcs); - if (!frml) { - kfree(phyinfo); - goto out; - } + if (!frml) + goto out_err; phyinfo->frm_layer = frml; layer_set_up(frml, cnfg->mux); @@ -531,7 +531,11 @@ got_phyid: } list_add_rcu(&phyinfo->node, &cnfg->phys); -out: + mutex_unlock(&cnfg->lock); + return; + +out_err: + kfree(phyinfo); mutex_unlock(&cnfg->lock); } EXPORT_SYMBOL(cfcnfg_add_phy_layer);