mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-15 01:24:33 +00:00
ieee1394: nodemgr: remove a kcalloc
Was I sleepwalking when I wrote this? Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
This commit is contained in:
parent
3015c73978
commit
1e4f7bc8f8
@ -754,59 +754,33 @@ static DEFINE_MUTEX(nodemgr_serialize_remove_uds);
|
|||||||
static void nodemgr_remove_uds(struct node_entry *ne)
|
static void nodemgr_remove_uds(struct node_entry *ne)
|
||||||
{
|
{
|
||||||
struct class_device *cdev;
|
struct class_device *cdev;
|
||||||
struct unit_directory *ud, **unreg;
|
struct unit_directory *tmp, *ud;
|
||||||
size_t i, count;
|
|
||||||
|
|
||||||
/*
|
/* Iteration over nodemgr_ud_class.children has to be protected by
|
||||||
* This is awkward:
|
|
||||||
* Iteration over nodemgr_ud_class.children has to be protected by
|
|
||||||
* nodemgr_ud_class.sem, but class_device_unregister() will eventually
|
* nodemgr_ud_class.sem, but class_device_unregister() will eventually
|
||||||
* take nodemgr_ud_class.sem too. Therefore store all uds to be
|
* take nodemgr_ud_class.sem too. Therefore pick out one ud at a time,
|
||||||
* unregistered in a temporary array, release the semaphore, and then
|
* release the semaphore, and then unregister the ud. Since this code
|
||||||
* unregister the uds.
|
* may be called from other contexts besides the knodemgrds, protect the
|
||||||
*
|
|
||||||
* Since nodemgr_remove_uds can also run in other contexts than the
|
|
||||||
* knodemgrds (which are currently globally serialized), protect the
|
|
||||||
* gap after release of the semaphore by nodemgr_serialize_remove_uds.
|
* gap after release of the semaphore by nodemgr_serialize_remove_uds.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mutex_lock(&nodemgr_serialize_remove_uds);
|
mutex_lock(&nodemgr_serialize_remove_uds);
|
||||||
|
for (;;) {
|
||||||
down(&nodemgr_ud_class.sem);
|
ud = NULL;
|
||||||
count = 0;
|
down(&nodemgr_ud_class.sem);
|
||||||
list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
|
list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
|
||||||
ud = container_of(cdev, struct unit_directory, class_dev);
|
tmp = container_of(cdev, struct unit_directory,
|
||||||
if (ud->ne == ne)
|
class_dev);
|
||||||
count++;
|
if (tmp->ne == ne) {
|
||||||
}
|
ud = tmp;
|
||||||
if (!count) {
|
break;
|
||||||
up(&nodemgr_ud_class.sem);
|
}
|
||||||
mutex_unlock(&nodemgr_serialize_remove_uds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
unreg = kcalloc(count, sizeof(*unreg), GFP_KERNEL);
|
|
||||||
if (!unreg) {
|
|
||||||
HPSB_ERR("NodeMgr: out of memory in nodemgr_remove_uds");
|
|
||||||
up(&nodemgr_ud_class.sem);
|
|
||||||
mutex_unlock(&nodemgr_serialize_remove_uds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
list_for_each_entry(cdev, &nodemgr_ud_class.children, node) {
|
|
||||||
ud = container_of(cdev, struct unit_directory, class_dev);
|
|
||||||
if (ud->ne == ne) {
|
|
||||||
BUG_ON(i >= count);
|
|
||||||
unreg[i++] = ud;
|
|
||||||
}
|
}
|
||||||
|
up(&nodemgr_ud_class.sem);
|
||||||
|
if (ud == NULL)
|
||||||
|
break;
|
||||||
|
class_device_unregister(&ud->class_dev);
|
||||||
|
device_unregister(&ud->device);
|
||||||
}
|
}
|
||||||
up(&nodemgr_ud_class.sem);
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
|
||||||
class_device_unregister(&unreg[i]->class_dev);
|
|
||||||
device_unregister(&unreg[i]->device);
|
|
||||||
}
|
|
||||||
kfree(unreg);
|
|
||||||
|
|
||||||
mutex_unlock(&nodemgr_serialize_remove_uds);
|
mutex_unlock(&nodemgr_serialize_remove_uds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user