[PATCH 1/2] NTB: perf: Fix an error code in perf_setup_inbuf()

6 views
Skip to first unread message

Yang Li

unread,
Jun 4, 2021, 6:21:21 AM6/4/21
to jdm...@kudzu.us, dave....@intel.com, all...@gmail.com, linu...@googlegroups.com, linux-...@vger.kernel.org, Yang Li
When the function IS_ALIGNED() returns false, the value of ret is 0.
So, we set ret to -ENOMEM to indicate this error.

Clean up smatch warning:
drivers/ntb/test/ntb_perf.c:602 perf_setup_inbuf() warn: missing error
code 'ret'.

Reported-by: Abaci Robot <ab...@linux.alibaba.com>
Signed-off-by: Yang Li <yang...@linux.alibaba.com>
---
drivers/ntb/test/ntb_perf.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c
index 89df135..c20b375 100644
--- a/drivers/ntb/test/ntb_perf.c
+++ b/drivers/ntb/test/ntb_perf.c
@@ -598,6 +598,7 @@ static int perf_setup_inbuf(struct perf_peer *peer)
return -ENOMEM;
}
if (!IS_ALIGNED(peer->inbuf_xlat, xlat_align)) {
+ ret = -ENOMEM;
dev_err(&perf->ntb->dev, "Unaligned inbuf allocated\n");
goto err_free_inbuf;
}
--
1.8.3.1

Yang Li

unread,
Jun 4, 2021, 6:21:27 AM6/4/21
to jdm...@kudzu.us, dave....@intel.com, all...@gmail.com, linu...@googlegroups.com, linux-...@vger.kernel.org, Yang Li
When the value of nm->isr_ctx is false, the value of ret is 0.
So, we set ret to -ENOMEM to indicate this error.

Clean up smatch warning:
drivers/ntb/test/ntb_msi_test.c:373 ntb_msit_probe() warn: missing error
code 'ret'.

Reported-by: Abaci Robot <ab...@linux.alibaba.com>
Signed-off-by: Yang Li <yang...@linux.alibaba.com>
---
drivers/ntb/test/ntb_msi_test.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ntb/test/ntb_msi_test.c b/drivers/ntb/test/ntb_msi_test.c
index 7095ecd..5f9e0be 100644
--- a/drivers/ntb/test/ntb_msi_test.c
+++ b/drivers/ntb/test/ntb_msi_test.c
@@ -369,8 +369,10 @@ static int ntb_msit_probe(struct ntb_client *client, struct ntb_dev *ntb)
if (ret)
goto remove_dbgfs;

- if (!nm->isr_ctx)
+ if (!nm->isr_ctx) {
+ return -ENOMEM;
goto remove_dbgfs;
+ }

ntb_link_enable(ntb, NTB_SPEED_AUTO, NTB_WIDTH_AUTO);

--
1.8.3.1

Logan Gunthorpe

unread,
Jun 4, 2021, 11:18:24 AM6/4/21
to Yang Li, jdm...@kudzu.us, dave....@intel.com, all...@gmail.com, linu...@googlegroups.com, linux-...@vger.kernel.org
I think you made a typo here. You probably meant ret = -ENOMEM.

Thanks,

Logan

Serge Semin

unread,
Jun 5, 2021, 2:05:58 PM6/5/21
to Yang Li, jdm...@kudzu.us, dave....@intel.com, all...@gmail.com, linu...@googlegroups.com, linux-...@vger.kernel.org
Hello Yang.

On Fri, Jun 04, 2021 at 06:20:50PM +0800, Yang Li wrote:
> When the function IS_ALIGNED() returns false, the value of ret is 0.
> So, we set ret to -ENOMEM to indicate this error.
>
> Clean up smatch warning:
> drivers/ntb/test/ntb_perf.c:602 perf_setup_inbuf() warn: missing error
> code 'ret'.

Great catch! Thanks for posing the fix. Indeed ret would zero in case of
unaligned buffer allocation. Though such situation is very improbable.
A tiny nitpick below.

>
> Reported-by: Abaci Robot <ab...@linux.alibaba.com>
> Signed-off-by: Yang Li <yang...@linux.alibaba.com>
> ---
> drivers/ntb/test/ntb_perf.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c
> index 89df135..c20b375 100644
> --- a/drivers/ntb/test/ntb_perf.c
> +++ b/drivers/ntb/test/ntb_perf.c
> @@ -598,6 +598,7 @@ static int perf_setup_inbuf(struct perf_peer *peer)
> return -ENOMEM;
> }
> if (!IS_ALIGNED(peer->inbuf_xlat, xlat_align)) {

> + ret = -ENOMEM;

I'd set -EINVAL here. In this case we do have enough memory, but the
base address is unaligned in a way the NTB hw requires. After fixing
that feel free to add:
Reviewed-by: Serge Semin <fancer...@gmail.com>

-Sergey

> dev_err(&perf->ntb->dev, "Unaligned inbuf allocated\n");
> goto err_free_inbuf;
> }
> --
> 1.8.3.1
>
> --
> You received this message because you are subscribed to the Google Groups "linux-ntb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to linux-ntb+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/linux-ntb/1622802051-43464-1-git-send-email-yang.lee%40linux.alibaba.com.

