Commit 2fa532c5 authored by Tejun Heo's avatar Tejun Heo Committed by Linus Torvalds

ppp: convert to idr_alloc()

Convert to the much saner new idr interface.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ec09ebc1
...@@ -2953,46 +2953,21 @@ static void __exit ppp_cleanup(void) ...@@ -2953,46 +2953,21 @@ static void __exit ppp_cleanup(void)
* by holding all_ppp_mutex * by holding all_ppp_mutex
*/ */
static int __unit_alloc(struct idr *p, void *ptr, int n)
{
int unit, err;
again:
if (!idr_pre_get(p, GFP_KERNEL)) {
pr_err("PPP: No free memory for idr\n");
return -ENOMEM;
}
err = idr_get_new_above(p, ptr, n, &unit);
if (err < 0) {
if (err == -EAGAIN)
goto again;
return err;
}
return unit;
}
/* associate pointer with specified number */ /* associate pointer with specified number */
static int unit_set(struct idr *p, void *ptr, int n) static int unit_set(struct idr *p, void *ptr, int n)
{ {
int unit; int unit;
unit = __unit_alloc(p, ptr, n); unit = idr_alloc(p, ptr, n, n + 1, GFP_KERNEL);
if (unit < 0) if (unit == -ENOSPC)
return unit; unit = -EINVAL;
else if (unit != n) {
idr_remove(p, unit);
return -EINVAL;
}
return unit; return unit;
} }
/* get new free unit number and associate pointer with it */ /* get new free unit number and associate pointer with it */
static int unit_get(struct idr *p, void *ptr) static int unit_get(struct idr *p, void *ptr)
{ {
return __unit_alloc(p, ptr, 0); return idr_alloc(p, ptr, 0, 0, GFP_KERNEL);
} }
/* put unit number back to a pool */ /* put unit number back to a pool */
......
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