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

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>

authored by

Tejun Heo and committed by
Linus Torvalds
3ab4ee8f 9f12563d

+9 -13
+9 -13
drivers/misc/c2port/core.c
··· 885 885 struct c2port_ops *ops, void *devdata) 886 886 { 887 887 struct c2port_device *c2dev; 888 - int id, ret; 888 + int ret; 889 889 890 890 if (unlikely(!ops) || unlikely(!ops->access) || \ 891 891 unlikely(!ops->c2d_dir) || unlikely(!ops->c2ck_set) || \ ··· 897 897 if (unlikely(!c2dev)) 898 898 return ERR_PTR(-ENOMEM); 899 899 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); 906 901 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); 908 903 spin_unlock_irq(&c2port_idr_lock); 904 + idr_preload_end(); 909 905 910 906 if (ret < 0) 911 - goto error_idr_get_new; 912 - c2dev->id = id; 907 + goto error_idr_alloc; 908 + c2dev->id = ret; 913 909 914 910 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev, 915 - "c2port%d", id); 911 + "c2port%d", c2dev->id); 916 912 if (unlikely(IS_ERR(c2dev->dev))) { 917 913 ret = PTR_ERR(c2dev->dev); 918 914 goto error_device_create; ··· 942 946 943 947 error_device_create: 944 948 spin_lock_irq(&c2port_idr_lock); 945 - idr_remove(&c2port_idr, id); 949 + idr_remove(&c2port_idr, c2dev->id); 946 950 spin_unlock_irq(&c2port_idr_lock); 947 951 948 - error_idr_get_new: 952 + error_idr_alloc: 949 953 kfree(c2dev); 950 954 951 955 return ERR_PTR(ret);