Commit ec09ebc1 authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

macvtap: convert to idr_alloc()

Convert to the much saner new idr interface.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 589e9c4d
...@@ -279,28 +279,17 @@ static int macvtap_receive(struct sk_buff *skb) ...@@ -279,28 +279,17 @@ static int macvtap_receive(struct sk_buff *skb)
static int macvtap_get_minor(struct macvlan_dev *vlan) static int macvtap_get_minor(struct macvlan_dev *vlan)
{ {
int retval = -ENOMEM; int retval = -ENOMEM;
int id;
mutex_lock(&minor_lock); mutex_lock(&minor_lock);
if (idr_pre_get(&minor_idr, GFP_KERNEL) == 0) retval = idr_alloc(&minor_idr, vlan, 1, MACVTAP_NUM_DEVS, GFP_KERNEL);
goto exit; if (retval >= 0) {
vlan->minor = retval;
retval = idr_get_new_above(&minor_idr, vlan, 1, &id); } else if (retval == -ENOSPC) {
if (retval < 0) {
if (retval == -EAGAIN)
retval = -ENOMEM;
goto exit;
}
if (id < MACVTAP_NUM_DEVS) {
vlan->minor = id;
} else {
printk(KERN_ERR "too many macvtap devices\n"); printk(KERN_ERR "too many macvtap devices\n");
retval = -EINVAL; retval = -EINVAL;
idr_remove(&minor_idr, id);
} }
exit:
mutex_unlock(&minor_lock); mutex_unlock(&minor_lock);
return retval; return retval < 0 ? retval : 0;
} }
static void macvtap_free_minor(struct macvlan_dev *vlan) static void macvtap_free_minor(struct macvlan_dev *vlan)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment