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>
This commit is contained in:
parent
3bec60d511
commit
37b61890d7
2 changed files with 13 additions and 17 deletions
|
@ -487,27 +487,28 @@ static int ioctl_get_info(struct client *client, union ioctl_arg *arg)
|
||||||
static int add_client_resource(struct client *client,
|
static int add_client_resource(struct client *client,
|
||||||
struct client_resource *resource, gfp_t gfp_mask)
|
struct client_resource *resource, gfp_t gfp_mask)
|
||||||
{
|
{
|
||||||
|
bool preload = gfp_mask & __GFP_WAIT;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
retry:
|
if (preload)
|
||||||
if (idr_pre_get(&client->resource_idr, gfp_mask) == 0)
|
idr_preload(gfp_mask);
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&client->lock, flags);
|
spin_lock_irqsave(&client->lock, flags);
|
||||||
|
|
||||||
if (client->in_shutdown)
|
if (client->in_shutdown)
|
||||||
ret = -ECANCELED;
|
ret = -ECANCELED;
|
||||||
else
|
else
|
||||||
ret = idr_get_new(&client->resource_idr, resource,
|
ret = idr_alloc(&client->resource_idr, resource, 0, 0,
|
||||||
&resource->handle);
|
GFP_NOWAIT);
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
|
resource->handle = ret;
|
||||||
client_get(client);
|
client_get(client);
|
||||||
schedule_if_iso_resource(resource);
|
schedule_if_iso_resource(resource);
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&client->lock, flags);
|
|
||||||
|
|
||||||
if (ret == -EAGAIN)
|
spin_unlock_irqrestore(&client->lock, flags);
|
||||||
goto retry;
|
if (preload)
|
||||||
|
idr_preload_end();
|
||||||
|
|
||||||
return ret < 0 ? ret : 0;
|
return ret < 0 ? ret : 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1017,16 +1017,11 @@ static void fw_device_init(struct work_struct *work)
|
||||||
|
|
||||||
fw_device_get(device);
|
fw_device_get(device);
|
||||||
down_write(&fw_device_rwsem);
|
down_write(&fw_device_rwsem);
|
||||||
ret = idr_pre_get(&fw_device_idr, GFP_KERNEL) ?
|
minor = idr_alloc(&fw_device_idr, device, 0, 1 << MINORBITS,
|
||||||
idr_get_new(&fw_device_idr, device, &minor) :
|
GFP_KERNEL);
|
||||||
-ENOMEM;
|
|
||||||
if (minor >= 1 << MINORBITS) {
|
|
||||||
idr_remove(&fw_device_idr, minor);
|
|
||||||
minor = -ENOSPC;
|
|
||||||
}
|
|
||||||
up_write(&fw_device_rwsem);
|
up_write(&fw_device_rwsem);
|
||||||
|
|
||||||
if (ret < 0)
|
if (minor < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
device->device.bus = &fw_bus_type;
|
device->device.bus = &fw_bus_type;
|
||||||
|
|
Loading…
Add table
Reference in a new issue