linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] IB/mthca: fix return value of error branch in mthca_init_cq()
@ 2020-11-19 12:38 Xiongfeng Wang
  2020-11-19 15:30 ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Xiongfeng Wang @ 2020-11-19 12:38 UTC (permalink / raw)
  To: dledford, jgg; +Cc: wangxiongfeng2, linux-rdma, linux-kernel

We return 'err' in the error branch, but this variable may be set as
zero by the above code. Fix it by setting 'err'  as a negative value
before we goto the error label.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 drivers/infiniband/hw/mthca/mthca_cq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index c3cfea2..98d697b 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -803,8 +803,10 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
 	}
 
 	mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
-	if (IS_ERR(mailbox))
+	if (IS_ERR(mailbox)) {
+		err = -ENOMEM;
 		goto err_out_arm;
+	}
 
 	cq_context = mailbox->buf;
 
@@ -850,6 +852,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
 			    cq->cqn & (dev->limits.num_cqs - 1),
 			    cq)) {
 		spin_unlock_irq(&dev->cq_table.lock);
+		err = -ENOMEM;
 		goto err_out_free_mr;
 	}
 	spin_unlock_irq(&dev->cq_table.lock);
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] IB/mthca: fix return value of error branch in mthca_init_cq()
  2020-11-19 12:38 [PATCH] IB/mthca: fix return value of error branch in mthca_init_cq() Xiongfeng Wang
@ 2020-11-19 15:30 ` Jason Gunthorpe
  2020-11-20  1:51   ` Xiongfeng Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2020-11-19 15:30 UTC (permalink / raw)
  To: Xiongfeng Wang; +Cc: dledford, linux-rdma, linux-kernel

On Thu, Nov 19, 2020 at 08:38:49PM +0800, Xiongfeng Wang wrote:
> We return 'err' in the error branch, but this variable may be set as
> zero by the above code. Fix it by setting 'err'  as a negative value
> before we goto the error label.
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>

Missing fixes line

>  drivers/infiniband/hw/mthca/mthca_cq.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
> index c3cfea2..98d697b 100644
> --- a/drivers/infiniband/hw/mthca/mthca_cq.c
> +++ b/drivers/infiniband/hw/mthca/mthca_cq.c
> @@ -803,8 +803,10 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
>  	}
>  
>  	mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
> -	if (IS_ERR(mailbox))
> +	if (IS_ERR(mailbox)) {
> +		err = -ENOMEM;
>  		goto err_out_arm;
> +	}

mthca_alloc_mailbox returns err_ptr so this should do 

   err = ERR_PTR(mailbox)

>  	cq_context = mailbox->buf;
>  
> @@ -850,6 +852,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
>  			    cq->cqn & (dev->limits.num_cqs - 1),
>  			    cq)) {
>  		spin_unlock_irq(&dev->cq_table.lock);
> +		err = -ENOMEM;

And this should assign err to the output of mthca_array_set

Please fix and resend.

Thanks,
Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] IB/mthca: fix return value of error branch in mthca_init_cq()
  2020-11-19 15:30 ` Jason Gunthorpe
@ 2020-11-20  1:51   ` Xiongfeng Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Xiongfeng Wang @ 2020-11-20  1:51 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: dledford, linux-rdma, linux-kernel

Hi, Jason

Thanks for your reply !

On 2020/11/19 23:30, Jason Gunthorpe wrote:
> On Thu, Nov 19, 2020 at 08:38:49PM +0800, Xiongfeng Wang wrote:
>> We return 'err' in the error branch, but this variable may be set as
>> zero by the above code. Fix it by setting 'err'  as a negative value
>> before we goto the error label.
>>
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
> 
> Missing fixes line
> 
>>  drivers/infiniband/hw/mthca/mthca_cq.c | 5 ++++-
>>  1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
>> index c3cfea2..98d697b 100644
>> --- a/drivers/infiniband/hw/mthca/mthca_cq.c
>> +++ b/drivers/infiniband/hw/mthca/mthca_cq.c
>> @@ -803,8 +803,10 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
>>  	}
>>  
>>  	mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
>> -	if (IS_ERR(mailbox))
>> +	if (IS_ERR(mailbox)) {
>> +		err = -ENOMEM;
>>  		goto err_out_arm;
>> +	}
> 
> mthca_alloc_mailbox returns err_ptr so this should do 
> 
>    err = ERR_PTR(mailbox)

Is it PTR_ERR here ?
Since mailbox is a pointer.

> 
>>  	cq_context = mailbox->buf;
>>  
>> @@ -850,6 +852,7 @@ int mthca_init_cq(struct mthca_dev *dev, int nent,
>>  			    cq->cqn & (dev->limits.num_cqs - 1),
>>  			    cq)) {
>>  		spin_unlock_irq(&dev->cq_table.lock);
>> +		err = -ENOMEM;
> 
> And this should assign err to the output of mthca_array_set
> 
> Please fix and resend.

Sure.

Thanks,
Xiongfeng

> 
> Thanks,
> Jason
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-11-20  1:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19 12:38 [PATCH] IB/mthca: fix return value of error branch in mthca_init_cq() Xiongfeng Wang
2020-11-19 15:30 ` Jason Gunthorpe
2020-11-20  1:51   ` Xiongfeng Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).