wl1251: return -ENOMEM if kzalloc fails

the original code used goto out if kzalloc fails,but the out include kfree,
so return -ENOMEM if kzalloc fails.

Signed-off-by: Jing Wang <windsdaemon@gmail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
This commit is contained in:
Jing Wang 2013-10-24 16:14:11 +08:00 committed by John W. Linville
parent d94248ac2a
commit 60ce473e49
1 changed files with 68 additions and 141 deletions

View File

@ -18,10 +18,8 @@ int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
wl1251_debug(DEBUG_ACX, "acx frame rates"); wl1251_debug(DEBUG_ACX, "acx frame rates");
rates = kzalloc(sizeof(*rates), GFP_KERNEL); rates = kzalloc(sizeof(*rates), GFP_KERNEL);
if (!rates) { if (!rates)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
rates->tx_ctrl_frame_rate = ctrl_rate; rates->tx_ctrl_frame_rate = ctrl_rate;
rates->tx_ctrl_frame_mod = ctrl_mod; rates->tx_ctrl_frame_mod = ctrl_mod;
@ -49,10 +47,8 @@ int wl1251_acx_station_id(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx dot11_station_id"); wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
mac = kzalloc(sizeof(*mac), GFP_KERNEL); mac = kzalloc(sizeof(*mac), GFP_KERNEL);
if (!mac) { if (!mac)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
for (i = 0; i < ETH_ALEN; i++) for (i = 0; i < ETH_ALEN; i++)
mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i]; mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
@ -74,10 +70,8 @@ int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id); wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
default_key = kzalloc(sizeof(*default_key), GFP_KERNEL); default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
if (!default_key) { if (!default_key)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
default_key->id = key_id; default_key->id = key_id;
@ -104,10 +98,8 @@ int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
wl1251_debug(DEBUG_ACX, "acx wake up conditions"); wl1251_debug(DEBUG_ACX, "acx wake up conditions");
wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL); wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
if (!wake_up) { if (!wake_up)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
wake_up->wake_up_event = wake_up_event; wake_up->wake_up_event = wake_up_event;
wake_up->listen_interval = listen_interval; wake_up->listen_interval = listen_interval;
@ -132,16 +124,13 @@ int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
wl1251_debug(DEBUG_ACX, "acx sleep auth"); wl1251_debug(DEBUG_ACX, "acx sleep auth");
auth = kzalloc(sizeof(*auth), GFP_KERNEL); auth = kzalloc(sizeof(*auth), GFP_KERNEL);
if (!auth) { if (!auth)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
auth->sleep_auth = sleep_auth; auth->sleep_auth = sleep_auth;
ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth)); ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
out:
kfree(auth); kfree(auth);
return ret; return ret;
} }
@ -154,10 +143,8 @@ int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
wl1251_debug(DEBUG_ACX, "acx fw rev"); wl1251_debug(DEBUG_ACX, "acx fw rev");
rev = kzalloc(sizeof(*rev), GFP_KERNEL); rev = kzalloc(sizeof(*rev), GFP_KERNEL);
if (!rev) { if (!rev)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev)); ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
if (ret < 0) { if (ret < 0) {
@ -191,10 +178,8 @@ int wl1251_acx_tx_power(struct wl1251 *wl, int power)
return -EINVAL; return -EINVAL;
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx->current_tx_power = power * 10; acx->current_tx_power = power * 10;
@ -217,10 +202,8 @@ int wl1251_acx_feature_cfg(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx feature cfg"); wl1251_debug(DEBUG_ACX, "acx feature cfg");
feature = kzalloc(sizeof(*feature), GFP_KERNEL); feature = kzalloc(sizeof(*feature), GFP_KERNEL);
if (!feature) { if (!feature)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */ /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
feature->data_flow_options = 0; feature->data_flow_options = 0;
@ -261,10 +244,8 @@ int wl1251_acx_data_path_params(struct wl1251 *wl,
wl1251_debug(DEBUG_ACX, "acx data path params"); wl1251_debug(DEBUG_ACX, "acx data path params");
params = kzalloc(sizeof(*params), GFP_KERNEL); params = kzalloc(sizeof(*params), GFP_KERNEL);
if (!params) { if (!params)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE; params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE; params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
@ -309,10 +290,8 @@ int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
wl1251_debug(DEBUG_ACX, "acx rx msdu life time"); wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx->lifetime = life_time; acx->lifetime = life_time;
ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME, ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
@ -335,10 +314,8 @@ int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
wl1251_debug(DEBUG_ACX, "acx rx config"); wl1251_debug(DEBUG_ACX, "acx rx config");
rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL); rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
if (!rx_config) { if (!rx_config)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
rx_config->config_options = config; rx_config->config_options = config;
rx_config->filter_options = filter; rx_config->filter_options = filter;
@ -363,10 +340,8 @@ int wl1251_acx_pd_threshold(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx data pd threshold"); wl1251_debug(DEBUG_ACX, "acx data pd threshold");
pd = kzalloc(sizeof(*pd), GFP_KERNEL); pd = kzalloc(sizeof(*pd), GFP_KERNEL);
if (!pd) { if (!pd)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* FIXME: threshold value not set */ /* FIXME: threshold value not set */
@ -389,10 +364,8 @@ int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
wl1251_debug(DEBUG_ACX, "acx slot"); wl1251_debug(DEBUG_ACX, "acx slot");
slot = kzalloc(sizeof(*slot), GFP_KERNEL); slot = kzalloc(sizeof(*slot), GFP_KERNEL);
if (!slot) { if (!slot)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
slot->wone_index = STATION_WONE_INDEX; slot->wone_index = STATION_WONE_INDEX;
slot->slot_time = slot_time; slot->slot_time = slot_time;
@ -416,10 +389,8 @@ int wl1251_acx_group_address_tbl(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx group address tbl"); wl1251_debug(DEBUG_ACX, "acx group address tbl");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* MAC filtering */ /* MAC filtering */
acx->enabled = 0; acx->enabled = 0;
@ -444,10 +415,8 @@ int wl1251_acx_service_period_timeout(struct wl1251 *wl)
int ret; int ret;
rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL); rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
if (!rx_timeout) { if (!rx_timeout)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
wl1251_debug(DEBUG_ACX, "acx service period timeout"); wl1251_debug(DEBUG_ACX, "acx service period timeout");
@ -475,10 +444,8 @@ int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
wl1251_debug(DEBUG_ACX, "acx rts threshold"); wl1251_debug(DEBUG_ACX, "acx rts threshold");
rts = kzalloc(sizeof(*rts), GFP_KERNEL); rts = kzalloc(sizeof(*rts), GFP_KERNEL);
if (!rts) { if (!rts)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
rts->threshold = rts_threshold; rts->threshold = rts_threshold;
@ -501,10 +468,8 @@ int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
wl1251_debug(DEBUG_ACX, "acx beacon filter opt"); wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL); beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
if (!beacon_filter) { if (!beacon_filter)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
beacon_filter->enable = enable_filter; beacon_filter->enable = enable_filter;
beacon_filter->max_num_beacons = 0; beacon_filter->max_num_beacons = 0;
@ -530,10 +495,8 @@ int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx beacon filter table"); wl1251_debug(DEBUG_ACX, "acx beacon filter table");
ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL); ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
if (!ie_table) { if (!ie_table)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* configure default beacon pass-through rules */ /* configure default beacon pass-through rules */
ie_table->num_ie = 1; ie_table->num_ie = 1;
@ -560,10 +523,8 @@ int wl1251_acx_conn_monit_params(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx connection monitor parameters"); wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD; acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT; acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
@ -589,10 +550,8 @@ int wl1251_acx_sg_enable(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx sg enable"); wl1251_debug(DEBUG_ACX, "acx sg enable");
pta = kzalloc(sizeof(*pta), GFP_KERNEL); pta = kzalloc(sizeof(*pta), GFP_KERNEL);
if (!pta) { if (!pta)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
pta->enable = SG_ENABLE; pta->enable = SG_ENABLE;
@ -615,10 +574,8 @@ int wl1251_acx_sg_cfg(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx sg cfg"); wl1251_debug(DEBUG_ACX, "acx sg cfg");
param = kzalloc(sizeof(*param), GFP_KERNEL); param = kzalloc(sizeof(*param), GFP_KERNEL);
if (!param) { if (!param)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* BT-WLAN coext parameters */ /* BT-WLAN coext parameters */
param->min_rate = RATE_INDEX_24MBPS; param->min_rate = RATE_INDEX_24MBPS;
@ -669,10 +626,8 @@ int wl1251_acx_cca_threshold(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx cca threshold"); wl1251_debug(DEBUG_ACX, "acx cca threshold");
detection = kzalloc(sizeof(*detection), GFP_KERNEL); detection = kzalloc(sizeof(*detection), GFP_KERNEL);
if (!detection) { if (!detection)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D; detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
detection->tx_energy_detection = 0; detection->tx_energy_detection = 0;
@ -682,7 +637,6 @@ int wl1251_acx_cca_threshold(struct wl1251 *wl)
if (ret < 0) if (ret < 0)
wl1251_warning("failed to set cca threshold: %d", ret); wl1251_warning("failed to set cca threshold: %d", ret);
out:
kfree(detection); kfree(detection);
return ret; return ret;
} }
@ -695,10 +649,8 @@ int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx bcn dtim options"); wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
bb = kzalloc(sizeof(*bb), GFP_KERNEL); bb = kzalloc(sizeof(*bb), GFP_KERNEL);
if (!bb) { if (!bb)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE; bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE; bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
@ -724,10 +676,8 @@ int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
wl1251_debug(DEBUG_ACX, "acx aid"); wl1251_debug(DEBUG_ACX, "acx aid");
acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL); acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
if (!acx_aid) { if (!acx_aid)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx_aid->aid = aid; acx_aid->aid = aid;
@ -750,10 +700,8 @@ int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
wl1251_debug(DEBUG_ACX, "acx event mbox mask"); wl1251_debug(DEBUG_ACX, "acx event mbox mask");
mask = kzalloc(sizeof(*mask), GFP_KERNEL); mask = kzalloc(sizeof(*mask), GFP_KERNEL);
if (!mask) { if (!mask)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* high event mask is unused */ /* high event mask is unused */
mask->high_event_mask = 0xffffffff; mask->high_event_mask = 0xffffffff;
@ -805,10 +753,8 @@ int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
wl1251_debug(DEBUG_ACX, "acx_set_preamble"); wl1251_debug(DEBUG_ACX, "acx_set_preamble");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx->preamble = preamble; acx->preamble = preamble;
@ -832,10 +778,8 @@ int wl1251_acx_cts_protect(struct wl1251 *wl,
wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect"); wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx->ctsprotect = ctsprotect; acx->ctsprotect = ctsprotect;
@ -856,10 +800,8 @@ int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
int ret; int ret;
tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL); tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
if (!tsf_info) { if (!tsf_info)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO, ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
tsf_info, sizeof(*tsf_info)); tsf_info, sizeof(*tsf_info));
@ -900,11 +842,8 @@ int wl1251_acx_rate_policies(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx rate policies"); wl1251_debug(DEBUG_ACX, "acx rate policies");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx)
if (!acx) { return -ENOMEM;
ret = -ENOMEM;
goto out;
}
/* configure one default (one-size-fits-all) rate class */ /* configure one default (one-size-fits-all) rate class */
acx->rate_class_cnt = 1; acx->rate_class_cnt = 1;
@ -932,10 +871,8 @@ int wl1251_acx_mem_cfg(struct wl1251 *wl)
wl1251_debug(DEBUG_ACX, "acx mem cfg"); wl1251_debug(DEBUG_ACX, "acx mem cfg");
mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL); mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
if (!mem_conf) { if (!mem_conf)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* memory config */ /* memory config */
mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS); mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
@ -979,10 +916,8 @@ int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
wl1251_debug(DEBUG_ACX, "acx tbtt and dtim"); wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx->tbtt = tbtt; acx->tbtt = tbtt;
acx->dtim = dtim; acx->dtim = dtim;
@ -1008,10 +943,8 @@ int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
wl1251_debug(DEBUG_ACX, "acx bet enable"); wl1251_debug(DEBUG_ACX, "acx bet enable");
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx) { if (!acx)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
acx->enable = mode; acx->enable = mode;
acx->max_consecutive = max_consecutive; acx->max_consecutive = max_consecutive;
@ -1037,11 +970,8 @@ int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
"aifs %d txop %d", ac, cw_min, cw_max, aifs, txop); "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx)
if (!acx) { return -ENOMEM;
ret = -ENOMEM;
goto out;
}
acx->ac = ac; acx->ac = ac;
acx->cw_min = cw_min; acx->cw_min = cw_min;
@ -1073,11 +1003,8 @@ int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
ps_scheme, ack_policy); ps_scheme, ack_policy);
acx = kzalloc(sizeof(*acx), GFP_KERNEL); acx = kzalloc(sizeof(*acx), GFP_KERNEL);
if (!acx)
if (!acx) { return -ENOMEM;
ret = -ENOMEM;
goto out;
}
acx->queue = queue; acx->queue = queue;
acx->type = type; acx->type = type;