diff options
author | Roland Dreier <rolandd@cisco.com> | 2006-06-17 23:37:40 -0400 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2006-06-17 23:37:40 -0400 |
commit | 3463175d6ee55fdbd5cda2a03415e2068599b2b7 (patch) | |
tree | f629b7c65894d591d861bb121a71f67d0b960f36 /drivers/infiniband | |
parent | 92b1582268e269b3a9e54e186e740396f0f2012b (diff) |
IB/uverbs: Factor out common idr code
Factor out common code for adding a userspace object to an idr into a
function idr_add_uobj(). This shrinks both the source and object code:
add/remove: 1/0 grow/shrink: 0/6 up/down: 57/-220 (-163)
function old new delta
idr_add_uobj - 57 +57
ib_uverbs_create_ah 543 512 -31
ib_uverbs_create_srq 662 630 -32
ib_uverbs_reg_mr 737 699 -38
ib_uverbs_create_cq 639 600 -39
ib_uverbs_alloc_pd 485 446 -39
ib_uverbs_create_qp 1020 979 -41
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband')
-rw-r--r-- | drivers/infiniband/core/uverbs_cmd.c | 82 |
1 files changed, 22 insertions, 60 deletions
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 37824f68e377..403dd811ec7f 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c | |||
@@ -50,6 +50,22 @@ | |||
50 | (udata)->outlen = (olen); \ | 50 | (udata)->outlen = (olen); \ |
51 | } while (0) | 51 | } while (0) |
52 | 52 | ||
53 | static int idr_add_uobj(struct idr *idr, void *obj, struct ib_uobject *uobj) | ||
54 | { | ||
55 | int ret; | ||
56 | |||
57 | retry: | ||
58 | if (!idr_pre_get(idr, GFP_KERNEL)) | ||
59 | return -ENOMEM; | ||
60 | |||
61 | ret = idr_get_new(idr, uobj, &uobj->id); | ||
62 | |||
63 | if (ret == -EAGAIN) | ||
64 | goto retry; | ||
65 | |||
66 | return ret; | ||
67 | } | ||
68 | |||
53 | ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, | 69 | ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file, |
54 | const char __user *buf, | 70 | const char __user *buf, |
55 | int in_len, int out_len) | 71 | int in_len, int out_len) |
@@ -295,16 +311,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, | |||
295 | 311 | ||
296 | mutex_lock(&ib_uverbs_idr_mutex); | 312 | mutex_lock(&ib_uverbs_idr_mutex); |
297 | 313 | ||
298 | retry: | 314 | ret = idr_add_uobj(&ib_uverbs_pd_idr, pd, uobj); |
299 | if (!idr_pre_get(&ib_uverbs_pd_idr, GFP_KERNEL)) { | ||
300 | ret = -ENOMEM; | ||
301 | goto err_up; | ||
302 | } | ||
303 | |||
304 | ret = idr_get_new(&ib_uverbs_pd_idr, pd, &uobj->id); | ||
305 | |||
306 | if (ret == -EAGAIN) | ||
307 | goto retry; | ||
308 | if (ret) | 315 | if (ret) |
309 | goto err_up; | 316 | goto err_up; |
310 | 317 | ||
@@ -458,16 +465,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, | |||
458 | resp.lkey = mr->lkey; | 465 | resp.lkey = mr->lkey; |
459 | resp.rkey = mr->rkey; | 466 | resp.rkey = mr->rkey; |
460 | 467 | ||
461 | retry: | 468 | ret = idr_add_uobj(&ib_uverbs_mr_idr, mr, &obj->uobject); |
462 | if (!idr_pre_get(&ib_uverbs_mr_idr, GFP_KERNEL)) { | ||
463 | ret = -ENOMEM; | ||
464 | goto err_unreg; | ||
465 | } | ||
466 | |||
467 | ret = idr_get_new(&ib_uverbs_mr_idr, mr, &obj->uobject.id); | ||
468 | |||
469 | if (ret == -EAGAIN) | ||
470 | goto retry; | ||
471 | if (ret) | 469 | if (ret) |
472 | goto err_unreg; | 470 | goto err_unreg; |
473 | 471 | ||
@@ -632,16 +630,7 @@ ssize_t ib_uverbs_create_cq(struct ib_uverbs_file *file, | |||
632 | 630 | ||
633 | mutex_lock(&ib_uverbs_idr_mutex); | 631 | mutex_lock(&ib_uverbs_idr_mutex); |
634 | 632 | ||
635 | retry: | 633 | ret = idr_add_uobj(&ib_uverbs_cq_idr, cq, &uobj->uobject); |
636 | if (!idr_pre_get(&ib_uverbs_cq_idr, GFP_KERNEL)) { | ||
637 | ret = -ENOMEM; | ||
638 | goto err_up; | ||
639 | } | ||
640 | |||
641 | ret = idr_get_new(&ib_uverbs_cq_idr, cq, &uobj->uobject.id); | ||
642 | |||
643 | if (ret == -EAGAIN) | ||
644 | goto retry; | ||
645 | if (ret) | 634 | if (ret) |
646 | goto err_up; | 635 | goto err_up; |
647 | 636 | ||
@@ -946,16 +935,7 @@ ssize_t ib_uverbs_create_qp(struct ib_uverbs_file *file, | |||
946 | memset(&resp, 0, sizeof resp); | 935 | memset(&resp, 0, sizeof resp); |
947 | resp.qpn = qp->qp_num; | 936 | resp.qpn = qp->qp_num; |
948 | 937 | ||
949 | retry: | 938 | ret = idr_add_uobj(&ib_uverbs_qp_idr, qp, &uobj->uevent.uobject); |
950 | if (!idr_pre_get(&ib_uverbs_qp_idr, GFP_KERNEL)) { | ||
951 | ret = -ENOMEM; | ||
952 | goto err_destroy; | ||
953 | } | ||
954 | |||
955 | ret = idr_get_new(&ib_uverbs_qp_idr, qp, &uobj->uevent.uobject.id); | ||
956 | |||
957 | if (ret == -EAGAIN) | ||
958 | goto retry; | ||
959 | if (ret) | 939 | if (ret) |
960 | goto err_destroy; | 940 | goto err_destroy; |
961 | 941 | ||
@@ -1614,16 +1594,7 @@ ssize_t ib_uverbs_create_ah(struct ib_uverbs_file *file, | |||
1614 | 1594 | ||
1615 | ah->uobject = uobj; | 1595 | ah->uobject = uobj; |
1616 | 1596 | ||
1617 | retry: | 1597 | ret = idr_add_uobj(&ib_uverbs_ah_idr, ah, uobj); |
1618 | if (!idr_pre_get(&ib_uverbs_ah_idr, GFP_KERNEL)) { | ||
1619 | ret = -ENOMEM; | ||
1620 | goto err_destroy; | ||
1621 | } | ||
1622 | |||
1623 | ret = idr_get_new(&ib_uverbs_ah_idr, ah, &uobj->id); | ||
1624 | |||
1625 | if (ret == -EAGAIN) | ||
1626 | goto retry; | ||
1627 | if (ret) | 1598 | if (ret) |
1628 | goto err_destroy; | 1599 | goto err_destroy; |
1629 | 1600 | ||
@@ -1846,16 +1817,7 @@ ssize_t ib_uverbs_create_srq(struct ib_uverbs_file *file, | |||
1846 | 1817 | ||
1847 | memset(&resp, 0, sizeof resp); | 1818 | memset(&resp, 0, sizeof resp); |
1848 | 1819 | ||
1849 | retry: | 1820 | ret = idr_add_uobj(&ib_uverbs_srq_idr, srq, &uobj->uobject); |
1850 | if (!idr_pre_get(&ib_uverbs_srq_idr, GFP_KERNEL)) { | ||
1851 | ret = -ENOMEM; | ||
1852 | goto err_destroy; | ||
1853 | } | ||
1854 | |||
1855 | ret = idr_get_new(&ib_uverbs_srq_idr, srq, &uobj->uobject.id); | ||
1856 | |||
1857 | if (ret == -EAGAIN) | ||
1858 | goto retry; | ||
1859 | if (ret) | 1821 | if (ret) |
1860 | goto err_destroy; | 1822 | goto err_destroy; |
1861 | 1823 | ||