diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-07-13 17:27:25 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-07-22 22:00:23 -0400 |
commit | bd4674dfc5fc704837148f36af41e1e0a640dfec (patch) | |
tree | 548c1480e87a85372760339053fc72ebeedd6403 /drivers/pci/hotplug/acpiphp_glue.c | |
parent | 75a33ed1b58005e455cb6533a7689ac0eb6bedd6 (diff) |
ACPI / hotplug / PCI: Embed function struct into struct acpiphp_context
Since there has to be a struct acpiphp_func object for every struct
acpiphp_context created by register_slot(), the struct acpiphp_func
one can be embedded into the struct acpiphp_context one, which allows
some code simplifications to be made.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Tested-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Diffstat (limited to 'drivers/pci/hotplug/acpiphp_glue.c')
-rw-r--r-- | drivers/pci/hotplug/acpiphp_glue.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c index 5d79175b9a09..cc7453e0722e 100644 --- a/drivers/pci/hotplug/acpiphp_glue.c +++ b/drivers/pci/hotplug/acpiphp_glue.c | |||
@@ -128,7 +128,7 @@ static void acpiphp_put_context(struct acpiphp_context *context) | |||
128 | if (--context->refcount) | 128 | if (--context->refcount) |
129 | return; | 129 | return; |
130 | 130 | ||
131 | WARN_ON(context->func || context->bridge); | 131 | WARN_ON(context->bridge); |
132 | acpi_detach_data(context->handle, acpiphp_context_handler); | 132 | acpi_detach_data(context->handle, acpiphp_context_handler); |
133 | kfree(context); | 133 | kfree(context); |
134 | } | 134 | } |
@@ -155,12 +155,9 @@ static void free_bridge(struct kref *kref) | |||
155 | bridge = container_of(kref, struct acpiphp_bridge, ref); | 155 | bridge = container_of(kref, struct acpiphp_bridge, ref); |
156 | 156 | ||
157 | list_for_each_entry_safe(slot, next, &bridge->slots, node) { | 157 | list_for_each_entry_safe(slot, next, &bridge->slots, node) { |
158 | list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) { | 158 | list_for_each_entry_safe(func, tmp, &slot->funcs, sibling) |
159 | context = func->context; | 159 | acpiphp_put_context(func_to_context(func)); |
160 | context->func = NULL; | 160 | |
161 | acpiphp_put_context(context); | ||
162 | kfree(func); | ||
163 | } | ||
164 | kfree(slot); | 161 | kfree(slot); |
165 | } | 162 | } |
166 | 163 | ||
@@ -168,7 +165,7 @@ static void free_bridge(struct kref *kref) | |||
168 | /* Root bridges will not have hotplug context. */ | 165 | /* Root bridges will not have hotplug context. */ |
169 | if (context) { | 166 | if (context) { |
170 | /* Release the reference taken by acpiphp_enumerate_slots(). */ | 167 | /* Release the reference taken by acpiphp_enumerate_slots(). */ |
171 | put_bridge(context->func->slot->bridge); | 168 | put_bridge(context->func.slot->bridge); |
172 | context->bridge = NULL; | 169 | context->bridge = NULL; |
173 | acpiphp_put_context(context); | 170 | acpiphp_put_context(context); |
174 | } | 171 | } |
@@ -190,7 +187,7 @@ static void free_bridge(struct kref *kref) | |||
190 | static void post_dock_fixups(acpi_handle not_used, u32 event, void *data) | 187 | static void post_dock_fixups(acpi_handle not_used, u32 event, void *data) |
191 | { | 188 | { |
192 | struct acpiphp_context *context = data; | 189 | struct acpiphp_context *context = data; |
193 | struct pci_bus *bus = context->func->slot->bridge->pci_bus; | 190 | struct pci_bus *bus = context->func.slot->bridge->pci_bus; |
194 | u32 buses; | 191 | u32 buses; |
195 | 192 | ||
196 | if (!bus->self) | 193 | if (!bus->self) |
@@ -251,14 +248,14 @@ static void acpiphp_dock_init(void *data) | |||
251 | { | 248 | { |
252 | struct acpiphp_context *context = data; | 249 | struct acpiphp_context *context = data; |
253 | 250 | ||
254 | get_bridge(context->func->slot->bridge); | 251 | get_bridge(context->func.slot->bridge); |
255 | } | 252 | } |
256 | 253 | ||
257 | static void acpiphp_dock_release(void *data) | 254 | static void acpiphp_dock_release(void *data) |
258 | { | 255 | { |
259 | struct acpiphp_context *context = data; | 256 | struct acpiphp_context *context = data; |
260 | 257 | ||
261 | put_bridge(context->func->slot->bridge); | 258 | put_bridge(context->func.slot->bridge); |
262 | } | 259 | } |
263 | 260 | ||
264 | /* callback routine to register each ACPI PCI slot object */ | 261 | /* callback routine to register each ACPI PCI slot object */ |
@@ -288,23 +285,16 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, | |||
288 | device = (adr >> 16) & 0xffff; | 285 | device = (adr >> 16) & 0xffff; |
289 | function = adr & 0xffff; | 286 | function = adr & 0xffff; |
290 | 287 | ||
291 | newfunc = kzalloc(sizeof(struct acpiphp_func), GFP_KERNEL); | ||
292 | if (!newfunc) | ||
293 | return AE_NO_MEMORY; | ||
294 | |||
295 | newfunc->handle = handle; | ||
296 | newfunc->function = function; | ||
297 | |||
298 | mutex_lock(&acpiphp_context_lock); | 288 | mutex_lock(&acpiphp_context_lock); |
299 | context = acpiphp_init_context(handle); | 289 | context = acpiphp_init_context(handle); |
300 | if (!context) { | 290 | if (!context) { |
301 | mutex_unlock(&acpiphp_context_lock); | 291 | mutex_unlock(&acpiphp_context_lock); |
302 | acpi_handle_err(handle, "No hotplug context\n"); | 292 | acpi_handle_err(handle, "No hotplug context\n"); |
303 | kfree(newfunc); | ||
304 | return AE_NOT_EXIST; | 293 | return AE_NOT_EXIST; |
305 | } | 294 | } |
306 | newfunc->context = context; | 295 | newfunc = &context->func; |
307 | context->func = newfunc; | 296 | newfunc->handle = handle; |
297 | newfunc->function = function; | ||
308 | mutex_unlock(&acpiphp_context_lock); | 298 | mutex_unlock(&acpiphp_context_lock); |
309 | 299 | ||
310 | if (acpi_has_method(handle, "_EJ0")) | 300 | if (acpi_has_method(handle, "_EJ0")) |
@@ -404,10 +394,8 @@ static acpi_status register_slot(acpi_handle handle, u32 lvl, void *data, | |||
404 | 394 | ||
405 | err: | 395 | err: |
406 | mutex_lock(&acpiphp_context_lock); | 396 | mutex_lock(&acpiphp_context_lock); |
407 | context->func = NULL; | ||
408 | acpiphp_put_context(context); | 397 | acpiphp_put_context(context); |
409 | mutex_unlock(&acpiphp_context_lock); | 398 | mutex_unlock(&acpiphp_context_lock); |
410 | kfree(newfunc); | ||
411 | return status; | 399 | return status; |
412 | } | 400 | } |
413 | 401 | ||
@@ -938,7 +926,7 @@ void acpiphp_check_host_bridge(acpi_handle handle) | |||
938 | static void hotplug_event(acpi_handle handle, u32 type, void *data) | 926 | static void hotplug_event(acpi_handle handle, u32 type, void *data) |
939 | { | 927 | { |
940 | struct acpiphp_context *context = data; | 928 | struct acpiphp_context *context = data; |
941 | struct acpiphp_func *func = context->func; | 929 | struct acpiphp_func *func = &context->func; |
942 | struct acpiphp_bridge *bridge; | 930 | struct acpiphp_bridge *bridge; |
943 | char objname[64]; | 931 | char objname[64]; |
944 | struct acpi_buffer buffer = { .length = sizeof(objname), | 932 | struct acpi_buffer buffer = { .length = sizeof(objname), |
@@ -1029,7 +1017,7 @@ static void hotplug_event_work(struct work_struct *work) | |||
1029 | 1017 | ||
1030 | acpi_scan_lock_release(); | 1018 | acpi_scan_lock_release(); |
1031 | kfree(hp_work); /* allocated in handle_hotplug_event() */ | 1019 | kfree(hp_work); /* allocated in handle_hotplug_event() */ |
1032 | put_bridge(context->func->slot->bridge); | 1020 | put_bridge(context->func.slot->bridge); |
1033 | } | 1021 | } |
1034 | 1022 | ||
1035 | /** | 1023 | /** |
@@ -1047,7 +1035,7 @@ static void handle_hotplug_event(acpi_handle handle, u32 type, void *data) | |||
1047 | mutex_lock(&acpiphp_context_lock); | 1035 | mutex_lock(&acpiphp_context_lock); |
1048 | context = acpiphp_get_context(handle); | 1036 | context = acpiphp_get_context(handle); |
1049 | if (context) { | 1037 | if (context) { |
1050 | get_bridge(context->func->slot->bridge); | 1038 | get_bridge(context->func.slot->bridge); |
1051 | acpiphp_put_context(context); | 1039 | acpiphp_put_context(context); |
1052 | } | 1040 | } |
1053 | mutex_unlock(&acpiphp_context_lock); | 1041 | mutex_unlock(&acpiphp_context_lock); |
@@ -1109,7 +1097,7 @@ void acpiphp_enumerate_slots(struct pci_bus *bus) | |||
1109 | */ | 1097 | */ |
1110 | mutex_lock(&acpiphp_context_lock); | 1098 | mutex_lock(&acpiphp_context_lock); |
1111 | context = acpiphp_get_context(handle); | 1099 | context = acpiphp_get_context(handle); |
1112 | if (WARN_ON(!context || !context->func)) { | 1100 | if (WARN_ON(!context)) { |
1113 | mutex_unlock(&acpiphp_context_lock); | 1101 | mutex_unlock(&acpiphp_context_lock); |
1114 | put_device(&bus->dev); | 1102 | put_device(&bus->dev); |
1115 | kfree(bridge); | 1103 | kfree(bridge); |
@@ -1118,7 +1106,7 @@ void acpiphp_enumerate_slots(struct pci_bus *bus) | |||
1118 | bridge->context = context; | 1106 | bridge->context = context; |
1119 | context->bridge = bridge; | 1107 | context->bridge = bridge; |
1120 | /* Get a reference to the parent bridge. */ | 1108 | /* Get a reference to the parent bridge. */ |
1121 | get_bridge(context->func->slot->bridge); | 1109 | get_bridge(context->func.slot->bridge); |
1122 | mutex_unlock(&acpiphp_context_lock); | 1110 | mutex_unlock(&acpiphp_context_lock); |
1123 | } | 1111 | } |
1124 | 1112 | ||