Skip to content

Commit f9c47b2

Browse files
DeanLuickjgunthorpe
authored andcommitted
IB/hfi1: Assign npages earlier
Improve code clarity and enable earlier use of tidbuf->npages by moving its assignment to structure creation time. Signed-off-by: Dean Luick <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Link: https://lore.kernel.org/r/167329104884.1472990.4639750192433251493.stgit@awfm-02.cornelisnetworks.com Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent c956940 commit f9c47b2

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

drivers/infiniband/hw/hfi1/user_exp_rcv.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,11 @@ static void unpin_rcv_pages(struct hfi1_filedata *fd,
160160
static int pin_rcv_pages(struct hfi1_filedata *fd, struct tid_user_buf *tidbuf)
161161
{
162162
int pinned;
163-
unsigned int npages;
163+
unsigned int npages = tidbuf->npages;
164164
unsigned long vaddr = tidbuf->vaddr;
165165
struct page **pages = NULL;
166166
struct hfi1_devdata *dd = fd->uctxt->dd;
167167

168-
/* Get the number of pages the user buffer spans */
169-
npages = num_user_pages(vaddr, tidbuf->length);
170-
if (!npages)
171-
return -EINVAL;
172-
173168
if (npages > fd->uctxt->expected_count) {
174169
dd_dev_err(dd, "Expected buffer too big\n");
175170
return -EINVAL;
@@ -196,7 +191,6 @@ static int pin_rcv_pages(struct hfi1_filedata *fd, struct tid_user_buf *tidbuf)
196191
return pinned;
197192
}
198193
tidbuf->pages = pages;
199-
tidbuf->npages = npages;
200194
fd->tid_n_pinned += pinned;
201195
return pinned;
202196
}
@@ -274,6 +268,7 @@ int hfi1_user_exp_rcv_setup(struct hfi1_filedata *fd,
274268
mutex_init(&tidbuf->cover_mutex);
275269
tidbuf->vaddr = tinfo->vaddr;
276270
tidbuf->length = tinfo->length;
271+
tidbuf->npages = num_user_pages(tidbuf->vaddr, tidbuf->length);
277272
tidbuf->psets = kcalloc(uctxt->expected_count, sizeof(*tidbuf->psets),
278273
GFP_KERNEL);
279274
if (!tidbuf->psets) {

0 commit comments

Comments
 (0)