Skip to content

Commit 3ab4ee8

Browse files
htejuntorvalds
authored andcommitted
misc/c2port: convert to idr_alloc()
Convert to the much saner new idr interface. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Rodolfo Giometti <giometti@linux.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9f12563 commit 3ab4ee8

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

‎drivers/misc/c2port/core.c‎

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ struct c2port_device *c2port_device_register(char *name,
885885
struct c2port_ops *ops, void *devdata)
886886
{
887887
struct c2port_device *c2dev;
888-
int id, ret;
888+
int ret;
889889

890890
if (unlikely(!ops) || unlikely(!ops->access) || \
891891
unlikely(!ops->c2d_dir) || unlikely(!ops->c2ck_set) || \
@@ -897,22 +897,18 @@ struct c2port_device *c2port_device_register(char *name,
897897
if (unlikely(!c2dev))
898898
return ERR_PTR(-ENOMEM);
899899

900-
ret = idr_pre_get(&c2port_idr, GFP_KERNEL);
901-
if (!ret) {
902-
ret = -ENOMEM;
903-
goto error_idr_get_new;
904-
}
905-
900+
idr_preload(GFP_KERNEL);
906901
spin_lock_irq(&c2port_idr_lock);
907-
ret = idr_get_new(&c2port_idr, c2dev, &id);
902+
ret = idr_alloc(&c2port_idr, c2dev, 0, 0, GFP_NOWAIT);
908903
spin_unlock_irq(&c2port_idr_lock);
904+
idr_preload_end();
909905

910906
if (ret < 0)
911-
goto error_idr_get_new;
912-
c2dev->id = id;
907+
goto error_idr_alloc;
908+
c2dev->id = ret;
913909

914910
c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
915-
"c2port%d", id);
911+
"c2port%d", c2dev->id);
916912
if (unlikely(IS_ERR(c2dev->dev))) {
917913
ret = PTR_ERR(c2dev->dev);
918914
goto error_device_create;
@@ -946,10 +942,10 @@ struct c2port_device *c2port_device_register(char *name,
946942

947943
error_device_create:
948944
spin_lock_irq(&c2port_idr_lock);
949-
idr_remove(&c2port_idr, id);
945+
idr_remove(&c2port_idr, c2dev->id);
950946
spin_unlock_irq(&c2port_idr_lock);
951947

952-
error_idr_get_new:
948+
error_idr_alloc:
953949
kfree(c2dev);
954950

955951
return ERR_PTR(ret);

0 commit comments

Comments
 (0)