From: Leon Romanovsky <leon@kernel.org>
To: SF Markus Elfring <elfring@users.sourceforge.net>
Cc: Devesh Sharma <devesh.sharma@avagotech.com>,
Doug Ledford <dledford@redhat.com>,
Hal Rosenstock <hal.rosenstock@gmail.com>,
Sean Hefty <sean.hefty@intel.com>,
Selvin Xavier <selvin.xavier@avagotech.com>,
Yuval Shaia <yuval.shaia@oracle.com>,
linux-rdma@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH v2 07/12] IB/ocrdma: Adjust 21 checks for null pointers
Date: Sun, 23 Apr 2017 09:07:19 +0300 [thread overview]
Message-ID: <20170423060719.GZ14088@mtr-leonro.local> (raw)
In-Reply-To: <3ec5ffa4-8976-e793-f22c-5f01c9d6bb9d@users.sourceforge.net>
[-- Attachment #1: Type: text/plain, Size: 7922 bytes --]
On Sat, Apr 22, 2017 at 04:47:19PM +0200, SF Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Sat, 22 Apr 2017 14:20:37 +0200
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> The script “checkpatch.pl” pointed information out like the following.
>
> Comparison to NULL could be written !…
>
> Thus fix affected source code places.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>
> v2:
> Changes were rebased on source files from Linux next-20170421.
> These were recombined as requested by Doug Ledford.
>
> drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 20 ++++++++++----------
> drivers/infiniband/hw/ocrdma/ocrdma_main.c | 2 +-
> drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 20 ++++++++++----------
> 3 files changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
> index d5b988b011d1..8c7f0b108a7f 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c
> @@ -665,7 +665,7 @@ static void ocrdma_process_qpcat_error(struct ocrdma_dev *dev,
> enum ib_qp_state new_ib_qps = IB_QPS_ERR;
> enum ib_qp_state old_ib_qps;
>
> - if (qp == NULL)
> + if (!qp)
> BUG();
There is a need to get rid of BUG() in driver code.
> ocrdma_qp_state_change(qp, new_ib_qps, &old_ib_qps);
> }
> @@ -693,7 +693,7 @@ static void ocrdma_dispatch_ibevent(struct ocrdma_dev *dev,
> if (cqe->qpvalid_qpid & OCRDMA_AE_MCQE_QPVALID) {
> if (qpid < dev->attr.max_qp)
> qp = dev->qp_tbl[qpid];
> - if (qp == NULL) {
> + if (!qp) {
> pr_err("ocrdma%d:Async event - qpid %u is not valid\n",
> dev->id, qpid);
> return;
> @@ -703,7 +703,7 @@ static void ocrdma_dispatch_ibevent(struct ocrdma_dev *dev,
> if (cqe->cqvalid_cqid & OCRDMA_AE_MCQE_CQVALID) {
> if (cqid < dev->attr.max_cq)
> cq = dev->cq_tbl[cqid];
> - if (cq == NULL) {
> + if (!cq) {
> pr_err("ocrdma%d:Async event - cqid %u is not valid\n",
> dev->id, cqid);
> return;
> @@ -882,7 +882,7 @@ static int ocrdma_mq_cq_handler(struct ocrdma_dev *dev, u16 cq_id)
>
> while (1) {
> cqe = ocrdma_get_mcqe(dev);
> - if (cqe == NULL)
> + if (!cqe)
> break;
> ocrdma_le32_to_cpu(cqe, sizeof(*cqe));
> cqe_popped += 1;
> @@ -948,7 +948,7 @@ static void ocrdma_qp_buddy_cq_handler(struct ocrdma_dev *dev,
> * false - Check for RQ CQ
> */
> bcq = _ocrdma_qp_buddy_cq_handler(dev, cq, true);
> - if (bcq == NULL)
> + if (!bcq)
> bcq = _ocrdma_qp_buddy_cq_handler(dev, cq, false);
> spin_unlock_irqrestore(&dev->flush_q_lock, flags);
>
> @@ -969,7 +969,7 @@ static void ocrdma_qp_cq_handler(struct ocrdma_dev *dev, u16 cq_idx)
> BUG();
>
> cq = dev->cq_tbl[cq_idx];
> - if (cq == NULL)
> + if (!cq)
> return;
>
> if (cq->ibcq.comp_handler) {
> @@ -1289,7 +1289,7 @@ int ocrdma_mbx_rdma_stats(struct ocrdma_dev *dev, bool reset)
> int status;
>
> old_stats = kmalloc(sizeof(*old_stats), GFP_KERNEL);
> - if (old_stats == NULL)
> + if (!old_stats)
> return -ENOMEM;
>
> memset(mqe, 0, sizeof(*mqe));
> @@ -1676,12 +1676,12 @@ static int ocrdma_mbx_create_ah_tbl(struct ocrdma_dev *dev)
> dev->av_tbl.pbl.va = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
> &dev->av_tbl.pbl.pa,
> GFP_KERNEL);
> - if (dev->av_tbl.pbl.va == NULL)
> + if (!dev->av_tbl.pbl.va)
> goto mem_err;
>
> dev->av_tbl.va = dma_alloc_coherent(&pdev->dev, dev->av_tbl.size,
> &pa, GFP_KERNEL);
> - if (dev->av_tbl.va == NULL)
> + if (!dev->av_tbl.va)
> goto mem_err_ah;
> dev->av_tbl.pa = pa;
> dev->av_tbl.num_ah = max_ah;
> @@ -1722,7 +1722,7 @@ static void ocrdma_mbx_delete_ah_tbl(struct ocrdma_dev *dev)
> struct ocrdma_delete_ah_tbl *cmd;
> struct pci_dev *pdev = dev->nic_info.pdev;
>
> - if (dev->av_tbl.va == NULL)
> + if (!dev->av_tbl.va)
> return;
>
> cmd = ocrdma_init_emb_mqe(OCRDMA_CMD_DELETE_AH_TBL, sizeof(*cmd));
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> index e2aa67d6cbb8..b82f6c6942e0 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c
> @@ -238,7 +238,7 @@ static int ocrdma_alloc_resources(struct ocrdma_dev *dev)
>
> dev->stag_arr = kcalloc(OCRDMA_MAX_STAG, sizeof(*dev->stag_arr),
> GFP_KERNEL);
> - if (dev->stag_arr == NULL)
> + if (!dev->stag_arr)
> goto alloc_err;
>
> ocrdma_alloc_pd_pool(dev);
> diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> index 5eaf946aeac6..c804889db7e1 100644
> --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c
> @@ -267,7 +267,7 @@ static int ocrdma_add_mmap(struct ocrdma_ucontext *uctx, u64 phy_addr,
> struct ocrdma_mm *mm;
>
> mm = kzalloc(sizeof(*mm), GFP_KERNEL);
> - if (mm == NULL)
> + if (!mm)
> return -ENOMEM;
> mm->key.phy_addr = phy_addr;
> mm->key.len = len;
> @@ -1194,7 +1194,7 @@ static int ocrdma_add_qpn_map(struct ocrdma_dev *dev, struct ocrdma_qp *qp)
> {
> int status = -EINVAL;
>
> - if (qp->id < OCRDMA_MAX_QP && dev->qp_tbl[qp->id] == NULL) {
> + if (qp->id < OCRDMA_MAX_QP && !dev->qp_tbl[qp->id]) {
> dev->qp_tbl[qp->id] = qp;
> status = 0;
> }
> @@ -1362,11 +1362,11 @@ static int ocrdma_alloc_wr_id_tbl(struct ocrdma_qp *qp)
> {
> qp->wqe_wr_id_tbl = kcalloc(qp->sq.max_cnt, sizeof(*qp->wqe_wr_id_tbl),
> GFP_KERNEL);
> - if (qp->wqe_wr_id_tbl == NULL)
> + if (!qp->wqe_wr_id_tbl)
> return -ENOMEM;
> qp->rqe_wr_id_tbl = kcalloc(qp->rq.max_cnt, sizeof(*qp->rqe_wr_id_tbl),
> GFP_KERNEL);
> - if (qp->rqe_wr_id_tbl == NULL)
> + if (!qp->rqe_wr_id_tbl)
> return -ENOMEM;
Memory leak here, need to free qp->wqe_wr_id_tb here.
>
> return 0;
> @@ -1426,7 +1426,7 @@ struct ib_qp *ocrdma_create_qp(struct ib_pd *ibpd,
> goto gen_err;
> }
> ocrdma_set_qp_init_params(qp, pd, attrs);
> - if (udata == NULL)
> + if (!udata)
> qp->cap_flags |= (OCRDMA_QP_MW_BIND | OCRDMA_QP_LKEY0 |
> OCRDMA_QP_FAST_REG);
>
> @@ -1438,7 +1438,7 @@ struct ib_qp *ocrdma_create_qp(struct ib_pd *ibpd,
> goto mbx_err;
>
> /* user space QP's wr_id table are managed in library */
> - if (udata == NULL) {
> + if (!udata) {
> status = ocrdma_alloc_wr_id_tbl(qp);
> if (status)
> goto map_err;
> @@ -1899,11 +1899,11 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd,
> if (status)
> goto err;
>
> - if (udata == NULL) {
> + if (!udata) {
> srq->rqe_wr_id_tbl = kcalloc(srq->rq.max_cnt,
> sizeof(*srq->rqe_wr_id_tbl),
> GFP_KERNEL);
> - if (srq->rqe_wr_id_tbl == NULL)
> + if (!srq->rqe_wr_id_tbl)
> goto arm_err;
>
> srq->bit_fields_len = (srq->rq.max_cnt / 32) +
> @@ -1911,7 +1911,7 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd,
> srq->idx_bit_fields = kmalloc_array(srq->bit_fields_len,
> sizeof(*srq->idx_bit_fields),
> GFP_KERNEL);
> - if (srq->idx_bit_fields == NULL)
> + if (!srq->idx_bit_fields)
> goto arm_err;
> memset(srq->idx_bit_fields, 0xff,
> srq->bit_fields_len * sizeof(*srq->idx_bit_fields));
> @@ -2885,7 +2885,7 @@ static int ocrdma_poll_hwcq(struct ocrdma_cq *cq, int num_entries,
> if (qpn == 0)
> goto skip_cqe;
> qp = dev->qp_tbl[qpn];
> - BUG_ON(qp == NULL);
> + BUG_ON(!qp);
Again, bug in driver can crash whole system. There is a need to get rid
of it.
>
> expand = is_cqe_for_sq(cqe)
> ? ocrdma_poll_scqe(qp, cqe, ibwc, &polled, &stop)
> --
> 2.12.2
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-04-23 6:07 UTC|newest]
Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <fc421509-4069-da8a-b308-60b49ea91ada@users.sourceforge.net>
2017-03-08 12:36 ` [PATCH 01/26] IB/ocrdma: Use kcalloc() in ocrdma_create_eqs() SF Markus Elfring
2017-03-08 12:41 ` [PATCH 02/26] IB/ocrdma: Use kcalloc() in ocrdma_mbx_alloc_pd_range() SF Markus Elfring
2017-03-08 14:03 ` Yuval Shaia
2017-04-20 20:40 ` Doug Ledford
2017-03-08 12:45 ` [PATCH 03/26] IB/ocrdma: Improve size determinations in ocrdma_mbx_get_dcbx_config() SF Markus Elfring
2017-03-08 13:54 ` Yuval Shaia
2017-03-08 14:46 ` Devesh Sharma
2017-03-08 12:48 ` [PATCH 04/26] IB/ocrdma: Delete unnecessary variable initialisations " SF Markus Elfring
2017-03-08 14:06 ` Yuval Shaia
2017-03-08 12:50 ` [PATCH 05/26] IB/ocrdma: Improve another size determination in ocrdma_mbx_query_qp() SF Markus Elfring
2017-03-08 14:07 ` Yuval Shaia
2017-03-08 12:53 ` [PATCH 06/26] IB/ocrdma: Improve another size determination in ocrdma_alloc_pd_pool() SF Markus Elfring
2017-03-08 12:55 ` [PATCH 07/26] IB/ocrdma: Improve another size determination in ocrdma_mbx_get_ctrl_attribs() SF Markus Elfring
2017-03-08 14:08 ` Yuval Shaia
2017-03-08 12:58 ` [PATCH 08/26] IB/ocrdma: Improve size determinations in ocrdma_mbx_rdma_stats() SF Markus Elfring
2017-03-08 14:20 ` Yuval Shaia
2017-03-08 13:00 ` [PATCH 09/26] IB/ocrdma: Improve another size determination in ocrdma_mq_cq_handler() SF Markus Elfring
2017-03-08 14:22 ` Yuval Shaia
2017-03-08 13:02 ` [PATCH 10/26] IB/ocrdma: Improve another size determination in ocrdma_init_emb_mqe() SF Markus Elfring
2017-03-08 14:22 ` Yuval Shaia
2017-03-08 14:42 ` Devesh Sharma
2017-03-08 13:04 ` [PATCH 11/26] IB/ocrdma: Delete unnecessary braces SF Markus Elfring
2017-03-08 14:24 ` Yuval Shaia
2017-03-08 14:59 ` Devesh Sharma
2017-03-08 13:07 ` [PATCH 12/26] IB/ocrdma: Adjust ten checks for null pointers SF Markus Elfring
2017-03-08 14:27 ` Yuval Shaia
2017-03-08 13:09 ` [PATCH 13/26] IB/ocrdma: Use kcalloc() in ocrdma_alloc_resources() SF Markus Elfring
2017-03-08 13:10 ` [PATCH 14/26] IB/ocrdma: Improve another size determination in ocrdma_add() SF Markus Elfring
2017-03-08 14:27 ` Yuval Shaia
2017-03-08 13:13 ` [PATCH 15/26] IB/ocrdma: Delete an error message for a failed memory allocation " SF Markus Elfring
2017-03-08 15:03 ` Devesh Sharma
2017-03-08 15:26 ` Yuval Shaia
2017-03-08 13:15 ` [PATCH 16/26] IB/ocrdma: Adjust a null pointer check in ocrdma_alloc_resources() SF Markus Elfring
2017-03-08 15:03 ` Devesh Sharma
2017-03-09 11:42 ` Yuval Shaia
2017-03-08 13:17 ` [PATCH 17/26] IB/ocrdma: Use kmalloc_array() in ocrdma_create_srq() SF Markus Elfring
2017-03-08 15:05 ` Devesh Sharma
2017-03-08 13:19 ` [PATCH 18/26] IB/ocrdma: Use kcalloc() in three functions SF Markus Elfring
2017-03-08 15:10 ` Devesh Sharma
2017-03-08 13:20 ` [PATCH 19/26] IB/ocrdma: Improve another size determination in ocrdma_alloc_mr() SF Markus Elfring
2017-03-08 15:07 ` Devesh Sharma
2017-03-09 12:03 ` Yuval Shaia
2017-03-08 13:22 ` [PATCH 20/26] IB/ocrdma: Delete an unnecessary variable assignment " SF Markus Elfring
2017-03-08 15:13 ` Devesh Sharma
2017-03-09 11:59 ` Yuval Shaia
2017-03-08 13:24 ` [PATCH 21/26] IB/ocrdma: Improve another size determination in ocrdma_create_srq() SF Markus Elfring
2017-03-08 15:15 ` Devesh Sharma
2017-03-09 11:46 ` Yuval Shaia
2017-03-08 13:26 ` [PATCH 22/26] IB/ocrdma: Returning only value constants in ocrdma_resize_cq() SF Markus Elfring
2017-03-08 15:16 ` Devesh Sharma
2017-03-09 12:01 ` Yuval Shaia
2017-03-08 13:28 ` [PATCH 23/26] IB/ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd() SF Markus Elfring
2017-03-08 15:16 ` Devesh Sharma
2017-03-09 11:57 ` Yuval Shaia
2017-03-08 13:30 ` [PATCH 24/26] IB/ocrdma: One jump label less in ocrdma_alloc_ucontext_pd() SF Markus Elfring
2017-03-08 15:17 ` Devesh Sharma
2017-03-09 11:55 ` Yuval Shaia
2017-03-08 13:32 ` [PATCH 25/26] IB/ocrdma: Delete unnecessary braces SF Markus Elfring
2017-03-09 11:50 ` Yuval Shaia
2017-03-08 13:34 ` [PATCH 26/26] IB/ocrdma: Adjust further ten checks for null pointers SF Markus Elfring
2017-03-08 15:18 ` Devesh Sharma
2017-03-09 11:43 ` Yuval Shaia
[not found] ` <1492720999.3041.18.camel@redhat.com>
2017-04-22 14:26 ` [PATCH v2 00/12] InfiniBand-OCRDMA: Fine-tuning for several function implementations SF Markus Elfring
2017-04-22 14:30 ` [PATCH v2 01/12] IB/ocrdma: Use kcalloc() in ocrdma_mbx_alloc_pd_range() SF Markus Elfring
2017-04-24 16:27 ` Devesh Sharma
2017-04-25 17:02 ` Doug Ledford
2017-08-08 17:26 ` [v2 " SF Markus Elfring
2017-08-09 6:43 ` Leon Romanovsky
2017-04-22 14:33 ` [PATCH v2 02/12] IB/ocrdma: Use kcalloc() in five functions SF Markus Elfring
2017-04-22 14:36 ` [PATCH v2 03/12] IB/ocrdma: Improve size determinations in ten functions SF Markus Elfring
2017-04-23 7:33 ` Leon Romanovsky
2017-04-24 12:54 ` Dennis Dalessandro
2017-04-24 13:23 ` SF Markus Elfring
2017-04-24 14:33 ` Leon Romanovsky
2017-04-24 14:54 ` SF Markus Elfring
2017-04-24 16:38 ` [PATCH v2 03/12] " Doug Ledford
2017-04-24 18:02 ` Leon Romanovsky
2017-04-24 16:38 ` Doug Ledford
2017-04-22 14:40 ` [PATCH v2 04/12] IB/ocrdma: Delete unnecessary variable initialisations in ocrdma_mbx_get_dcbx_config() SF Markus Elfring
2017-04-22 14:43 ` [PATCH v2 05/12] IB/ocrdma: Delete unnecessary braces SF Markus Elfring
2017-04-22 14:45 ` [PATCH v2 06/12] IB/ocrdma: Use kmalloc_array() in ocrdma_create_srq() SF Markus Elfring
2017-04-22 14:47 ` [PATCH v2 07/12] IB/ocrdma: Adjust 21 checks for null pointers SF Markus Elfring
2017-04-23 6:07 ` Leon Romanovsky [this message]
2017-04-22 14:48 ` [PATCH v2 08/12] IB/ocrdma: Delete an error message for a failed memory allocation in ocrdma_add() SF Markus Elfring
2017-04-22 14:49 ` [PATCH v2 09/12] IB/ocrdma: Delete an unnecessary variable assignment in ocrdma_alloc_mr() SF Markus Elfring
2017-04-22 14:50 ` [PATCH v2 10/12] IB/ocrdma: Returning only value constants in ocrdma_resize_cq() SF Markus Elfring
2017-04-22 14:51 ` [PATCH v2 11/12] IB/ocrdma: Delete an unnecessary variable in ocrdma_dealloc_pd() SF Markus Elfring
2017-04-22 14:54 ` [PATCH v2 12/12] IB/ocrdma: One jump label less in ocrdma_alloc_ucontext_pd() SF Markus Elfring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170423060719.GZ14088@mtr-leonro.local \
--to=leon@kernel.org \
--cc=devesh.sharma@avagotech.com \
--cc=dledford@redhat.com \
--cc=elfring@users.sourceforge.net \
--cc=hal.rosenstock@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=sean.hefty@intel.com \
--cc=selvin.xavier@avagotech.com \
--cc=yuval.shaia@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®