.. | .. |
---|
57 | 57 | hns_roce_bitmap_cleanup(&hr_dev->pd_bitmap); |
---|
58 | 58 | } |
---|
59 | 59 | |
---|
60 | | -struct ib_pd *hns_roce_alloc_pd(struct ib_device *ib_dev, |
---|
61 | | - struct ib_ucontext *context, |
---|
62 | | - struct ib_udata *udata) |
---|
| 60 | +int hns_roce_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata) |
---|
63 | 61 | { |
---|
64 | | - struct hns_roce_dev *hr_dev = to_hr_dev(ib_dev); |
---|
65 | | - struct device *dev = hr_dev->dev; |
---|
66 | | - struct hns_roce_pd *pd; |
---|
| 62 | + struct ib_device *ib_dev = ibpd->device; |
---|
| 63 | + struct hns_roce_pd *pd = to_hr_pd(ibpd); |
---|
67 | 64 | int ret; |
---|
68 | | - |
---|
69 | | - pd = kmalloc(sizeof(*pd), GFP_KERNEL); |
---|
70 | | - if (!pd) |
---|
71 | | - return ERR_PTR(-ENOMEM); |
---|
72 | 65 | |
---|
73 | 66 | ret = hns_roce_pd_alloc(to_hr_dev(ib_dev), &pd->pdn); |
---|
74 | 67 | if (ret) { |
---|
75 | | - kfree(pd); |
---|
76 | | - dev_err(dev, "[alloc_pd]hns_roce_pd_alloc failed!\n"); |
---|
77 | | - return ERR_PTR(ret); |
---|
| 68 | + ibdev_err(ib_dev, "failed to alloc pd, ret = %d.\n", ret); |
---|
| 69 | + return ret; |
---|
78 | 70 | } |
---|
79 | 71 | |
---|
80 | | - if (context) { |
---|
81 | | - struct hns_roce_ib_alloc_pd_resp uresp = {.pdn = pd->pdn}; |
---|
| 72 | + if (udata) { |
---|
| 73 | + struct hns_roce_ib_alloc_pd_resp resp = {.pdn = pd->pdn}; |
---|
82 | 74 | |
---|
83 | | - if (ib_copy_to_udata(udata, &uresp, sizeof(uresp))) { |
---|
| 75 | + ret = ib_copy_to_udata(udata, &resp, |
---|
| 76 | + min(udata->outlen, sizeof(resp))); |
---|
| 77 | + if (ret) { |
---|
84 | 78 | hns_roce_pd_free(to_hr_dev(ib_dev), pd->pdn); |
---|
85 | | - dev_err(dev, "[alloc_pd]ib_copy_to_udata failed!\n"); |
---|
86 | | - kfree(pd); |
---|
87 | | - return ERR_PTR(-EFAULT); |
---|
| 79 | + ibdev_err(ib_dev, "failed to copy to udata, ret = %d\n", ret); |
---|
88 | 80 | } |
---|
89 | 81 | } |
---|
90 | 82 | |
---|
91 | | - return &pd->ibpd; |
---|
| 83 | + return ret; |
---|
92 | 84 | } |
---|
93 | | -EXPORT_SYMBOL_GPL(hns_roce_alloc_pd); |
---|
94 | 85 | |
---|
95 | | -int hns_roce_dealloc_pd(struct ib_pd *pd) |
---|
| 86 | +int hns_roce_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata) |
---|
96 | 87 | { |
---|
97 | 88 | hns_roce_pd_free(to_hr_dev(pd->device), to_hr_pd(pd)->pdn); |
---|
98 | | - kfree(to_hr_pd(pd)); |
---|
99 | | - |
---|
100 | 89 | return 0; |
---|
101 | 90 | } |
---|
102 | | -EXPORT_SYMBOL_GPL(hns_roce_dealloc_pd); |
---|
103 | 91 | |
---|
104 | 92 | int hns_roce_uar_alloc(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar) |
---|
105 | 93 | { |
---|
106 | 94 | struct resource *res; |
---|
107 | | - int ret = 0; |
---|
| 95 | + int ret; |
---|
108 | 96 | |
---|
109 | 97 | /* Using bitmap to manager UAR index */ |
---|
110 | 98 | ret = hns_roce_bitmap_alloc(&hr_dev->uar_table.bitmap, &uar->logic_idx); |
---|
111 | | - if (ret == -1) |
---|
| 99 | + if (ret) |
---|
112 | 100 | return -ENOMEM; |
---|
113 | 101 | |
---|
114 | 102 | if (uar->logic_idx > 0 && hr_dev->caps.phy_num_uars > 1) |
---|