From bda1e4e5a3d976046378cd495a63e1ee0847deec Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:33:54 -0600 Subject: PNP: add pnp_alloc_dev() Add pnp_alloc_dev() to allocate a struct pnp_dev and fill in the protocol, instance number, and initial PNP ID. Now it is always valid to use dev_printk() on any pnp_dev pointer. Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/pnpacpi/core.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'drivers/pnp/pnpacpi/core.c') diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c index 86aea1ebfee7..fd3fca6dddd3 100644 --- a/drivers/pnp/pnpacpi/core.c +++ b/drivers/pnp/pnpacpi/core.c @@ -152,7 +152,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device) { acpi_handle temp = NULL; acpi_status status; - struct pnp_id *dev_id; struct pnp_dev *dev; status = acpi_get_handle(device->handle, "_CRS", &temp); @@ -160,11 +159,10 @@ static int __init pnpacpi_add_device(struct acpi_device *device) is_exclusive_device(device)) return 0; - dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); - if (!dev) { - pnp_err("Out of memory"); + dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device)); + if (!dev) return -ENOMEM; - } + dev->data = device->handle; /* .enabled means the device can decode the resources */ dev->active = device->status.enabled; @@ -180,19 +178,11 @@ static int __init pnpacpi_add_device(struct acpi_device *device) if (ACPI_SUCCESS(status)) dev->capabilities |= PNP_DISABLE; - dev->protocol = &pnpacpi_protocol; - if (strlen(acpi_device_name(device))) strncpy(dev->name, acpi_device_name(device), sizeof(dev->name)); else strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name)); - dev->number = num; - - dev_id = pnp_add_id(dev, acpi_device_hid(device)); - if (!dev_id) - goto err; - if (dev->active) { /* parse allocated resource */ status = pnpacpi_parse_allocated_resource(device->handle, @@ -230,9 +220,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device) num++; return AE_OK; -err: - kfree(dev); - return -EINVAL; } static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, -- cgit v1.2.3