aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-06-30 17:47:14 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2013-07-14 19:33:11 -0400
commit4ec24065a65b4debfdeb591cc01a4aa092651f53 (patch)
treeaa21b3a9df792b568c0fef3b809e33b2232960c1
parent37f908778f20bbcc35ab9a98a5b584329c6abf08 (diff)
ACPI / dock: Simplify dock_init_hotplug() and dock_release_hotplug()
Make dock_init_hotplug() and dock_release_hotplug() slightly simpler and move some checks in those functions to the code paths where they are needed. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Acked-by: Yinghai Lu <yinghai@kernel.org>
-rw-r--r--drivers/acpi/dock.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 41c5d04a89c1..b1170d60a836 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -130,19 +130,16 @@ static int dock_init_hotplug(struct dock_dependent_device *dd,
130 int ret = 0; 130 int ret = 0;
131 131
132 mutex_lock(&hotplug_lock); 132 mutex_lock(&hotplug_lock);
133 133 if (WARN_ON(dd->hp_context)) {
134 if (dd->hp_context) {
135 ret = -EEXIST; 134 ret = -EEXIST;
136 } else { 135 } else {
137 dd->hp_refcount = 1; 136 dd->hp_refcount = 1;
138 dd->hp_ops = ops; 137 dd->hp_ops = ops;
139 dd->hp_context = context; 138 dd->hp_context = context;
140 dd->hp_release = release; 139 dd->hp_release = release;
140 if (init)
141 init(context);
141 } 142 }
142
143 if (!WARN_ON(ret) && init)
144 init(context);
145
146 mutex_unlock(&hotplug_lock); 143 mutex_unlock(&hotplug_lock);
147 return ret; 144 return ret;
148} 145}
@@ -157,22 +154,17 @@ static int dock_init_hotplug(struct dock_dependent_device *dd,
157 */ 154 */
158static void dock_release_hotplug(struct dock_dependent_device *dd) 155static void dock_release_hotplug(struct dock_dependent_device *dd)
159{ 156{
160 void (*release)(void *) = NULL;
161 void *context = NULL;
162
163 mutex_lock(&hotplug_lock); 157 mutex_lock(&hotplug_lock);
164
165 if (dd->hp_context && !--dd->hp_refcount) { 158 if (dd->hp_context && !--dd->hp_refcount) {
159 void (*release)(void *) = dd->hp_release;
160 void *context = dd->hp_context;
161
166 dd->hp_ops = NULL; 162 dd->hp_ops = NULL;
167 context = dd->hp_context;
168 dd->hp_context = NULL; 163 dd->hp_context = NULL;
169 release = dd->hp_release;
170 dd->hp_release = NULL; 164 dd->hp_release = NULL;
165 if (release)
166 release(context);
171 } 167 }
172
173 if (release && context)
174 release(context);
175
176 mutex_unlock(&hotplug_lock); 168 mutex_unlock(&hotplug_lock);
177} 169}
178 170