Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1741174 > unrolled thread

[PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

Started by"Wei Hu (Xavier)" <xavier.huwei@huawei.com>
First post2017-09-28 06:40 +0200
Last post2017-09-29 15:20 +0200
Articles 7 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp "Wei Hu (Xavier)" <xavier.huwei@huawei.com> - 2017-09-28 06:40 +0200
    Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc  return NULL in hns_roce_v1_recreate_lp_qp Leon Romanovsky <leon@kernel.org> - 2017-09-28 11:20 +0200
      Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc  return NULL in hns_roce_v1_recreate_lp_qp "Wei Hu (Xavier)" <xavier.huwei@huawei.com> - 2017-09-28 14:00 +0200
        Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc  return NULL in hns_roce_v1_recreate_lp_qp Leon Romanovsky <leon@kernel.org> - 2017-09-28 15:00 +0200
          Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc  return NULL in hns_roce_v1_recreate_lp_qp "Wei Hu (Xavier)" <xavier.huwei@huawei.com> - 2017-09-29 08:10 +0200
            Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc  return NULL in hns_roce_v1_recreate_lp_qp Leon Romanovsky <leon@kernel.org> - 2017-09-29 12:30 +0200
              Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc  return NULL in hns_roce_v1_recreate_lp_qp "Wei Hu (Xavier)" <xavier.huwei@tom.com> - 2017-09-29 15:20 +0200

#1741174 — [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

From"Wei Hu (Xavier)" <xavier.huwei@huawei.com>
Date2017-09-28 06:40 +0200
Subject[PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp
Message-ID<uuyM9-4cw-11@gated-at.bofh.it>
From: Lijun Ou <oulijun@huawei.com>

When lp_qp_work is NULL, it should be returned ENOMEM. This patch
mainly fixes it.

Ihis patch fixes the smatch error as below:
drivers/infiniband/hw/hns/hns_roce_hw_v1.c:918 hns_roce_v1_recreate_lp_qp()
error: potential null dereference 'lp_qp_work'.  (kzalloc returns null)

Signed-off-by: Lijun Ou <oulijun@huawei.com>
Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
Signed-off-by: Shaobo Xu <xushaobo2@huawei.com>
---
 drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
index 95f5c88..1071fa2 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
@@ -912,6 +912,8 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
 
 	lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
 			     GFP_KERNEL);
+	if (!lp_qp_work)
+		return -ENOMEM;
 
 	INIT_WORK(&(lp_qp_work->work), hns_roce_v1_recreate_lp_qp_work_fn);
 
-- 
1.9.1

[toc] | [next] | [standalone]


#1741316 — Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

FromLeon Romanovsky <leon@kernel.org>
Date2017-09-28 11:20 +0200
SubjectRe: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp
Message-ID<uuD98-78P-17@gated-at.bofh.it>
In reply to#1741174

[Multipart message — attachments visible in raw view] — view raw

On Thu, Sep 28, 2017 at 12:57:28PM +0800, Wei Hu (Xavier) wrote:
> From: Lijun Ou <oulijun@huawei.com>
>
> When lp_qp_work is NULL, it should be returned ENOMEM. This patch
> mainly fixes it.
>
> Ihis patch fixes the smatch error as below:
> drivers/infiniband/hw/hns/hns_roce_hw_v1.c:918 hns_roce_v1_recreate_lp_qp()
> error: potential null dereference 'lp_qp_work'.  (kzalloc returns null)
>
> Signed-off-by: Lijun Ou <oulijun@huawei.com>
> Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
> Signed-off-by: Shaobo Xu <xushaobo2@huawei.com>
> ---
>  drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 95f5c88..1071fa2 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -912,6 +912,8 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
>
>  	lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
>  			     GFP_KERNEL);
> +	if (!lp_qp_work)
> +		return -ENOMEM;
>

You will treat this error in the same was as you will treat timeout,
which is wrong.

1656          */
1657         if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
1658                 dev_warn(&hr_dev->pdev->dev, "recreate lp qp timeout!\n");
1659
1660         p = (u32 *)(&addr[0]);


>  	INIT_WORK(&(lp_qp_work->work), hns_roce_v1_recreate_lp_qp_work_fn);
>
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [next] | [standalone]


#1741473 — Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

From"Wei Hu (Xavier)" <xavier.huwei@huawei.com>
Date2017-09-28 14:00 +0200
SubjectRe: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp
Message-ID<uuFDX-8w4-19@gated-at.bofh.it>
In reply to#1741316

