PNP: change pnp_add_id() to allocate its own pnp_id structures
authorBjorn Helgaas <bjorn.helgaas@hp.com>
Mon, 28 Apr 2008 22:33:52 +0000 (16:33 -0600)
committerLen Brown <len.brown@intel.com>
Tue, 29 Apr 2008 07:22:16 +0000 (03:22 -0400)
This moves some of the pnp_id knowledge out of the backends and into
the PNP core.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
drivers/pnp/base.h
drivers/pnp/driver.c
drivers/pnp/isapnp/core.c
drivers/pnp/pnpacpi/core.c
drivers/pnp/pnpbios/core.c
drivers/pnp/pnpbios/rsparser.c

index abefcc3515217ab4d3d3ae9eaaf0a042542429b0..ba55b0623f7e69792a50019f2965493dda21c663 100644 (file)
@@ -1,6 +1,6 @@
 extern spinlock_t pnp_lock;
 void *pnp_alloc(long size);
-int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev);
+struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
 void pnp_free_option(struct pnp_option *option);
index e85cbf116db131c5eaa78c6ffbcde234bb33c750..d3f869ee1d92a5b8e90919b6df880efb7ec73ee8 100644 (file)
@@ -226,22 +226,36 @@ void pnp_unregister_driver(struct pnp_driver *drv)
 
 /**
  * pnp_add_id - adds an EISA id to the specified device
- * @id: pointer to a pnp_id structure
  * @dev: pointer to the desired device
+ * @id: pointer to an EISA id string
  */
-int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev)
+struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id)
 {
-       struct pnp_id *ptr;
+       struct pnp_id *dev_id, *ptr;
 
-       id->next = NULL;
+       dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+       if (!dev_id)
+               return NULL;
+
+       dev_id->id[0] = id[0];
+       dev_id->id[1] = id[1];
+       dev_id->id[2] = id[2];
+       dev_id->id[3] = tolower(id[3]);
+       dev_id->id[4] = tolower(id[4]);
+       dev_id->id[5] = tolower(id[5]);
+       dev_id->id[6] = tolower(id[6]);
+       dev_id->id[7] = '\0';
+
+       dev_id->next = NULL;
        ptr = dev->id;
        while (ptr && ptr->next)
                ptr = ptr->next;
        if (ptr)
-               ptr->next = id;
+               ptr->next = dev_id;
        else
-               dev->id = id;
-       return 0;
+               dev->id = dev_id;
+
+       return dev_id;
 }
 
 EXPORT_SYMBOL(pnp_register_driver);
index dd67752a5828d33d67e1848917584f6877a92ef9..10cade831433b15a159a38707c1c8b55e0d675b7 100644 (file)
@@ -44,6 +44,8 @@
 #include <linux/mutex.h>
 #include <asm/io.h>
 
+#include "../base.h"
+
 #if 0
 #define ISAPNP_REGION_OK
 #endif
@@ -401,20 +403,16 @@ static void __init isapnp_skip_bytes(int count)
 static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
                            unsigned short device)
 {
-       struct pnp_id *id;
+       char id[8];
 
-       if (!dev)
-               return;
-       id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
-       if (!id)
-               return;
-       sprintf(id->id, "%c%c%c%x%x%x%x",
+       sprintf(id, "%c%c%c%x%x%x%x",
                'A' + ((vendor >> 2) & 0x3f) - 1,
                'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
                'A' + ((vendor >> 8) & 0x1f) - 1,
                (device >> 4) & 0x0f,
                device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
-       pnp_add_id(id, dev);
+
+       pnp_add_id(dev, id);
 }
 
 /*
index 4807d76f8a049d224774c2b6fc4f0edab0817e85..86aea1ebfee73f7461e151d354a7a18a312211d0 100644 (file)
@@ -73,18 +73,6 @@ static int __init ispnpidacpi(char *id)
        return 1;
 }
 
-static void __init pnpidacpi_to_pnpid(char *id, char *str)
-{
-       str[0] = id[0];
-       str[1] = id[1];
-       str[2] = id[2];
-       str[3] = tolower(id[3]);
-       str[4] = tolower(id[4]);
-       str[5] = tolower(id[5]);
-       str[6] = tolower(id[6]);
-       str[7] = '\0';
-}
-
 static int pnpacpi_get_resources(struct pnp_dev *dev,
                                 struct pnp_resource_table *res)
 {
@@ -201,12 +189,9 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
 
        dev->number = num;
 
-       /* set the initial values for the PnP device */
-       dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+       dev_id = pnp_add_id(dev, acpi_device_hid(device));
        if (!dev_id)
                goto err;
-       pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
-       pnp_add_id(dev_id, dev);
 
        if (dev->active) {
                /* parse allocated resource */
@@ -227,7 +212,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
                }
        }
 
-       /* parse compatible ids */
        if (device->flags.compatible_ids) {
                struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
                int i;
@@ -235,12 +219,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
                for (i = 0; i < cid_list->count; i++) {
                        if (!ispnpidacpi(cid_list->id[i].value))
                                continue;
-                       dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
-                       if (!dev_id)
-                               continue;
-
-                       pnpidacpi_to_pnpid(cid_list->id[i].value, dev_id->id);
-                       pnp_add_id(dev_id, dev);
+                       pnp_add_id(dev, cid_list->id[i].value);
                }
        }
 
index 2a5353bceb24809ab046a994484de75c588e0432..2d592aea0aa773c8ffb0bee76465017d5009e785 100644 (file)
@@ -332,16 +332,14 @@ static int __init insert_device(struct pnp_bios_node *node)
        if (!dev)
                return -1;
 
-       dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
+       pnpid32_to_pnpid(node->eisa_id, id);
+       dev_id = pnp_add_id(dev, id);
        if (!dev_id) {
                kfree(dev);
                return -1;
        }
 
        dev->number = node->handle;
-       pnpid32_to_pnpid(node->eisa_id, id);
-       memcpy(dev_id->id, id, 7);
-       pnp_add_id(dev_id, dev);
        pnpbios_parse_data_stream(dev, node);
        dev->active = pnp_is_active(dev);
        dev->flags = node->flags;
index caade3531416f6a7392595f7b5fd432fa2a05660..dbc88412c12efcca8631028bf9bbf913fd3806da 100644 (file)
@@ -16,6 +16,7 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
 }
 #endif                         /* CONFIG_PCI */
 
+#include "../base.h"
 #include "pnpbios.h"
 
 /* standard resource tags */
@@ -548,13 +549,11 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
                case SMALL_TAG_COMPATDEVID:     /* compatible ID */
                        if (len != 4)
                                goto len_err;
-                       dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
-                       if (!dev_id)
-                               return NULL;
                        pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
                                         24, id);
-                       memcpy(&dev_id->id, id, 7);
-                       pnp_add_id(dev_id, dev);
+                       dev_id = pnp_add_id(dev, id);
+                       if (!dev_id)
+                               return NULL;
                        break;
 
                case SMALL_TAG_END: