Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / input / gameport / ns558.c
index 7c5c631..3e2d28f 100644 (file)
@@ -142,7 +142,7 @@ static int ns558_isa_probe(int io)
                        return -EBUSY;
        }
 
-       ns558 = kcalloc(1, sizeof(struct ns558), GFP_KERNEL);
+       ns558 = kzalloc(sizeof(struct ns558), GFP_KERNEL);
        port = gameport_allocate_port();
        if (!ns558 || !port) {
                printk(KERN_ERR "ns558: Memory allocation failed.\n");
@@ -215,7 +215,7 @@ static int ns558_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *did)
        if (!request_region(ioport, iolen, "ns558-pnp"))
                return -EBUSY;
 
-       ns558 = kcalloc(1, sizeof(struct ns558), GFP_KERNEL);
+       ns558 = kzalloc(sizeof(struct ns558), GFP_KERNEL);
        port = gameport_allocate_port();
        if (!ns558 || !port) {
                printk(KERN_ERR "ns558: Memory allocation failed\n");
@@ -252,39 +252,38 @@ static struct pnp_driver ns558_pnp_driver;
 
 #endif
 
-static int pnp_registered = 0;
-
 static int __init ns558_init(void)
 {
        int i = 0;
+       int error;
+
+       error = pnp_register_driver(&ns558_pnp_driver);
+       if (error && error != -ENODEV)  /* should be ENOSYS really */
+               return error;
 
 /*
- * Probe ISA ports first so that PnP gets to choose free port addresses
- * not occupied by the ISA ports.
+ * Probe ISA ports after PnP, so that PnP ports that are already
+ * enabled get detected as PnP. This may be suboptimal in multi-device
+ * configurations, but saves hassle with simple setups.
  */
 
        while (ns558_isa_portlist[i])
                ns558_isa_probe(ns558_isa_portlist[i++]);
 
-       if (pnp_register_driver(&ns558_pnp_driver) >= 0)
-               pnp_registered = 1;
-
-
-       return (list_empty(&ns558_list) && !pnp_registered) ? -ENODEV : 0;
+       return list_empty(&ns558_list) && error ? -ENODEV : 0;
 }
 
 static void __exit ns558_exit(void)
 {
-       struct ns558 *ns558;
+       struct ns558 *ns558, *safe;
 
-       list_for_each_entry(ns558, &ns558_list, node) {
+       list_for_each_entry_safe(ns558, safe, &ns558_list, node) {
                gameport_unregister_port(ns558->gameport);
                release_region(ns558->io & ~(ns558->size - 1), ns558->size);
                kfree(ns558);
        }
 
-       if (pnp_registered)
-               pnp_unregister_driver(&ns558_pnp_driver);
+       pnp_unregister_driver(&ns558_pnp_driver);
 }
 
 module_init(ns558_init);