Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

firewire: convert to idr_alloc()

Convert to the much saner new idr interface.

v2: Stefan pointed out that add_client_resource() may be called from
non-process context. Preload iff @gfp_mask contains __GFP_WAIT.
Also updated to include minor upper limit check.

[tim.gardner@canonical.com: fix accidentally orphaned 'minor'[
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Tejun Heo and committed by
Linus Torvalds
37b61890 3bec60d5

+13 -17
+10 -9
drivers/firewire/core-cdev.c
··· 487 487 static int add_client_resource(struct client *client, 488 488 struct client_resource *resource, gfp_t gfp_mask) 489 489 { 490 + bool preload = gfp_mask & __GFP_WAIT; 490 491 unsigned long flags; 491 492 int ret; 492 493 493 - retry: 494 - if (idr_pre_get(&client->resource_idr, gfp_mask) == 0) 495 - return -ENOMEM; 496 - 494 + if (preload) 495 + idr_preload(gfp_mask); 497 496 spin_lock_irqsave(&client->lock, flags); 497 + 498 498 if (client->in_shutdown) 499 499 ret = -ECANCELED; 500 500 else 501 - ret = idr_get_new(&client->resource_idr, resource, 502 - &resource->handle); 501 + ret = idr_alloc(&client->resource_idr, resource, 0, 0, 502 + GFP_NOWAIT); 503 503 if (ret >= 0) { 504 + resource->handle = ret; 504 505 client_get(client); 505 506 schedule_if_iso_resource(resource); 506 507 } 507 - spin_unlock_irqrestore(&client->lock, flags); 508 508 509 - if (ret == -EAGAIN) 510 - goto retry; 509 + spin_unlock_irqrestore(&client->lock, flags); 510 + if (preload) 511 + idr_preload_end(); 511 512 512 513 return ret < 0 ? ret : 0; 513 514 }
+3 -8
drivers/firewire/core-device.c
··· 1017 1017 1018 1018 fw_device_get(device); 1019 1019 down_write(&fw_device_rwsem); 1020 - ret = idr_pre_get(&fw_device_idr, GFP_KERNEL) ? 1021 - idr_get_new(&fw_device_idr, device, &minor) : 1022 - -ENOMEM; 1023 - if (minor >= 1 << MINORBITS) { 1024 - idr_remove(&fw_device_idr, minor); 1025 - minor = -ENOSPC; 1026 - } 1020 + minor = idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS, 1021 + GFP_KERNEL); 1027 1022 up_write(&fw_device_rwsem); 1028 1023 1029 - if (ret < 0) 1024 + if (minor < 0) 1030 1025 goto error; 1031 1026 1032 1027 device->device.bus = &fw_bus_type;