Commit b2e6e3ba7deb525f180df64f32f3fcb214538bea

Authored by MUNEDA Takahiro
Committed by Greg Kroah-Hartman
1 parent dc6712d126

[PATCH] acpiphp: fix acpi_path_name

I encountered the problem that the insmod of the acpiphp
fails because of the mis-freeing of the memory.

I tested this patch on my tiger4 box.

Signed-off-by: MUNEDA Takahiro <muneda.takahiro@jp.fujitsu.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 3 changed files with 27 additions and 43 deletions Side-by-side Diff

drivers/pci/hotplug/acpi_pcihp.c
... ... @@ -37,39 +37,19 @@
37 37 #define METHOD_NAME__HPP "_HPP"
38 38 #define METHOD_NAME_OSHP "OSHP"
39 39  
40   -/* acpi_path_name
41   - *
42   - * @handle - the acpi_handle of the object who's name you want.
43   - *
44   - * Caller must free buffer.
45   - */
46   -u8 * acpi_path_name(acpi_handle handle)
47   -{
48   - acpi_status status;
49   - struct acpi_buffer ret_buf = {ACPI_ALLOCATE_BUFFER, NULL};
50   - union acpi_object *obj;
51 40  
52   - status = acpi_get_name(handle, ACPI_FULL_PATHNAME, &ret_buf);
53   - if (ACPI_FAILURE(status)) {
54   - return NULL;
55   - }
56   - obj = ret_buf.pointer;
57   - return obj->string.pointer;
58   -}
59   -EXPORT_SYMBOL_GPL(acpi_path_name);
60   -
61   -
62   -
63 41 static acpi_status
64 42 acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
65 43 {
66 44 acpi_status status;
67 45 u8 nui[4];
68 46 struct acpi_buffer ret_buf = { 0, NULL};
  47 + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
69 48 union acpi_object *ext_obj, *package;
70   - u8 *path_name = acpi_path_name(handle);
71 49 int i, len = 0;
72 50  
  51 + acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  52 +
73 53 /* get _hpp */
74 54 status = acpi_evaluate_object(handle, METHOD_NAME__HPP, NULL, &ret_buf);
75 55 switch (status) {
... ... @@ -77,8 +57,8 @@
77 57 ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
78 58 if (!ret_buf.pointer) {
79 59 printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
80   - __FUNCTION__, path_name);
81   - acpi_os_free(path_name);
  60 + __FUNCTION__, (char *)string.pointer);
  61 + acpi_os_free(string.pointer);
82 62 return AE_NO_MEMORY;
83 63 }
84 64 status = acpi_evaluate_object(handle, METHOD_NAME__HPP,
... ... @@ -88,8 +68,8 @@
88 68 default:
89 69 if (ACPI_FAILURE(status)) {
90 70 pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
91   - path_name, status);
92   - acpi_os_free(path_name);
  71 + (char *)string.pointer, status);
  72 + acpi_os_free(string.pointer);
93 73 return status;
94 74 }
95 75 }
... ... @@ -97,7 +77,7 @@
97 77 ext_obj = (union acpi_object *) ret_buf.pointer;
98 78 if (ext_obj->type != ACPI_TYPE_PACKAGE) {
99 79 printk(KERN_ERR "%s:%s _HPP obj not a package\n", __FUNCTION__,
100   - path_name);
  80 + (char *)string.pointer);
101 81 status = AE_ERROR;
102 82 goto free_and_return;
103 83 }
... ... @@ -112,7 +92,7 @@
112 92 break;
113 93 default:
114 94 printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
115   - __FUNCTION__, path_name);
  95 + __FUNCTION__, (char *)string.pointer);
116 96 status = AE_ERROR;
117 97 goto free_and_return;
118 98 }
... ... @@ -129,8 +109,8 @@
129 109 pr_debug(" _HPP: enable PERR =0x%x\n", hpp->enable_perr);
130 110  
131 111 free_and_return:
132   - acpi_os_free(path_name);
133   - kfree(ret_buf.pointer);
  112 + acpi_os_free(string.pointer);
  113 + acpi_os_free(ret_buf.pointer);
134 114 return status;
135 115 }
136 116  
137 117  
138 118  
139 119  
... ... @@ -143,16 +123,20 @@
143 123 acpi_status acpi_run_oshp(acpi_handle handle)
144 124 {
145 125 acpi_status status;
146   - u8 *path_name = acpi_path_name(handle);
  126 + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
147 127  
  128 + acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  129 +
148 130 /* run OSHP */
149 131 status = acpi_evaluate_object(handle, METHOD_NAME_OSHP, NULL, NULL);
150 132 if (ACPI_FAILURE(status))
151 133 printk(KERN_ERR "%s:%s OSHP fails=0x%x\n", __FUNCTION__,
152   - path_name, status);
  134 + (char *)string.pointer, status);
153 135 else
154   - pr_debug("%s:%s OSHP passes\n", __FUNCTION__, path_name);
155   - acpi_os_free(path_name);
  136 + pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
  137 + (char *)string.pointer);
  138 +
  139 + acpi_os_free(string.pointer);
156 140 return status;
157 141 }
158 142 EXPORT_SYMBOL_GPL(acpi_run_oshp);
drivers/pci/hotplug/pci_hotplug.h
... ... @@ -190,7 +190,6 @@
190 190 extern acpi_status acpi_run_oshp(acpi_handle handle);
191 191 extern acpi_status acpi_get_hp_params_from_firmware(struct pci_dev *dev,
192 192 struct hotplug_params *hpp);
193   -extern u8 * acpi_path_name(acpi_handle handle);
194 193 int acpi_root_bridge(acpi_handle handle);
195 194 #endif
196 195 #endif
drivers/pci/hotplug/pciehp_hpc.c
... ... @@ -1246,7 +1246,7 @@
1246 1246 acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
1247 1247 struct pci_dev *pdev = dev;
1248 1248 struct pci_bus *parent;
1249   - u8 *path_name = NULL;
  1249 + struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
1250 1250  
1251 1251 /*
1252 1252 * Per PCI firmware specification, we should run the ACPI _OSC
1253 1253  
... ... @@ -1278,16 +1278,17 @@
1278 1278 }
1279 1279  
1280 1280 while (handle) {
1281   - path_name = acpi_path_name(handle);
1282   - dbg("Trying to get hotplug control for %s \n", path_name);
  1281 + acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
  1282 + dbg("Trying to get hotplug control for %s \n",
  1283 + (char *)string.pointer);
1283 1284 status = pci_osc_control_set(handle,
1284 1285 OSC_PCI_EXPRESS_NATIVE_HP_CONTROL);
1285 1286 if (status == AE_NOT_FOUND)
1286 1287 status = acpi_run_oshp(handle);
1287 1288 if (ACPI_SUCCESS(status)) {
1288 1289 dbg("Gained control for hotplug HW for pci %s (%s)\n",
1289   - pci_name(dev), path_name);
1290   - acpi_os_free(path_name);
  1290 + pci_name(dev), (char *)string.pointer);
  1291 + acpi_os_free(string.pointer);
1291 1292 return 0;
1292 1293 }
1293 1294 if (acpi_root_bridge(handle))
... ... @@ -1300,8 +1301,8 @@
1300 1301  
1301 1302 err("Cannot get control of hotplug hardware for pci %s\n",
1302 1303 pci_name(dev));
1303   - if (path_name)
1304   - acpi_os_free(path_name);
  1304 +
  1305 + acpi_os_free(string.pointer);
1305 1306 return -1;
1306 1307 }
1307 1308 #endif