On 2017/9/28 17:13, Leon Romanovsky wrote:
> On Thu, Sep 28, 2017 at 12:57:28PM +0800, Wei Hu (Xavier) wrote:
>> From: Lijun Ou <oulijun@huawei.com>
>>
>> When lp_qp_work is NULL, it should be returned ENOMEM. This patch
>> mainly fixes it.
>>
>> Ihis patch fixes the smatch error as below:
>> drivers/infiniband/hw/hns/hns_roce_hw_v1.c:918 hns_roce_v1_recreate_lp_qp()
>> error: potential null dereference 'lp_qp_work'.  (kzalloc returns null)
>>
>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>> Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
>> Signed-off-by: Shaobo Xu <xushaobo2@huawei.com>
>> ---
>>   drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>> index 95f5c88..1071fa2 100644
>> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>> @@ -912,6 +912,8 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
>>
>>   	lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
>>   			     GFP_KERNEL);
>> +	if (!lp_qp_work)
>> +		return -ENOMEM;
>>
> You will treat this error in the same was as you will treat timeout,
> which is wrong.
Thanks,  Leon
We will send v2 to fix the compatible warn info.
> 1656          */
> 1657         if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
> 1658                 dev_warn(&hr_dev->pdev->dev, "recreate lp qp timeout!\n");
> 1659
> 1660         p = (u32 *)(&addr[0]);
>
>
>>   	INIT_WORK(&(lp_qp_work->work), hns_roce_v1_recreate_lp_qp_work_fn);
>>
>> --
>> 1.9.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [next] | [standalone]


#1741517 — Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

FromLeon Romanovsky <leon@kernel.org>
Date2017-09-28 15:00 +0200
SubjectRe: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp
Message-ID<uuGA2-Fm-39@gated-at.bofh.it>
In reply to#1741473

[Multipart message — attachments visible in raw view] — view raw

On Thu, Sep 28, 2017 at 07:56:59PM +0800, Wei Hu (Xavier) wrote:
>
>
> On 2017/9/28 17:13, Leon Romanovsky wrote:
> > On Thu, Sep 28, 2017 at 12:57:28PM +0800, Wei Hu (Xavier) wrote:
> > > From: Lijun Ou <oulijun@huawei.com>
> > >
> > > When lp_qp_work is NULL, it should be returned ENOMEM. This patch
> > > mainly fixes it.
> > >
> > > Ihis patch fixes the smatch error as below:
> > > drivers/infiniband/hw/hns/hns_roce_hw_v1.c:918 hns_roce_v1_recreate_lp_qp()
> > > error: potential null dereference 'lp_qp_work'.  (kzalloc returns null)
> > >
> > > Signed-off-by: Lijun Ou <oulijun@huawei.com>
> > > Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
> > > Signed-off-by: Shaobo Xu <xushaobo2@huawei.com>
> > > ---
> > >   drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 2 ++
> > >   1 file changed, 2 insertions(+)
> > >
> > > diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> > > index 95f5c88..1071fa2 100644
> > > --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> > > +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> > > @@ -912,6 +912,8 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
> > >
> > >   	lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
> > >   			     GFP_KERNEL);
> > > +	if (!lp_qp_work)
> > > +		return -ENOMEM;
> > >
> > You will treat this error in the same was as you will treat timeout,
> > which is wrong.
> Thanks,  Leon
> We will send v2 to fix the compatible warn info.

No, you missed the point.
From the code flow below the behavior of hns_roce_v1_recreate_lp_qp
for ENOMEM and ETIMEOUT returns will be the same and it is wrong.

For the ETIMEOUT, you can continue, for ENOMEM, you should properly
unfold the whole flow.

Thanks


> > 1656          */
> > 1657         if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
> > 1658                 dev_warn(&hr_dev->pdev->dev, "recreate lp qp timeout!\n");
> > 1659
> > 1660         p = (u32 *)(&addr[0]);
> >
> >
> > >   	INIT_WORK(&(lp_qp_work->work), hns_roce_v1_recreate_lp_qp_work_fn);
> > >
> > > --
> > > 1.9.1
> > >
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [next] | [standalone]


#1741935 — Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

From"Wei Hu (Xavier)" <xavier.huwei@huawei.com>
Date2017-09-29 08:10 +0200
SubjectRe: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp
Message-ID<uuWEN-2sN-11@gated-at.bofh.it>
In reply to#1741517

