aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2009-08-21 10:35:20 -0400
committerJohn W. Linville <linville@tuxdriver.com>2009-08-28 14:40:35 -0400
commitca4fe30097d700c595c13362200083650759e104 (patch)
tree13f96510106953e337769a00c24fd3ccf1a9949a /drivers
parent1e3d31c589a6bcb05cd7fccccf9657c27b0e3dd1 (diff)
libertas: clean up and clarify get_common_rates
Clarify what the heck the function is doing with better variable names and less indirection and better comments. Also ensure callers use the proper minimum size, even though all rates arrays should be size MAX_RATES anyway. Reverts part of Andrey's dynamic alloc patch since we don't really need it. Also leaves the passed-in rates array alone on errors. Signed-off-by: Dan Williams <dcbw@redhat.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/libertas/assoc.c58
1 files changed, 27 insertions, 31 deletions
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
index a9440a96b2e7..dd8732611ba9 100644
--- a/drivers/net/wireless/libertas/assoc.c
+++ b/drivers/net/wireless/libertas/assoc.c
@@ -34,7 +34,8 @@ static const u8 bssid_off[ETH_ALEN] __attribute__ ((aligned (2))) =
34 * 34 *
35 * @param priv A pointer to struct lbs_private structure 35 * @param priv A pointer to struct lbs_private structure
36 * @param rates the buffer which keeps input and output 36 * @param rates the buffer which keeps input and output
37 * @param rates_size the size of rate1 buffer; new size of buffer on return 37 * @param rates_size the size of rates buffer; new size of buffer on return,
38 * which will be less than or equal to original rates_size
38 * 39 *
39 * @return 0 on success, or -1 on error 40 * @return 0 on success, or -1 on error
40 */ 41 */
@@ -42,46 +43,41 @@ static int get_common_rates(struct lbs_private *priv,
42 u8 *rates, 43 u8 *rates,
43 u16 *rates_size) 44 u16 *rates_size)
44{ 45{
45 u8 *card_rates = lbs_bg_rates;
46 size_t num_card_rates = sizeof(lbs_bg_rates);
47 int i, j; 46 int i, j;
48 u8 *tmp; 47 u8 intersection[MAX_RATES];
49 size_t tmp_size = 0; 48 u16 intersection_size;
49 u16 num_rates = 0;
50 50
51 tmp = kzalloc(MAX_RATES * ARRAY_SIZE(lbs_bg_rates), GFP_KERNEL); 51 intersection_size = min_t(u16, *rates_size, ARRAY_SIZE(intersection));
52 if (!tmp)
53 return -1;
54 52
55 /* For each rate in card_rates that exists in rate1, copy to tmp */ 53 /* Allow each rate from 'rates' that is supported by the hardware */
56 for (i = 0; card_rates[i] && (i < num_card_rates); i++) { 54 for (i = 0; i < ARRAY_SIZE(lbs_bg_rates) && lbs_bg_rates[i]; i++) {
57 for (j = 0; rates[j] && (j < *rates_size); j++) { 55 for (j = 0; j < intersection_size && rates[j]; j++) {
58 if (rates[j] == card_rates[i]) 56 if (rates[j] == lbs_bg_rates[i])
59 tmp[tmp_size++] = card_rates[i]; 57 intersection[num_rates++] = rates[j];
60 } 58 }
61 } 59 }
62 60
63 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size); 61 lbs_deb_hex(LBS_DEB_JOIN, "AP rates ", rates, *rates_size);
64 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", card_rates, num_card_rates); 62 lbs_deb_hex(LBS_DEB_JOIN, "card rates ", lbs_bg_rates,
65 lbs_deb_hex(LBS_DEB_JOIN, "common rates", tmp, tmp_size); 63 ARRAY_SIZE(lbs_bg_rates));
64 lbs_deb_hex(LBS_DEB_JOIN, "common rates", intersection, num_rates);
66 lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate); 65 lbs_deb_join("TX data rate 0x%02x\n", priv->cur_rate);
67 66
68 memset(rates, 0, *rates_size);
69 *rates_size = min_t(u16, tmp_size, *rates_size);
70 memcpy(rates, tmp, *rates_size);
71
72 if (!priv->enablehwauto) { 67 if (!priv->enablehwauto) {
73 for (i = 0; i < tmp_size; i++) { 68 for (i = 0; i < num_rates; i++) {
74 if (tmp[i] == priv->cur_rate) 69 if (intersection[i] == priv->cur_rate)
75 break; 70 goto done;
76 }
77 if (i == tmp_size) {
78 lbs_pr_alert("Previously set fixed data rate %#x isn't "
79 "compatible with the network.\n",
80 priv->cur_rate);
81 return -1;
82 } 71 }
72 lbs_pr_alert("Previously set fixed data rate %#x isn't "
73 "compatible with the network.\n", priv->cur_rate);
74 return -1;
83 } 75 }
84 kfree(tmp); 76
77done:
78 memset(rates, 0, *rates_size);
79 *rates_size = num_rates;
80 memcpy(rates, intersection, num_rates);
85 return 0; 81 return 0;
86} 82}
87 83
@@ -324,7 +320,7 @@ static int lbs_associate(struct lbs_private *priv,
324 320
325 rates = (struct mrvl_ie_rates_param_set *) pos; 321 rates = (struct mrvl_ie_rates_param_set *) pos;
326 rates->header.type = cpu_to_le16(TLV_TYPE_RATES); 322 rates->header.type = cpu_to_le16(TLV_TYPE_RATES);
327 tmplen = MAX_RATES; 323 tmplen = min_t(u16, ARRAY_SIZE(bss->rates), MAX_RATES);
328 memcpy(&rates->rates, &bss->rates, tmplen); 324 memcpy(&rates->rates, &bss->rates, tmplen);
329 if (get_common_rates(priv, rates->rates, &tmplen)) { 325 if (get_common_rates(priv, rates->rates, &tmplen)) {
330 ret = -1; 326 ret = -1;
@@ -599,7 +595,7 @@ static int lbs_adhoc_join(struct lbs_private *priv,
599 595
600 /* Copy Data rates from the rates recorded in scan response */ 596 /* Copy Data rates from the rates recorded in scan response */
601 memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates)); 597 memset(cmd.bss.rates, 0, sizeof(cmd.bss.rates));
602 ratesize = min_t(u16, sizeof(cmd.bss.rates), MAX_RATES); 598 ratesize = min_t(u16, ARRAY_SIZE(cmd.bss.rates), ARRAY_SIZE (bss->rates));
603 memcpy(cmd.bss.rates, bss->rates, ratesize); 599 memcpy(cmd.bss.rates, bss->rates, ratesize);
604 if (get_common_rates(priv, cmd.bss.rates, &ratesize)) { 600 if (get_common_rates(priv, cmd.bss.rates, &ratesize)) {
605 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n"); 601 lbs_deb_join("ADHOC_JOIN: get_common_rates returned error.\n");