diff mbox series

[for-next,03/11] RDMA/hns: Check return value of kmalloc with macro

Message ID 1584624298-23841-4-git-send-email-liweihang@huawei.com (mailing list archive)
State Superseded
Headers show
Series RDMA/hns: Various cleanups | expand

Commit Message

Weihang Li March 19, 2020, 1:24 p.m. UTC
From: Yixian Liu <liuyixian@huawei.com>

As the return value of kmalloc may be null or error code, use kernel macro
to do return value check.

Signed-off-by: Yixian Liu <liuyixian@huawei.com>
Signed-off-by: Weihang Li <liweihang@huawei.com>
---
 drivers/infiniband/hw/hns/hns_roce_cmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jason Gunthorpe March 19, 2020, 6:18 p.m. UTC | #1
On Thu, Mar 19, 2020 at 09:24:50PM +0800, Weihang Li wrote:
> From: Yixian Liu <liuyixian@huawei.com>
> 
> As the return value of kmalloc may be null or error code, use kernel macro
> to do return value check.

kmalloc always returns null, do not use IS_ERR_OR_NULL

Jason
Weihang Li March 20, 2020, 1:44 a.m. UTC | #2
On 2020/3/20 2:18, Jason Gunthorpe wrote:
> On Thu, Mar 19, 2020 at 09:24:50PM +0800, Weihang Li wrote:
>> From: Yixian Liu <liuyixian@huawei.com>
>>
>> As the return value of kmalloc may be null or error code, use kernel macro
>> to do return value check.
> 
> kmalloc always returns null, do not use IS_ERR_OR_NULL
> 
> Jason
> 

OK, will drop this one in v2.

Thank you
Weihang
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/hns/hns_roce_cmd.c b/drivers/infiniband/hw/hns/hns_roce_cmd.c
index 455d533..d52311a 100644
--- a/drivers/infiniband/hw/hns/hns_roce_cmd.c
+++ b/drivers/infiniband/hw/hns/hns_roce_cmd.c
@@ -268,7 +268,7 @@  struct hns_roce_cmd_mailbox
 	struct hns_roce_cmd_mailbox *mailbox;
 
 	mailbox = kmalloc(sizeof(*mailbox), GFP_KERNEL);
-	if (!mailbox)
+	if (IS_ERR_OR_NULL(mailbox))
 		return ERR_PTR(-ENOMEM);
 
 	mailbox->buf = dma_pool_alloc(hr_dev->cmd.pool, GFP_KERNEL,