diff mbox

[04/38] IB/ehca: fix handling idr_alloc result

Message ID 1442842450-29769-5-git-send-email-a.hajda@samsung.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Andrzej Hajda Sept. 21, 2015, 1:33 p.m. UTC
The function can return negative value.

The problem has been detected using proposed semantic patch
scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
---
 drivers/staging/rdma/ehca/ehca_cq.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Doug Ledford Sept. 29, 2015, 6:23 p.m. UTC | #1
On 09/21/2015 09:33 AM, Andrzej Hajda wrote:
> The function can return negative value.
> 
> The problem has been detected using proposed semantic patch
> scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].
> 
> [1]: http://permalink.gmane.org/gmane.linux.kernel/2038576
> 
> Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>

Patch looks fine to me.

Acked-by: Doug Ledford <dledford@redhat.com>

> ---
>  drivers/staging/rdma/ehca/ehca_cq.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/rdma/ehca/ehca_cq.c b/drivers/staging/rdma/ehca/ehca_cq.c
> index 9b68b17..ea1b5c1 100644
> --- a/drivers/staging/rdma/ehca/ehca_cq.c
> +++ b/drivers/staging/rdma/ehca/ehca_cq.c
> @@ -130,7 +130,7 @@ struct ib_cq *ehca_create_cq(struct ib_device *device,
>  	void *vpage;
>  	u32 counter;
>  	u64 rpage, cqx_fec, h_ret;
> -	int ipz_rc, i;
> +	int rc, i;
>  	unsigned long flags;
>  
>  	if (attr->flags)
> @@ -170,16 +170,17 @@ struct ib_cq *ehca_create_cq(struct ib_device *device,
>  
>  	idr_preload(GFP_KERNEL);
>  	write_lock_irqsave(&ehca_cq_idr_lock, flags);
> -	my_cq->token = idr_alloc(&ehca_cq_idr, my_cq, 0, 0x2000000, GFP_NOWAIT);
> +	rc = idr_alloc(&ehca_cq_idr, my_cq, 0, 0x2000000, GFP_NOWAIT);
>  	write_unlock_irqrestore(&ehca_cq_idr_lock, flags);
>  	idr_preload_end();
>  
> -	if (my_cq->token < 0) {
> +	if (rc < 0) {
>  		cq = ERR_PTR(-ENOMEM);
>  		ehca_err(device, "Can't allocate new idr entry. device=%p",
>  			 device);
>  		goto create_cq_exit1;
>  	}
> +	my_cq->token = rc;
>  
>  	/*
>  	 * CQs maximum depth is 4GB-64, but we need additional 20 as buffer
> @@ -195,11 +196,11 @@ struct ib_cq *ehca_create_cq(struct ib_device *device,
>  		goto create_cq_exit2;
>  	}
>  
> -	ipz_rc = ipz_queue_ctor(NULL, &my_cq->ipz_queue, param.act_pages,
> +	rc = ipz_queue_ctor(NULL, &my_cq->ipz_queue, param.act_pages,
>  				EHCA_PAGESIZE, sizeof(struct ehca_cqe), 0, 0);
> -	if (!ipz_rc) {
> +	if (!rc) {
>  		ehca_err(device, "ipz_queue_ctor() failed ipz_rc=%i device=%p",
> -			 ipz_rc, device);
> +			 rc, device);
>  		cq = ERR_PTR(-EINVAL);
>  		goto create_cq_exit3;
>  	}
>
diff mbox

Patch

diff --git a/drivers/staging/rdma/ehca/ehca_cq.c b/drivers/staging/rdma/ehca/ehca_cq.c
index 9b68b17..ea1b5c1 100644
--- a/drivers/staging/rdma/ehca/ehca_cq.c
+++ b/drivers/staging/rdma/ehca/ehca_cq.c
@@ -130,7 +130,7 @@  struct ib_cq *ehca_create_cq(struct ib_device *device,
 	void *vpage;
 	u32 counter;
 	u64 rpage, cqx_fec, h_ret;
-	int ipz_rc, i;
+	int rc, i;
 	unsigned long flags;
 
 	if (attr->flags)
@@ -170,16 +170,17 @@  struct ib_cq *ehca_create_cq(struct ib_device *device,
 
 	idr_preload(GFP_KERNEL);
 	write_lock_irqsave(&ehca_cq_idr_lock, flags);
-	my_cq->token = idr_alloc(&ehca_cq_idr, my_cq, 0, 0x2000000, GFP_NOWAIT);
+	rc = idr_alloc(&ehca_cq_idr, my_cq, 0, 0x2000000, GFP_NOWAIT);
 	write_unlock_irqrestore(&ehca_cq_idr_lock, flags);
 	idr_preload_end();
 
-	if (my_cq->token < 0) {
+	if (rc < 0) {
 		cq = ERR_PTR(-ENOMEM);
 		ehca_err(device, "Can't allocate new idr entry. device=%p",
 			 device);
 		goto create_cq_exit1;
 	}
+	my_cq->token = rc;
 
 	/*
 	 * CQs maximum depth is 4GB-64, but we need additional 20 as buffer
@@ -195,11 +196,11 @@  struct ib_cq *ehca_create_cq(struct ib_device *device,
 		goto create_cq_exit2;
 	}
 
-	ipz_rc = ipz_queue_ctor(NULL, &my_cq->ipz_queue, param.act_pages,
+	rc = ipz_queue_ctor(NULL, &my_cq->ipz_queue, param.act_pages,
 				EHCA_PAGESIZE, sizeof(struct ehca_cqe), 0, 0);
-	if (!ipz_rc) {
+	if (!rc) {
 		ehca_err(device, "ipz_queue_ctor() failed ipz_rc=%i device=%p",
-			 ipz_rc, device);
+			 rc, device);
 		cq = ERR_PTR(-EINVAL);
 		goto create_cq_exit3;
 	}