Yang Li

unread,
Jun 7, 2021, 1:56:32 AM6/7/21
to jdm...@kudzu.us, dave....@intel.com, all...@gmail.com, log...@deltatee.com, linu...@googlegroups.com, linux-...@vger.kernel.org, Yang Li
When the value of nm->isr_ctx is false, the value of ret is 0.
So, we set ret to -ENOMEM to indicate this error.

Clean up smatch warning:
drivers/ntb/test/ntb_msi_test.c:373 ntb_msit_probe() warn: missing
error code 'ret'.

Reported-by: Abaci Robot <ab...@linux.alibaba.com>
Signed-off-by: Yang Li <yang...@linux.alibaba.com>
---

Change in v2:
--revise typo

drivers/ntb/test/ntb_msi_test.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ntb/test/ntb_msi_test.c b/drivers/ntb/test/ntb_msi_test.c
index 7095ecd..4e18e08 100644
--- a/drivers/ntb/test/ntb_msi_test.c
+++ b/drivers/ntb/test/ntb_msi_test.c
@@ -369,8 +369,10 @@ static int ntb_msit_probe(struct ntb_client *client, struct ntb_dev *ntb)
if (ret)
goto remove_dbgfs;

- if (!nm->isr_ctx)
+ if (!nm->isr_ctx) {
+ ret = -ENOMEM;

Yang.Lee

unread,
Jun 7, 2021, 1:58:15 AM6/7/21
to jdmason, Logan Gunthorpe, dave.jiang, allenbh, linux-ntb, linux-kernel
Hi,
I have sent a V2 patch. 

Thanks for your review.
------------------------------------------------------------------
发件人:Logan Gunthorpe <log...@deltatee.com>
发送时间:2021年6月5日(星期六) 00:21
收件人:Yang Li <yang...@linux.alibaba.com>; jdmason <jdm...@kudzu.us>
抄 送:dave.jiang <dave....@intel.com>; allenbh <all...@gmail.com>; linux-ntb <linu...@googlegroups.com>; linux-kernel <linux-...@vger.kernel.org>
主 题:Re: [PATCH 2/2] NTB: Fix an error code in ntb_msit_probe()

Yang Li

unread,
Jun 7, 2021, 4:40:47 AM6/7/21
to jdm...@kudzu.us, dave....@intel.com, all...@gmail.com, fancer...@gmail.com, linu...@googlegroups.com, linux-...@vger.kernel.org, Yang Li
When the function IS_ALIGNED() returns false, the value of ret is 0.
So, we set ret to -EINVAL to indicate this error.

Clean up smatch warning:
drivers/ntb/test/ntb_perf.c:602 perf_setup_inbuf() warn: missing error
code 'ret'.

Reported-by: Abaci Robot <ab...@linux.alibaba.com>
Signed-off-by: Yang Li <yang...@linux.alibaba.com>
Reviewed-by: Serge Semin <fancer...@gmail.com>
---

Change in v2:
--According to Serge's suggestion, set ret to -EINVAL.
https://lore.kernel.org/lkml/20210605180554.ql4rhpukj57ujkxw@mobilestation/

drivers/ntb/test/ntb_perf.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/ntb/test/ntb_perf.c b/drivers/ntb/test/ntb_perf.c
index 89df135..65e1e5c 100644
--- a/drivers/ntb/test/ntb_perf.c
+++ b/drivers/ntb/test/ntb_perf.c
@@ -598,6 +598,7 @@ static int perf_setup_inbuf(struct perf_peer *peer)
return -ENOMEM;
}
if (!IS_ALIGNED(peer->inbuf_xlat, xlat_align)) {
+ ret = -EINVAL;

Logan Gunthorpe

unread,
Jun 7, 2021, 11:51:33 AM6/7/21
to Yang Li, jdm...@kudzu.us, dave....@intel.com, all...@gmail.com, linu...@googlegroups.com, linux-...@vger.kernel.org


On 2021-06-06 11:56 p.m., Yang Li wrote:
> When the value of nm->isr_ctx is false, the value of ret is 0.
> So, we set ret to -ENOMEM to indicate this error.
>
> Clean up smatch warning:
> drivers/ntb/test/ntb_msi_test.c:373 ntb_msit_probe() warn: missing
> error code 'ret'.
>
> Reported-by: Abaci Robot <ab...@linux.alibaba.com>
> Signed-off-by: Yang Li <yang...@linux.alibaba.com>

Thanks!

Reviewed-by: Logan Gunthorpe <log...@deltatee.com>
Reply all
Reply to author
Forward
0 new messages