Message ID | 20231009071801.10210-15-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 14/19] RDMA/siw: Simplify siw_mem_id2obj > > We can set mm then return it. > > Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> > --- > drivers/infiniband/sw/siw/siw_mem.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/infiniband/sw/siw/siw_mem.c > b/drivers/infiniband/sw/siw/siw_mem.c > index ac4502fb0a96..2d62f947d330 100644 > --- a/drivers/infiniband/sw/siw/siw_mem.c > +++ b/drivers/infiniband/sw/siw/siw_mem.c > @@ -53,13 +53,11 @@ struct siw_mem *siw_mem_id2obj(struct siw_device *sdev, > int stag_index) > > rcu_read_lock(); > mem = xa_load(&sdev->mem_xa, stag_index); > - if (likely(mem && kref_get_unless_zero(&mem->ref))) { > - rcu_read_unlock(); > - return mem; > - } > + if (likely(mem && !kref_get_unless_zero(&mem->ref))) > + mem = NULL; > rcu_read_unlock(); > > - return NULL; > + return mem; > } > > static void siw_free_plist(struct siw_page_chunk *chunk, int num_pages, > -- > 2.35.3 No let's keep it as is. It openly codes the likely case first. Your code makes the unlikely thing likely.
diff --git a/drivers/infiniband/sw/siw/siw_mem.c b/drivers/infiniband/sw/siw/siw_mem.c index ac4502fb0a96..2d62f947d330 100644 --- a/drivers/infiniband/sw/siw/siw_mem.c +++ b/drivers/infiniband/sw/siw/siw_mem.c @@ -53,13 +53,11 @@ struct siw_mem *siw_mem_id2obj(struct siw_device *sdev, int stag_index) rcu_read_lock(); mem = xa_load(&sdev->mem_xa, stag_index); - if (likely(mem && kref_get_unless_zero(&mem->ref))) { - rcu_read_unlock(); - return mem; - } + if (likely(mem && !kref_get_unless_zero(&mem->ref))) + mem = NULL; rcu_read_unlock(); - return NULL; + return mem; } static void siw_free_plist(struct siw_page_chunk *chunk, int num_pages,
We can set mm then return it. Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> --- drivers/infiniband/sw/siw/siw_mem.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)