On Mon, Aug 27, 2018 at 08:44:17AM +0300, Leon Romanovsky wrote: > From: Parav Pandit <parav@xxxxxxxxxxxx> > > Consolidate all error checks under single if() condition and use helper > unlikely() macro for them, in addition drop unneeded goto labels. > > rxe_pool_get_index() already provides RB tree based efficient lookup. > Avoid doing extra checks for error cases which are rare and already > covered by rxe_pool_get_index(). > > Signed-off-by: Parav Pandit <parav@xxxxxxxxxxxx> > Reviewed-by: Daniel Jurgens <danielj@xxxxxxxxxxxx> > Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> > --- > drivers/infiniband/sw/rxe/rxe_mr.c | 35 +++++++++++------------------------ > 1 file changed, 11 insertions(+), 24 deletions(-) > > diff --git a/drivers/infiniband/sw/rxe/rxe_mr.c b/drivers/infiniband/sw/rxe/rxe_mr.c > index dff605fdf60f..9d3916b93f23 100644 > --- a/drivers/infiniband/sw/rxe/rxe_mr.c > +++ b/drivers/infiniband/sw/rxe/rxe_mr.c > @@ -573,33 +573,20 @@ struct rxe_mem *lookup_mem(struct rxe_pd *pd, int access, u32 key, > struct rxe_dev *rxe = to_rdev(pd->ibpd.device); > int index = key >> 8; > > - if (index >= RXE_MIN_MR_INDEX && index <= RXE_MAX_MR_INDEX) { > - mem = rxe_pool_get_index(&rxe->mr_pool, index); > - if (!mem) > - goto err1; > - } else { > - goto err1; > + mem = rxe_pool_get_index(&rxe->mr_pool, index); > + if (!mem) > + return NULL; > + > + if (unlikely((type == lookup_local && mem->lkey != key) || > + (type == lookup_remote && mem->rkey != key) || > + mem->pd != pd || > + (access && !(access & mem->access)) || > + mem->state != RXE_MEM_STATE_VALID)) { > + rxe_drop_ref(mem); > + mem = NULL; > } > > - if ((type == lookup_local && mem->lkey != key) || > - (type == lookup_remote && mem->rkey != key)) > - goto err2; > - > - if (mem->pd != pd) > - goto err2; > - > - if (access && !(access & mem->access)) > - goto err2; > - > - if (mem->state != RXE_MEM_STATE_VALID) > - goto err2; > - > return mem; > - > -err2: > - rxe_drop_ref(mem); > -err1: > - return NULL; > } Not so sure it looks better :) Reviewed-by: Yuval Shaia <yuval.shaia@xxxxxxxxxx> > > int rxe_mem_map_pages(struct rxe_dev *rxe, struct rxe_mem *mem, > -- > 2.14.4 >