Message ID | 20231009071801.10210-10-guoqing.jiang@linux.dev (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Cleanup for siw | expand |
> -----Original Message----- > From: Guoqing Jiang <guoqing.jiang@linux.dev> > Sent: Monday, October 9, 2023 9:18 AM > To: Bernard Metzler <BMT@zurich.ibm.com>; jgg@ziepe.ca; leon@kernel.org > Cc: linux-rdma@vger.kernel.org > Subject: [EXTERNAL] [PATCH 09/19] RDMA/siw: Introduce SIW_STAG_MAX_INDEX > > Add the macro to remove magic number in the code. > > Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> > --- > drivers/infiniband/sw/siw/siw_mem.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/drivers/infiniband/sw/siw/siw_mem.c > b/drivers/infiniband/sw/siw/siw_mem.c > index 92c5776a9eed..ac4502fb0a96 100644 > --- a/drivers/infiniband/sw/siw/siw_mem.c > +++ b/drivers/infiniband/sw/siw/siw_mem.c > @@ -13,18 +13,20 @@ > #include "siw.h" > #include "siw_mem.h" > > +/* Stag lookup is based on its index part only (24 bits). */ > +#define SIW_STAG_MAX_INDEX 0x00ffffff > + > /* > - * Stag lookup is based on its index part only (24 bits). > * The code avoids special Stag of zero and tries to randomize > * STag values between 1 and SIW_STAG_MAX_INDEX. > */ > int siw_mem_add(struct siw_device *sdev, struct siw_mem *m) > { > - struct xa_limit limit = XA_LIMIT(1, 0x00ffffff); > + struct xa_limit limit = XA_LIMIT(1, SIW_STAG_MAX_INDEX); > u32 id, next; > > get_random_bytes(&next, 4); > - next &= 0x00ffffff; > + next &= SIW_STAG_MAX_INDEX; > > if (xa_alloc_cyclic(&sdev->mem_xa, &id, m, limit, &next, > GFP_KERNEL) < 0) > @@ -91,7 +93,7 @@ int siw_mr_add_mem(struct siw_mr *mr, struct ib_pd *pd, > void *mem_obj, > { > struct siw_device *sdev = to_siw_dev(pd->device); > struct siw_mem *mem = kzalloc(sizeof(*mem), GFP_KERNEL); > - struct xa_limit limit = XA_LIMIT(1, 0x00ffffff); > + struct xa_limit limit = XA_LIMIT(1, SIW_STAG_MAX_INDEX); > u32 id, next; > > if (!mem) > @@ -107,7 +109,7 @@ int siw_mr_add_mem(struct siw_mr *mr, struct ib_pd *pd, > void *mem_obj, > kref_init(&mem->ref); > > get_random_bytes(&next, 4); > - next &= 0x00ffffff; > + next &= SIW_STAG_MAX_INDEX; > > if (xa_alloc_cyclic(&sdev->mem_xa, &id, mem, limit, &next, > GFP_KERNEL) < 0) { > -- > 2.35.3 Okay. Acked-by: Bernard Metzler <bmt@zurich.ibm.com>
diff --git a/drivers/infiniband/sw/siw/siw_mem.c b/drivers/infiniband/sw/siw/siw_mem.c index 92c5776a9eed..ac4502fb0a96 100644 --- a/drivers/infiniband/sw/siw/siw_mem.c +++ b/drivers/infiniband/sw/siw/siw_mem.c @@ -13,18 +13,20 @@ #include "siw.h" #include "siw_mem.h" +/* Stag lookup is based on its index part only (24 bits). */ +#define SIW_STAG_MAX_INDEX 0x00ffffff + /* - * Stag lookup is based on its index part only (24 bits). * The code avoids special Stag of zero and tries to randomize * STag values between 1 and SIW_STAG_MAX_INDEX. */ int siw_mem_add(struct siw_device *sdev, struct siw_mem *m) { - struct xa_limit limit = XA_LIMIT(1, 0x00ffffff); + struct xa_limit limit = XA_LIMIT(1, SIW_STAG_MAX_INDEX); u32 id, next; get_random_bytes(&next, 4); - next &= 0x00ffffff; + next &= SIW_STAG_MAX_INDEX; if (xa_alloc_cyclic(&sdev->mem_xa, &id, m, limit, &next, GFP_KERNEL) < 0) @@ -91,7 +93,7 @@ int siw_mr_add_mem(struct siw_mr *mr, struct ib_pd *pd, void *mem_obj, { struct siw_device *sdev = to_siw_dev(pd->device); struct siw_mem *mem = kzalloc(sizeof(*mem), GFP_KERNEL); - struct xa_limit limit = XA_LIMIT(1, 0x00ffffff); + struct xa_limit limit = XA_LIMIT(1, SIW_STAG_MAX_INDEX); u32 id, next; if (!mem) @@ -107,7 +109,7 @@ int siw_mr_add_mem(struct siw_mr *mr, struct ib_pd *pd, void *mem_obj, kref_init(&mem->ref); get_random_bytes(&next, 4); - next &= 0x00ffffff; + next &= SIW_STAG_MAX_INDEX; if (xa_alloc_cyclic(&sdev->mem_xa, &id, mem, limit, &next, GFP_KERNEL) < 0) {
Add the macro to remove magic number in the code. Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> --- drivers/infiniband/sw/siw/siw_mem.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)