caif: add error handling for allocation

The allocation of "phyinfo" wasn't checked, and also the allocation
wasn't freed on error paths.  Sjur Brændeland pointed out as well
that "phy_driver" should be freed on the error path too.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Sjur Brændeland <sjur.brandeland@stericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Dan Carpenter 2011-09-20 21:21:59 +00:00 committed by David S. Miller
parent 64af1bac9b
commit 5bb20ed863
1 changed files with 14 additions and 9 deletions

View File

@ -467,7 +467,7 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type,
{ {
struct cflayer *frml; struct cflayer *frml;
struct cflayer *phy_driver = NULL; struct cflayer *phy_driver = NULL;
struct cfcnfg_phyinfo *phyinfo; struct cfcnfg_phyinfo *phyinfo = NULL;
int i; int i;
u8 phyid; u8 phyid;
@ -482,23 +482,25 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type,
goto got_phyid; goto got_phyid;
} }
pr_warn("Too many CAIF Link Layers (max 6)\n"); pr_warn("Too many CAIF Link Layers (max 6)\n");
goto out; goto out_err;
got_phyid: got_phyid:
phyinfo = kzalloc(sizeof(struct cfcnfg_phyinfo), GFP_ATOMIC); phyinfo = kzalloc(sizeof(struct cfcnfg_phyinfo), GFP_ATOMIC);
if (!phyinfo)
goto out_err;
switch (phy_type) { switch (phy_type) {
case CFPHYTYPE_FRAG: case CFPHYTYPE_FRAG:
phy_driver = phy_driver =
cfserl_create(CFPHYTYPE_FRAG, phyid, stx); cfserl_create(CFPHYTYPE_FRAG, phyid, stx);
if (!phy_driver) if (!phy_driver)
goto out; goto out_err;
break; break;
case CFPHYTYPE_CAIF: case CFPHYTYPE_CAIF:
phy_driver = NULL; phy_driver = NULL;
break; break;
default: default:
goto out; goto out_err;
} }
phy_layer->id = phyid; phy_layer->id = phyid;
phyinfo->pref = pref; phyinfo->pref = pref;
@ -512,10 +514,8 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type,
frml = cffrml_create(phyid, fcs); frml = cffrml_create(phyid, fcs);
if (!frml) { if (!frml)
kfree(phyinfo); goto out_err;
goto out;
}
phyinfo->frm_layer = frml; phyinfo->frm_layer = frml;
layer_set_up(frml, cnfg->mux); layer_set_up(frml, cnfg->mux);
@ -531,7 +531,12 @@ cfcnfg_add_phy_layer(struct cfcnfg *cnfg, enum cfcnfg_phy_type phy_type,
} }
list_add_rcu(&phyinfo->node, &cnfg->phys); list_add_rcu(&phyinfo->node, &cnfg->phys);
out: mutex_unlock(&cnfg->lock);
return;
out_err:
kfree(phy_driver);
kfree(phyinfo);
mutex_unlock(&cnfg->lock); mutex_unlock(&cnfg->lock);
} }
EXPORT_SYMBOL(cfcnfg_add_phy_layer); EXPORT_SYMBOL(cfcnfg_add_phy_layer);