summaryrefslogtreecommitdiff
path: root/drivers/pnp/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pnp/core.c')
-rw-r--r--drivers/pnp/core.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index 7d366ca672d3..cf37701a4f9e 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -109,15 +109,42 @@ static void pnp_release_device(struct device *dmdev)
kfree(dev);
}
-int __pnp_add_device(struct pnp_dev *dev)
+struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
{
- int ret;
+ struct pnp_dev *dev;
+ struct pnp_id *dev_id;
- pnp_fixup_device(dev);
+ dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
+ if (!dev)
+ return NULL;
+
+ dev->protocol = protocol;
+ dev->number = id;
+ dev->dma_mask = DMA_24BIT_MASK;
+
+ dev->dev.parent = &dev->protocol->dev;
dev->dev.bus = &pnp_bus_type;
dev->dev.dma_mask = &dev->dma_mask;
- dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
+ dev->dev.coherent_dma_mask = dev->dma_mask;
dev->dev.release = &pnp_release_device;
+
+ sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
+ dev->number);
+
+ dev_id = pnp_add_id(dev, pnpid);
+ if (!dev_id) {
+ kfree(dev);
+ return NULL;
+ }
+
+ return dev;
+}
+
+int __pnp_add_device(struct pnp_dev *dev)
+{
+ int ret;
+
+ pnp_fixup_device(dev);
dev->status = PNP_READY;
spin_lock(&pnp_lock);
list_add_tail(&dev->global_list, &pnp_global);
@@ -145,9 +172,6 @@ int pnp_add_device(struct pnp_dev *dev)
if (dev->card)
return -EINVAL;
- dev->dev.parent = &dev->protocol->dev;
- sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
- dev->number);
ret = __pnp_add_device(dev);
if (ret)
return ret;