diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2006-09-18 16:28:06 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-09-26 00:08:40 -0400 |
commit | 7e9f4b2d3e21e87c26025810413ef1592834e63b (patch) | |
tree | 8fa28b786420fede1f3b656ee21289cc4927c6b2 /lib/klist.c | |
parent | 81107bf531d2524afbcd61f3b4ad57a71295d591 (diff) |
Driver core: Don't call put methods while holding a spinlock
The klist utility routines currently call _put methods while holding a
spinlock. This is of course illegal; a put routine could try to
unregister a device and hence need to sleep.
No problems have arisen until now because in many cases klist removals
were done synchronously, so the _put methods were never actually used.
In other cases we may simply have been lucky.
This patch (as784) reworks the klist routines so that _put methods are
called only _after_ the klist's spinlock has been released.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib/klist.c')
-rw-r--r-- | lib/klist.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/klist.c b/lib/klist.c index 9c94f0b163a1..120bd175aa78 100644 --- a/lib/klist.c +++ b/lib/klist.c | |||
@@ -123,12 +123,10 @@ EXPORT_SYMBOL_GPL(klist_add_tail); | |||
123 | static void klist_release(struct kref * kref) | 123 | static void klist_release(struct kref * kref) |
124 | { | 124 | { |
125 | struct klist_node * n = container_of(kref, struct klist_node, n_ref); | 125 | struct klist_node * n = container_of(kref, struct klist_node, n_ref); |
126 | void (*put)(struct klist_node *) = n->n_klist->put; | 126 | |
127 | list_del(&n->n_node); | 127 | list_del(&n->n_node); |
128 | complete(&n->n_removed); | 128 | complete(&n->n_removed); |
129 | n->n_klist = NULL; | 129 | n->n_klist = NULL; |
130 | if (put) | ||
131 | put(n); | ||
132 | } | 130 | } |
133 | 131 | ||
134 | static int klist_dec_and_del(struct klist_node * n) | 132 | static int klist_dec_and_del(struct klist_node * n) |
@@ -145,10 +143,14 @@ static int klist_dec_and_del(struct klist_node * n) | |||
145 | void klist_del(struct klist_node * n) | 143 | void klist_del(struct klist_node * n) |
146 | { | 144 | { |
147 | struct klist * k = n->n_klist; | 145 | struct klist * k = n->n_klist; |
146 | void (*put)(struct klist_node *) = k->put; | ||
148 | 147 | ||
149 | spin_lock(&k->k_lock); | 148 | spin_lock(&k->k_lock); |
150 | klist_dec_and_del(n); | 149 | if (!klist_dec_and_del(n)) |
150 | put = NULL; | ||
151 | spin_unlock(&k->k_lock); | 151 | spin_unlock(&k->k_lock); |
152 | if (put) | ||
153 | put(n); | ||
152 | } | 154 | } |
153 | 155 | ||
154 | EXPORT_SYMBOL_GPL(klist_del); | 156 | EXPORT_SYMBOL_GPL(klist_del); |
@@ -161,10 +163,7 @@ EXPORT_SYMBOL_GPL(klist_del); | |||
161 | 163 | ||
162 | void klist_remove(struct klist_node * n) | 164 | void klist_remove(struct klist_node * n) |
163 | { | 165 | { |
164 | struct klist * k = n->n_klist; | 166 | klist_del(n); |
165 | spin_lock(&k->k_lock); | ||
166 | klist_dec_and_del(n); | ||
167 | spin_unlock(&k->k_lock); | ||
168 | wait_for_completion(&n->n_removed); | 167 | wait_for_completion(&n->n_removed); |
169 | } | 168 | } |
170 | 169 | ||
@@ -260,12 +259,15 @@ static struct klist_node * to_klist_node(struct list_head * n) | |||
260 | struct klist_node * klist_next(struct klist_iter * i) | 259 | struct klist_node * klist_next(struct klist_iter * i) |
261 | { | 260 | { |
262 | struct list_head * next; | 261 | struct list_head * next; |
262 | struct klist_node * lnode = i->i_cur; | ||
263 | struct klist_node * knode = NULL; | 263 | struct klist_node * knode = NULL; |
264 | void (*put)(struct klist_node *) = i->i_klist->put; | ||
264 | 265 | ||
265 | spin_lock(&i->i_klist->k_lock); | 266 | spin_lock(&i->i_klist->k_lock); |
266 | if (i->i_cur) { | 267 | if (lnode) { |
267 | next = i->i_cur->n_node.next; | 268 | next = lnode->n_node.next; |
268 | klist_dec_and_del(i->i_cur); | 269 | if (!klist_dec_and_del(lnode)) |
270 | put = NULL; | ||
269 | } else | 271 | } else |
270 | next = i->i_head->next; | 272 | next = i->i_head->next; |
271 | 273 | ||
@@ -275,6 +277,8 @@ struct klist_node * klist_next(struct klist_iter * i) | |||
275 | } | 277 | } |
276 | i->i_cur = knode; | 278 | i->i_cur = knode; |
277 | spin_unlock(&i->i_klist->k_lock); | 279 | spin_unlock(&i->i_klist->k_lock); |
280 | if (put && lnode) | ||
281 | put(lnode); | ||
278 | return knode; | 282 | return knode; |
279 | } | 283 | } |
280 | 284 | ||