On 2017/9/28 20:59, Leon Romanovsky wrote:
> On Thu, Sep 28, 2017 at 07:56:59PM +0800, Wei Hu (Xavier) wrote:
>>
>> On 2017/9/28 17:13, Leon Romanovsky wrote:
>>> On Thu, Sep 28, 2017 at 12:57:28PM +0800, Wei Hu (Xavier) wrote:
>>>> From: Lijun Ou <oulijun@huawei.com>
>>>>
>>>> When lp_qp_work is NULL, it should be returned ENOMEM. This patch
>>>> mainly fixes it.
>>>>
>>>> Ihis patch fixes the smatch error as below:
>>>> drivers/infiniband/hw/hns/hns_roce_hw_v1.c:918 hns_roce_v1_recreate_lp_qp()
>>>> error: potential null dereference 'lp_qp_work'.  (kzalloc returns null)
>>>>
>>>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>>>> Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
>>>> Signed-off-by: Shaobo Xu <xushaobo2@huawei.com>
>>>> ---
>>>>    drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 2 ++
>>>>    1 file changed, 2 insertions(+)
>>>>
>>>> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>>>> index 95f5c88..1071fa2 100644
>>>> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>>>> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>>>> @@ -912,6 +912,8 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
>>>>
>>>>    	lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
>>>>    			     GFP_KERNEL);
>>>> +	if (!lp_qp_work)
>>>> +		return -ENOMEM;
>>>>
>>> You will treat this error in the same was as you will treat timeout,
>>> which is wrong.
>> Thanks,  Leon
>> We will send v2 to fix the compatible warn info.
> No, you missed the point.
>  From the code flow below the behavior of hns_roce_v1_recreate_lp_qp
> for ENOMEM and ETIMEOUT returns will be the same and it is wrong.
>
> For the ETIMEOUT, you can continue, for ENOMEM, you should properly
> unfold the whole flow.
>
> Thanks
>
Hi, Leon
     We prepare to modify the warn info as bleow:

         if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
             dev_warn(&hr_dev->pdev->dev, "recreate lp qp failed!\n");

     for -ETIMEDOUT,  there is a warn info as blow, but there isn't this 
