On Mon, Sep 05, 2005 at 12:48:45PM -0400, Jeff Garzik wrote:
> >>I understand removing the NULL pointers, but .name is actually a string
> >>"NULL".. Leaving it to be NULL is not a very good idea. This "NULL"
> >>algorithm was designed for cases where there is default algorithm for
> >>encryption and encryption needs to be disabled for a specific station.
> >>In other words, userspace programs will be asking for an algorithm
> >>called "NULL".
> >
> >
> >Yeah, I missed that.  Jeff, can you fix that before applying or should
> >I resend?
> 
> Please resend updated patch.


Index: linux-2.6/net/ieee80211/ieee80211_crypt.c
===================================================================
--- linux-2.6.orig/net/ieee80211/ieee80211_crypt.c      2005-09-05 
14:38:19.000000000 +0200
+++ linux-2.6/net/ieee80211/ieee80211_crypt.c   2005-09-06 14:14:01.000000000 
+0200
@@ -11,16 +11,14 @@
  *
  */
 
-#include <linux/config.h>
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/slab.h>
-#include <asm/string.h>
-#include <asm/errno.h>
-
+#include <linux/string.h>
+#include <linux/errno.h>
 #include <net/ieee80211.h>
 
+
 MODULE_AUTHOR("Jouni Malinen");
 MODULE_DESCRIPTION("HostAP crypto");
 MODULE_LICENSE("GPL");
@@ -30,28 +28,19 @@
        struct ieee80211_crypto_ops *ops;
 };
 
