Commit 087da3b4 authored by Len Brown's avatar Len Brown

ACPI: simplify buffer management for acpi_pci_bind() etc.

use ACPI_ALLOCATE_BUFFER to remove the allocations
within acpi_pci_bind(), acpi_pci_unbind() and acpi_pci_bind_root().
While there, delete some unnecessary param inits from those routines.

Delete concept of ACPI_PATHNAME_MAX, since this was the last use.
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 39488b04
...@@ -111,12 +111,11 @@ EXPORT_SYMBOL(acpi_get_pci_id); ...@@ -111,12 +111,11 @@ EXPORT_SYMBOL(acpi_get_pci_id);
int acpi_pci_bind(struct acpi_device *device) int acpi_pci_bind(struct acpi_device *device)
{ {
int result = 0; int result = 0;
acpi_status status = AE_OK; acpi_status status;
struct acpi_pci_data *data = NULL; struct acpi_pci_data *data;
struct acpi_pci_data *pdata = NULL; struct acpi_pci_data *pdata;
char *pathname = NULL; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_buffer buffer = { 0, NULL }; acpi_handle handle;
acpi_handle handle = NULL;
struct pci_dev *dev; struct pci_dev *dev;
struct pci_bus *bus; struct pci_bus *bus;
...@@ -124,21 +123,18 @@ int acpi_pci_bind(struct acpi_device *device) ...@@ -124,21 +123,18 @@ int acpi_pci_bind(struct acpi_device *device)
if (!device || !device->parent) if (!device || !device->parent)
return -EINVAL; return -EINVAL;
pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
if (!pathname)
return -ENOMEM;
buffer.length = ACPI_PATHNAME_MAX;
buffer.pointer = pathname;
data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
if (!data) { if (!data)
kfree(pathname);
return -ENOMEM; return -ENOMEM;
status = acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
if (ACPI_FAILURE(status)) {
kfree(data);
return -ENODEV;
} }
acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n", ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI device [%s]...\n",
pathname)); (char *)buffer.pointer));
/* /*
* Segment & Bus * Segment & Bus
...@@ -262,7 +258,7 @@ int acpi_pci_bind(struct acpi_device *device) ...@@ -262,7 +258,7 @@ int acpi_pci_bind(struct acpi_device *device)
} }
end: end:
kfree(pathname); kfree(buffer.pointer);
if (result) if (result)
kfree(data); kfree(data);
...@@ -272,25 +268,21 @@ int acpi_pci_bind(struct acpi_device *device) ...@@ -272,25 +268,21 @@ int acpi_pci_bind(struct acpi_device *device)
static int acpi_pci_unbind(struct acpi_device *device) static int acpi_pci_unbind(struct acpi_device *device)
{ {
int result = 0; int result = 0;
acpi_status status = AE_OK; acpi_status status;
struct acpi_pci_data *data = NULL; struct acpi_pci_data *data;
char *pathname = NULL; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_buffer buffer = { 0, NULL };
if (!device || !device->parent) if (!device || !device->parent)
return -EINVAL; return -EINVAL;
pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL); status = acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
if (!pathname) if (ACPI_FAILURE(status))
return -ENOMEM; return -ENODEV;
buffer.length = ACPI_PATHNAME_MAX;
buffer.pointer = pathname;
acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unbinding PCI device [%s]...\n", ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Unbinding PCI device [%s]...\n",
pathname)); (char *) buffer.pointer));
kfree(pathname); kfree(buffer.pointer);
status = status =
acpi_get_data(device->handle, acpi_pci_data_handler, acpi_get_data(device->handle, acpi_pci_data_handler,
...@@ -322,50 +314,44 @@ acpi_pci_bind_root(struct acpi_device *device, ...@@ -322,50 +314,44 @@ acpi_pci_bind_root(struct acpi_device *device,
struct acpi_pci_id *id, struct pci_bus *bus) struct acpi_pci_id *id, struct pci_bus *bus)
{ {
int result = 0; int result = 0;
acpi_status status = AE_OK; acpi_status status;
struct acpi_pci_data *data = NULL; struct acpi_pci_data *data = NULL;
char *pathname = NULL; struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
struct acpi_buffer buffer = { 0, NULL };
pathname = kzalloc(ACPI_PATHNAME_MAX, GFP_KERNEL);
if (!pathname)
return -ENOMEM;
buffer.length = ACPI_PATHNAME_MAX;
buffer.pointer = pathname;
if (!device || !id || !bus) { if (!device || !id || !bus) {
kfree(pathname);
return -EINVAL; return -EINVAL;
} }
data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL); data = kzalloc(sizeof(struct acpi_pci_data), GFP_KERNEL);
if (!data) { if (!data)
kfree(pathname);
return -ENOMEM; return -ENOMEM;
}
data->id = *id; data->id = *id;
data->bus = bus; data->bus = bus;
device->ops.bind = acpi_pci_bind; device->ops.bind = acpi_pci_bind;
device->ops.unbind = acpi_pci_unbind; device->ops.unbind = acpi_pci_unbind;
acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer); status = acpi_get_name(device->handle, ACPI_FULL_PATHNAME, &buffer);
if (ACPI_FAILURE(status)) {
kfree (data);
return -ENODEV;
}
ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI root bridge [%s] to " ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Binding PCI root bridge [%s] to "
"%04x:%02x\n", pathname, id->segment, id->bus)); "%04x:%02x\n", (char *)buffer.pointer,
id->segment, id->bus));
status = acpi_attach_data(device->handle, acpi_pci_data_handler, data); status = acpi_attach_data(device->handle, acpi_pci_data_handler, data);
if (ACPI_FAILURE(status)) { if (ACPI_FAILURE(status)) {
ACPI_EXCEPTION((AE_INFO, status, ACPI_EXCEPTION((AE_INFO, status,
"Unable to attach ACPI-PCI context to device %s", "Unable to attach ACPI-PCI context to device %s",
pathname)); (char *)buffer.pointer));
result = -ENODEV; result = -ENODEV;
goto end; goto end;
} }
end: end:
kfree(pathname); kfree(buffer.pointer);
if (result != 0) if (result != 0)
kfree(data); kfree(data);
......
...@@ -70,9 +70,6 @@ ...@@ -70,9 +70,6 @@
#define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol); #define ACPI_EXPORT_SYMBOL(symbol) EXPORT_SYMBOL(symbol);
#define strtoul simple_strtoul #define strtoul simple_strtoul
/* Full namespace pathname length limit - arbitrary */
#define ACPI_PATHNAME_MAX 256
#else /* !__KERNEL__ */ #else /* !__KERNEL__ */
#include <stdarg.h> #include <stdarg.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment