Commit e3649293 authored by Joe Perches's avatar Joe Perches Committed by Jason Gunthorpe

IB/qib: Cleanup qib_set_part_key() with direct returns

Perhaps the function is better written without
the empty bail: label and without setting ret
and just using return.

Combining the int/bool conversion of any and the
direct returns makes the resulting code clearer.
Tested-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 3365776e
...@@ -568,20 +568,16 @@ static int qib_tid_free(struct qib_ctxtdata *rcd, unsigned subctxt, ...@@ -568,20 +568,16 @@ static int qib_tid_free(struct qib_ctxtdata *rcd, unsigned subctxt,
static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key)
{ {
struct qib_pportdata *ppd = rcd->ppd; struct qib_pportdata *ppd = rcd->ppd;
int i, any = 0, pidx = -1; int i, pidx = -1;
bool any = false;
u16 lkey = key & 0x7FFF; u16 lkey = key & 0x7FFF;
int ret;
if (lkey == (QIB_DEFAULT_P_KEY & 0x7FFF)) { if (lkey == (QIB_DEFAULT_P_KEY & 0x7FFF))
/* nothing to do; this key always valid */ /* nothing to do; this key always valid */
ret = 0; return 0;
goto bail;
}
if (!lkey) { if (!lkey)
ret = -EINVAL; return -EINVAL;
goto bail;
}
/* /*
* Set the full membership bit, because it has to be * Set the full membership bit, because it has to be
...@@ -594,18 +590,14 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) ...@@ -594,18 +590,14 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key)
for (i = 0; i < ARRAY_SIZE(rcd->pkeys); i++) { for (i = 0; i < ARRAY_SIZE(rcd->pkeys); i++) {
if (!rcd->pkeys[i] && pidx == -1) if (!rcd->pkeys[i] && pidx == -1)
pidx = i; pidx = i;
if (rcd->pkeys[i] == key) { if (rcd->pkeys[i] == key)
ret = -EEXIST; return -EEXIST;
goto bail;
}
} }
if (pidx == -1) { if (pidx == -1)
ret = -EBUSY; return -EBUSY;
goto bail; for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
}
for (any = i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
if (!ppd->pkeys[i]) { if (!ppd->pkeys[i]) {
any++; any = true;
continue; continue;
} }
if (ppd->pkeys[i] == key) { if (ppd->pkeys[i] == key) {
...@@ -613,44 +605,34 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key) ...@@ -613,44 +605,34 @@ static int qib_set_part_key(struct qib_ctxtdata *rcd, u16 key)
if (atomic_inc_return(pkrefs) > 1) { if (atomic_inc_return(pkrefs) > 1) {
rcd->pkeys[pidx] = key; rcd->pkeys[pidx] = key;
ret = 0; return 0;
goto bail;
} else {
/*
* lost race, decrement count, catch below
*/
atomic_dec(pkrefs);
any++;
} }
/*
* lost race, decrement count, catch below
*/
atomic_dec(pkrefs);
any = true;
} }
if ((ppd->pkeys[i] & 0x7FFF) == lkey) { if ((ppd->pkeys[i] & 0x7FFF) == lkey)
/* /*
* It makes no sense to have both the limited and * It makes no sense to have both the limited and
* full membership PKEY set at the same time since * full membership PKEY set at the same time since
* the unlimited one will disable the limited one. * the unlimited one will disable the limited one.
*/ */
ret = -EEXIST; return -EEXIST;
goto bail;
}
}
if (!any) {
ret = -EBUSY;
goto bail;
} }
if (!any)
return -EBUSY;
for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) { for (i = 0; i < ARRAY_SIZE(ppd->pkeys); i++) {
if (!ppd->pkeys[i] && if (!ppd->pkeys[i] &&
atomic_inc_return(&ppd->pkeyrefs[i]) == 1) { atomic_inc_return(&ppd->pkeyrefs[i]) == 1) {
rcd->pkeys[pidx] = key; rcd->pkeys[pidx] = key;
ppd->pkeys[i] = key; ppd->pkeys[i] = key;
(void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0); (void) ppd->dd->f_set_ib_cfg(ppd, QIB_IB_CFG_PKEYS, 0);
ret = 0; return 0;
goto bail;
} }
} }
ret = -EBUSY; return -EBUSY;
bail:
return ret;
} }
/** /**
......
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