-
-struct ieee80211_crypto {
-       struct list_head algs;
-       spinlock_t lock;
-};
-
-static struct ieee80211_crypto *hcrypt;
+static LIST_HEAD(ieee80211_crypto_algs);
+static DEFINE_SPINLOCK(ieee80211_crypto_lock);
 
 void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee,
                                           int force)
 {
-       struct list_head *ptr, *n;
-       struct ieee80211_crypt_data *entry;
-
-       for (ptr = ieee->crypt_deinit_list.next, n = ptr->next;
-            ptr != &ieee->crypt_deinit_list; ptr = n, n = ptr->next) {
-               entry = list_entry(ptr, struct ieee80211_crypt_data, list);
+       struct ieee80211_crypt_data *entry, *next;
 
+       list_for_each_entry_safe(entry, next, &ieee->crypt_deinit_list, list) {
                if (atomic_read(&entry->refcnt) != 0 && !force)
                        continue;
 
-               list_del(ptr);
+               list_del(&entry->list);
 
                if (entry->ops) {
                        entry->ops->deinit(entry->priv);
@@ -108,9 +97,6 @@
        unsigned long flags;
        struct ieee80211_crypto_alg *alg;
 
-       if (hcrypt == NULL)
-               return -1;
-
        alg = kmalloc(sizeof(*alg), GFP_KERNEL);
        if (alg == NULL)
                return -ENOMEM;
@@ -118,9 +104,9 @@
        memset(alg, 0, sizeof(*alg));
        alg->ops = ops;
 
-       spin_lock_irqsave(&hcrypt->lock, flags);
-       list_add(&alg->list, &hcrypt->algs);
-       spin_unlock_irqrestore(&hcrypt->lock, flags);
+       spin_lock_irqsave(&ieee80211_crypto_lock, flags);
+       list_add(&alg->list, &ieee80211_crypto_algs);
+       spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
 
        printk(KERN_DEBUG "ieee80211_crypt: registered algorithm '%s'\n",
               ops->name);
@@ -130,121 +116,71 @@
 
 int ieee80211_unregister_crypto_ops(struct ieee80211_crypto_ops *ops)
 {
+       struct ieee80211_crypto_alg *alg;
        unsigned long flags;
-       struct list_head *ptr;
-       struct ieee80211_crypto_alg *del_alg = NULL;
 
-       if (hcrypt == NULL)
-               return -1;
-
-       spin_lock_irqsave(&hcrypt->lock, flags);
-       for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) {
-               struct ieee80211_crypto_alg *alg =
-                       (struct ieee80211_crypto_alg *) ptr;
-               if (alg->ops == ops) {
-                       list_del(&alg->list);
-                       del_alg = alg;
-                       break;
-               }
-       }
-       spin_unlock_irqrestore(&hcrypt->lock, flags);
-
-       if (del_alg) {
-               printk(KERN_DEBUG "ieee80211_crypt: unregistered algorithm "
-                      "'%s'\n", ops->name);
-               kfree(del_alg);
-       }
-
-       return del_alg ? 0 : -1;
+       spin_lock_irqsave(&ieee80211_crypto_lock, flags);
+       list_for_each_entry(alg, &ieee80211_crypto_algs, list) {
+               if (alg->ops == ops)
+                       goto found;
+       }
+       spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
+       return -EINVAL;
+
+ found:
+       printk(KERN_DEBUG "ieee80211_crypt: unregistered algorithm "
+              "'%s'\n", ops->name);
+       list_del(&alg->list);
+       spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
+       kfree(alg);
+       return 0;
 }
 
 
 struct ieee80211_crypto_ops * ieee80211_get_crypto_ops(const char *name)
 {
+       struct ieee80211_crypto_alg *alg;
        unsigned long flags;
-       struct list_head *ptr;
-       struct ieee80211_crypto_alg *found_alg = NULL;
 
-       if (hcrypt == NULL)
-               return NULL;
-
-       spin_lock_irqsave(&hcrypt->lock, flags);
-       for (ptr = hcrypt->algs.next; ptr != &hcrypt->algs; ptr = ptr->next) {
-               struct ieee80211_crypto_alg *alg =
-                       (struct ieee80211_crypto_alg *) ptr;
-               if (strcmp(alg->ops->name, name) == 0) {
-                       found_alg = alg;
-                       break;
-               }
+       spin_lock_irqsave(&ieee80211_crypto_lock, flags);
+       list_for_each_entry(alg, &ieee80211_crypto_algs, list) {
+               if (strcmp(alg->ops->name, name) == 0)
+                       goto found;
        }
-       spin_unlock_irqrestore(&hcrypt->lock, flags);
+       spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
+       return NULL;
 
-       if (found_alg)
-               return found_alg->ops;
-       else
-               return NULL;
+ found:
+       spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
+       return alg->ops;
 }
 
 
-static void * ieee80211_crypt_null_init(int keyidx) { return (void *) 1; }
-static void ieee80211_crypt_null_deinit(void *priv) {}
+static void *ieee80211_crypt_null_init(int keyidx)
+{
+       return (void *) 1;
+}
+
+static void ieee80211_crypt_null_deinit(void *priv)
+{
+}
 
 static struct ieee80211_crypto_ops ieee80211_crypt_null = {
        .name                   = "NULL",
        .init                   = ieee80211_crypt_null_init,
        .deinit                 = ieee80211_crypt_null_deinit,
-       .encrypt_mpdu           = NULL,
-       .decrypt_mpdu           = NULL,
-       .encrypt_msdu           = NULL,
-       .decrypt_msdu           = NULL,
-       .set_key                = NULL,
-       .get_key                = NULL,
-       .extra_prefix_len       = 0,
-       .extra_postfix_len      = 0,
        .owner                  = THIS_MODULE,
 };
 
-
 static int __init ieee80211_crypto_init(void)
 {
-       int ret = -ENOMEM;
-
-       hcrypt = kmalloc(sizeof(*hcrypt), GFP_KERNEL);
-       if (!hcrypt)
-               goto out;
-
-       memset(hcrypt, 0, sizeof(*hcrypt));
-       INIT_LIST_HEAD(&hcrypt->algs);
-       spin_lock_init(&hcrypt->lock);
-
-       ret = ieee80211_register_crypto_ops(&ieee80211_crypt_null);
-       if (ret < 0) {
-               kfree(hcrypt);
-               hcrypt = NULL;
-       }
-out:
-       return ret;
+       return ieee80211_register_crypto_ops(&ieee80211_crypt_null);
 }
 
-
 static void __exit ieee80211_crypto_deinit(void)
 {
-       struct list_head *ptr, *n;
-
-       if (hcrypt == NULL)
-               return;
-
-       for (ptr = hcrypt->algs.next, n = ptr->next; ptr != &hcrypt->algs;
-            ptr = n, n = ptr->next) {
-               struct ieee80211_crypto_alg *alg =
-                       (struct ieee80211_crypto_alg *) ptr;
-               list_del(ptr);
-               printk(KERN_DEBUG "ieee80211_crypt: unregistered algorithm "
-                      "'%s' (deinit)\n", alg->ops->name);
-               kfree(alg);
-       }
-
-       kfree(hcrypt);
+       ieee80211_unregister_crypto_ops(&ieee80211_crypt_null);
+       BUG_ON(!list_empty(&ieee80211_crypto_algs));
 }
 
 EXPORT_SYMBOL(ieee80211_crypt_deinit_entries);
-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to