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

macvtap: convert to idr_alloc()

Convert to the much saner new idr interface.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
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
ec09ebc1 589e9c4d

+5 -16
+5 -16
drivers/net/macvtap.c
··· 279 279 static int macvtap_get_minor(struct macvlan_dev *vlan) 280 280 { 281 281 int retval = -ENOMEM; 282 - int id; 283 282 284 283 mutex_lock(&minor_lock); 285 - if (idr_pre_get(&minor_idr, GFP_KERNEL) == 0) 286 - goto exit; 287 - 288 - retval = idr_get_new_above(&minor_idr, vlan, 1, &id); 289 - if (retval < 0) { 290 - if (retval == -EAGAIN) 291 - retval = -ENOMEM; 292 - goto exit; 293 - } 294 - if (id < MACVTAP_NUM_DEVS) { 295 - vlan->minor = id; 296 - } else { 284 + retval = idr_alloc(&minor_idr, vlan, 1, MACVTAP_NUM_DEVS, GFP_KERNEL); 285 + if (retval >= 0) { 286 + vlan->minor = retval; 287 + } else if (retval == -ENOSPC) { 297 288 printk(KERN_ERR "too many macvtap devices\n"); 298 289 retval = -EINVAL; 299 - idr_remove(&minor_idr, id); 300 290 } 301 - exit: 302 291 mutex_unlock(&minor_lock); 303 - return retval; 292 + return retval < 0 ? retval : 0; 304 293 } 305 294 306 295 static void macvtap_free_minor(struct macvlan_dev *vlan)