one for -ENOMEM.
         dev_warn(dev, "recreate lp qp failed 20s timeout and return 
failed!\n");

         static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
         {
             <snip>
             lp_qp_work = kzalloc(sizeof(struct 
hns_roce_recreate_lp_qp_work),
                  GFP_KERNEL);
             if (!lp_qp_work)
                 return -ENOMEM;

             <snip>
             dev_warn(dev, "recreate lp qp failed 20s timeout and return 
failed!\n");
             return -ETIMEDOUT;
         }

     Regards
Wei Hu
>>> 1656          */
>>> 1657         if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
>>> 1658                 dev_warn(&hr_dev->pdev->dev, "recreate lp qp timeout!\n");
>>> 1659
>>> 1660         p = (u32 *)(&addr[0]);
>>>
>>>
>>>>    	INIT_WORK(&(lp_qp_work->work), hns_roce_v1_recreate_lp_qp_work_fn);
>>>>
>>>> --
>>>> 1.9.1
>>>>
>>>> --
>>>> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
>>>> the body of a message to majordomo@vger.kernel.org
>>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[toc] | [prev] | [next] | [standalone]


#1742036 — Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

FromLeon Romanovsky <leon@kernel.org>
Date2017-09-29 12:30 +0200
SubjectRe: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp
Message-ID<uv0Iq-4Vn-11@gated-at.bofh.it>
In reply to#1741935

[Multipart message — attachments visible in raw view] — view raw

On Fri, Sep 29, 2017 at 02:07:22PM +0800, Wei Hu (Xavier) wrote:
>
>
> On 2017/9/28 20:59, Leon Romanovsky wrote:
> > On Thu, Sep 28, 2017 at 07:56:59PM +0800, Wei Hu (Xavier) wrote:
> > >
> > > On 2017/9/28 17:13, Leon Romanovsky wrote:
> > > > On Thu, Sep 28, 2017 at 12:57:28PM +0800, Wei Hu (Xavier) wrote:
> > > > > From: Lijun Ou <oulijun@huawei.com>
> > > > >
> > > > > When lp_qp_work is NULL, it should be returned ENOMEM. This patch
> > > > > mainly fixes it.
> > > > >
> > > > > Ihis patch fixes the smatch error as below:
> > > > > drivers/infiniband/hw/hns/hns_roce_hw_v1.c:918 hns_roce_v1_recreate_lp_qp()
> > > > > error: potential null dereference 'lp_qp_work'.  (kzalloc returns null)
> > > > >
> > > > > Signed-off-by: Lijun Ou <oulijun@huawei.com>
> > > > > Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
> > > > > Signed-off-by: Shaobo Xu <xushaobo2@huawei.com>
> > > > > ---
> > > > >    drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 2 ++
> > > > >    1 file changed, 2 insertions(+)
> > > > >
> > > > > diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> > > > > index 95f5c88..1071fa2 100644
> > > > > --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> > > > > +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> > > > > @@ -912,6 +912,8 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
> > > > >
> > > > >    	lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
> > > > >    			     GFP_KERNEL);
> > > > > +	if (!lp_qp_work)
> > > > > +		return -ENOMEM;
> > > > >
> > > > You will treat this error in the same was as you will treat timeout,
> > > > which is wrong.
> > > Thanks,  Leon
> > > We will send v2 to fix the compatible warn info.
> > No, you missed the point.
> >  From the code flow below the behavior of hns_roce_v1_recreate_lp_qp
> > for ENOMEM and ETIMEOUT returns will be the same and it is wrong.
> >
> > For the ETIMEOUT, you can continue, for ENOMEM, you should properly
> > unfold the whole flow.
> >
> > Thanks
> >
> Hi, Leon
>     We prepare to modify the warn info as bleow:
>
>         if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
>             dev_warn(&hr_dev->pdev->dev, "recreate lp qp failed!\n");
>
>     for -ETIMEDOUT,  there is a warn info as blow, but there isn't this one
> for -ENOMEM.
>         dev_warn(dev, "recreate lp qp failed 20s timeout and return
> failed!\n");
>
>         static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
>         {
>             <snip>
>             lp_qp_work = kzalloc(sizeof(struct
> hns_roce_recreate_lp_qp_work),
>                  GFP_KERNEL);
>             if (!lp_qp_work)
>                 return -ENOMEM;
>
>             <snip>
>             dev_warn(dev, "recreate lp qp failed 20s timeout and return
> failed!\n");
>             return -ETIMEDOUT;
>         }
>
>     Regards
> Wei Hu

Hi Wei,

It will be helpful, if you post your suggestions in git diff format.

My expectation is to see the following code:

diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
index 747efd1ae5a6..0b9ec7c24f2d 100644
--- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
+++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
@@ -1648,14 +1648,18 @@ void hns_roce_v1_set_mac(struct hns_roce_dev *hr_dev, u8 phy_port, u8 *addr)
 	u16 *p_h;
 	u32 *p;
 	u32 val;

 	/*
 	 * When mac changed, loopback may fail
 	 * because of smac not equal to dmac.
 	 * We Need to release and create reserved qp again.
 	 */
-	if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
-		dev_warn(&hr_dev->pdev->dev, "recreate lp qp timeout!\n");
+	if (hr_dev->hw->dereg_mr) {
+		int ret;
+		ret = hns_roce_v1_recreate_lp_qp(hr_dev);
+		if (ret && ret != -ETIMEDOUT)
+			return ret;
+	}

 	p = (u32 *)(&addr[0]);
 	reg_smac_l = *p;

Thanks

[toc] | [prev] | [next] | [standalone]


#1742096 — Re: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp

From"Wei Hu (Xavier)" <xavier.huwei@tom.com>
Date2017-09-29 15:20 +0200
SubjectRe: [PATCH for-next 3/9] RDMA/hns: Add return statement when kzalloc return NULL in hns_roce_v1_recreate_lp_qp
Message-ID<uv3mV-6DK-1@gated-at.bofh.it>
In reply to#1742036

On 2017/9/29 18:23, Leon Romanovsky wrote:
> On Fri, Sep 29, 2017 at 02:07:22PM +0800, Wei Hu (Xavier) wrote:
>>
>> On 2017/9/28 20:59, Leon Romanovsky wrote:
>>> On Thu, Sep 28, 2017 at 07:56:59PM +0800, Wei Hu (Xavier) wrote:
>>>> On 2017/9/28 17:13, Leon Romanovsky wrote:
>>>>> On Thu, Sep 28, 2017 at 12:57:28PM +0800, Wei Hu (Xavier) wrote:
>>>>>> From: Lijun Ou <oulijun@huawei.com>
>>>>>>
>>>>>> When lp_qp_work is NULL, it should be returned ENOMEM. This patch
>>>>>> mainly fixes it.
>>>>>>
>>>>>> Ihis patch fixes the smatch error as below:
>>>>>> drivers/infiniband/hw/hns/hns_roce_hw_v1.c:918 hns_roce_v1_recreate_lp_qp()
>>>>>> error: potential null dereference 'lp_qp_work'.  (kzalloc returns null)
>>>>>>
>>>>>> Signed-off-by: Lijun Ou <oulijun@huawei.com>
>>>>>> Signed-off-by: Wei Hu (Xavier) <xavier.huwei@huawei.com>
>>>>>> Signed-off-by: Shaobo Xu <xushaobo2@huawei.com>
>>>>>> ---
>>>>>>     drivers/infiniband/hw/hns/hns_roce_hw_v1.c | 2 ++
>>>>>>     1 file changed, 2 insertions(+)
>>>>>>
>>>>>> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>>>>>> index 95f5c88..1071fa2 100644
>>>>>> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>>>>>> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
>>>>>> @@ -912,6 +912,8 @@ static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
>>>>>>
>>>>>>     	lp_qp_work = kzalloc(sizeof(struct hns_roce_recreate_lp_qp_work),
>>>>>>     			     GFP_KERNEL);
>>>>>> +	if (!lp_qp_work)
>>>>>> +		return -ENOMEM;
>>>>>>
>>>>> You will treat this error in the same was as you will treat timeout,
>>>>> which is wrong.
>>>> Thanks,  Leon
>>>> We will send v2 to fix the compatible warn info.
>>> No, you missed the point.
>>>   From the code flow below the behavior of hns_roce_v1_recreate_lp_qp
>>> for ENOMEM and ETIMEOUT returns will be the same and it is wrong.
>>>
>>> For the ETIMEOUT, you can continue, for ENOMEM, you should properly
>>> unfold the whole flow.
>>>
>>> Thanks
>>>
>> Hi, Leon
>>      We prepare to modify the warn info as bleow:
>>
>>          if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
>>              dev_warn(&hr_dev->pdev->dev, "recreate lp qp failed!\n");
>>
>>      for -ETIMEDOUT,  there is a warn info as blow, but there isn't this one
>> for -ENOMEM.
>>          dev_warn(dev, "recreate lp qp failed 20s timeout and return
>> failed!\n");
>>
>>          static int hns_roce_v1_recreate_lp_qp(struct hns_roce_dev *hr_dev)
>>          {
>>              <snip>
>>              lp_qp_work = kzalloc(sizeof(struct
>> hns_roce_recreate_lp_qp_work),
>>                   GFP_KERNEL);
>>              if (!lp_qp_work)
>>                  return -ENOMEM;
>>
>>              <snip>
>>              dev_warn(dev, "recreate lp qp failed 20s timeout and return
>> failed!\n");
>>              return -ETIMEDOUT;
>>          }
>>
>>      Regards
>> Wei Hu
> Hi Wei,
>
> It will be helpful, if you post your suggestions in git diff format.
>
> My expectation is to see the following code:
>
> diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> index 747efd1ae5a6..0b9ec7c24f2d 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v1.c
> @@ -1648,14 +1648,18 @@ void hns_roce_v1_set_mac(struct hns_roce_dev *hr_dev, u8 phy_port, u8 *addr)
>   	u16 *p_h;
>   	u32 *p;
>   	u32 val;
>
>   	/*
>   	 * When mac changed, loopback may fail
>   	 * because of smac not equal to dmac.
>   	 * We Need to release and create reserved qp again.
>   	 */
> -	if (hr_dev->hw->dereg_mr && hns_roce_v1_recreate_lp_qp(hr_dev))
> -		dev_warn(&hr_dev->pdev->dev, "recreate lp qp timeout!\n");
> +	if (hr_dev->hw->dereg_mr) {
> +		int ret;
> +		ret = hns_roce_v1_recreate_lp_qp(hr_dev);
> +		if (ret && ret != -ETIMEDOUT)
> +			return ret;
> +	}
>
>   	p = (u32 *)(&addr[0]);
>   	reg_smac_l = *p;
>
> Thanks
Hi, Leon
     Thanks for your suggestion. We will send patch v2 to fix it.

     Best Regard
Wei Hu

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web