logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

revision 2954 committed: msg#00139

Subject: revision 2954 committed
Project     : madwifi
Revision    : 2954
Author      : proski (Pavel Roskin)
Date        : 2007-11-25 06:42:23 +0100 (Sun, 25 Nov 2007)

Log Message :
Fix the last sparse warning - find key index in a loop

ath_key_alloc() was using pointer subtraction to determine the group key
index.  This is not optimal, as it's done by dividing a pointer-sized
integer by a number that is generally not a power of two.

Since there are only 4 (IEEE80211_WEP_NKID) keys to try, it's easier to
try them all in a loop.  It also makes the code more reliable, as it now
detects the cases when the key pointer is within the valid range, but
doesn't point to the beginning of an array element.

Affected Files:
* madwifi/trunk/ath/if_ath.c                          updated             


Modified: madwifi/trunk/ath/if_ath.c
===================================================================
--- madwifi/trunk/ath/if_ath.c  2007-11-25 04:13:49 UTC (rev 2953)
+++ madwifi/trunk/ath/if_ath.c  2007-11-25 05:42:23 UTC (rev 2954)
@@ -3607,16 +3607,22 @@
         * multi-station operation.
         */
        if ((k->wk_flags & IEEE80211_KEY_GROUP) && !sc->sc_mcastkey) {
-               ieee80211_keyix_t keyix;
+               int i;
+               ieee80211_keyix_t keyix = IEEE80211_KEYIX_NONE;
 
-               if (!(&vap->iv_nw_keys[0] <= k &&
-                   k < &vap->iv_nw_keys[IEEE80211_WEP_NKID])) {
+               for (i = 0; i < IEEE80211_WEP_NKID; i++) {
+                       if (k == &vap->iv_nw_keys[i]) {
+                               keyix = i;
+                               break;
+                       }
+               }
+               if (keyix == IEEE80211_KEYIX_NONE) {
                        /* should not happen */
                        DPRINTF(sc, ATH_DEBUG_KEYCACHE,
                                "%s: bogus group key\n", __func__);
                        return IEEE80211_KEYIX_NONE;
                }
-               keyix = k - vap->iv_nw_keys;
+
                /* XXX: We pre-allocate the global keys so have no way 
                 * to check if they've already been allocated. */
                return keyix;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/


<Prev in Thread] Current Thread [Next in Thread>