* [dpdk-dev] [PATCH] test: fix division by zero
@ 2021-04-23 7:35 Min Hu (Connor)
2021-05-12 16:53 ` Bruce Richardson
2021-05-13 1:10 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
0 siblings, 2 replies; 6+ messages in thread
From: Min Hu (Connor) @ 2021-04-23 7:35 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, anatoly.burakov, thomas
Variable i is used as a denominator which may be zero, and
this may result in segmentation fault.
This patch fixed it.
Fixes: 948bc3d6d095 ("test: add reciprocal based division")
Cc: stable@dpdk.org
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
app/test/test_reciprocal_division_perf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/app/test/test_reciprocal_division_perf.c b/app/test/test_reciprocal_division_perf.c
index a7be8aa..2647308 100644
--- a/app/test/test_reciprocal_division_perf.c
+++ b/app/test/test_reciprocal_division_perf.c
@@ -143,7 +143,7 @@ test_reciprocal_division_perf(void)
"result %"PRIu64"",
nresult_u64, rresult_u64);
result = 1;
- break;
+ goto err;
}
}
@@ -182,7 +182,7 @@ test_reciprocal_division_perf(void)
dividend_u64, divisor_u64,
nresult_u64, rresult_u64);
result = 1;
- break;
+ goto err;
}
}
printf("64bit Division results:\n");
@@ -195,6 +195,7 @@ test_reciprocal_division_perf(void)
printf("Cycles per division(reciprocal) : %3.2f\n",
((double)tot_cyc_r)/i);
+err:
return result;
}
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] test: fix division by zero
2021-04-23 7:35 [dpdk-dev] [PATCH] test: fix division by zero Min Hu (Connor)
@ 2021-05-12 16:53 ` Bruce Richardson
2021-05-13 1:11 ` Min Hu (Connor)
2021-05-13 1:10 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
1 sibling, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2021-05-12 16:53 UTC (permalink / raw)
To: Min Hu (Connor); +Cc: dev, ferruh.yigit, anatoly.burakov, thomas
On Fri, Apr 23, 2021 at 03:35:30PM +0800, Min Hu (Connor) wrote:
> Variable i is used as a denominator which may be zero, and
> this may result in segmentation fault.
>
> This patch fixed it.
>
> Fixes: 948bc3d6d095 ("test: add reciprocal based division")
> Cc: stable@dpdk.org
>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
> app/test/test_reciprocal_division_perf.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/app/test/test_reciprocal_division_perf.c b/app/test/test_reciprocal_division_perf.c
> index a7be8aa..2647308 100644
> --- a/app/test/test_reciprocal_division_perf.c
> +++ b/app/test/test_reciprocal_division_perf.c
> @@ -143,7 +143,7 @@ test_reciprocal_division_perf(void)
> "result %"PRIu64"",
> nresult_u64, rresult_u64);
> result = 1;
> - break;
> + goto err;
> }
> }
>
> @@ -182,7 +182,7 @@ test_reciprocal_division_perf(void)
> dividend_u64, divisor_u64,
> nresult_u64, rresult_u64);
> result = 1;
> - break;
> + goto err;
> }
> }
> printf("64bit Division results:\n");
> @@ -195,6 +195,7 @@ test_reciprocal_division_perf(void)
> printf("Cycles per division(reciprocal) : %3.2f\n",
> ((double)tot_cyc_r)/i);
>
> +err:
> return result;
> }
>
This looks correct as far as it goes, but I believe the same fix is needed
at lines 66 and 106 too.
One other thing I note is that currently the test will move on to the
next test case on failure, due to break, but using the goto will change
that behaviour. Therefore, I wonder if a better fix is to skip the
printouts if i == 0 in each case?
/Bruce
^ permalink raw reply [flat|nested] 6+ messages in thread
* [dpdk-dev] [PATCH v2] test: fix division by zero
2021-04-23 7:35 [dpdk-dev] [PATCH] test: fix division by zero Min Hu (Connor)
2021-05-12 16:53 ` Bruce Richardson
@ 2021-05-13 1:10 ` Min Hu (Connor)
2021-05-13 8:23 ` Bruce Richardson
1 sibling, 1 reply; 6+ messages in thread
From: Min Hu (Connor) @ 2021-05-13 1:10 UTC (permalink / raw)
To: dev; +Cc: ferruh.yigit, bruce.richardson, thomas
Variable i is used as a denominator which may be zero, and
this may result in segmentation fault.
This patch fixed it.
Fixes: 948bc3d6d095 ("test: add reciprocal based division")
Cc: stable@dpdk.org
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
v2:
* to skip the printouts if i == 0.
---
app/test/test_reciprocal_division_perf.c | 41 +++++++++++++++++++-------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/app/test/test_reciprocal_division_perf.c b/app/test/test_reciprocal_division_perf.c
index a7be8aa..4f62587 100644
--- a/app/test/test_reciprocal_division_perf.c
+++ b/app/test/test_reciprocal_division_perf.c
@@ -71,10 +71,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n\n",
- ((double)tot_cyc_r)/i);
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n\n",
+ ((double)tot_cyc_r)/i);
+ }
tot_cyc_n = 0;
tot_cyc_r = 0;
@@ -111,11 +113,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n\n",
- ((double)tot_cyc_r)/i);
-
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n\n",
+ ((double)tot_cyc_r)/i);
+ }
tot_cyc_n = 0;
tot_cyc_r = 0;
@@ -152,10 +155,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n\n",
- ((double)tot_cyc_r)/i);
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n\n",
+ ((double)tot_cyc_r)/i);
+ }
tot_cyc_n = 0;
tot_cyc_r = 0;
@@ -190,10 +195,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n",
- ((double)tot_cyc_r)/i);
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n",
+ ((double)tot_cyc_r)/i);
+ }
return result;
}
--
2.7.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH] test: fix division by zero
2021-05-12 16:53 ` Bruce Richardson
@ 2021-05-13 1:11 ` Min Hu (Connor)
0 siblings, 0 replies; 6+ messages in thread
From: Min Hu (Connor) @ 2021-05-13 1:11 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev, ferruh.yigit, anatoly.burakov, thomas
在 2021/5/13 0:53, Bruce Richardson 写道:
> On Fri, Apr 23, 2021 at 03:35:30PM +0800, Min Hu (Connor) wrote:
>> Variable i is used as a denominator which may be zero, and
>> this may result in segmentation fault.
>>
>> This patch fixed it.
>>
>> Fixes: 948bc3d6d095 ("test: add reciprocal based division")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
>> ---
>> app/test/test_reciprocal_division_perf.c | 5 +++--
>> 1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/app/test/test_reciprocal_division_perf.c b/app/test/test_reciprocal_division_perf.c
>> index a7be8aa..2647308 100644
>> --- a/app/test/test_reciprocal_division_perf.c
>> +++ b/app/test/test_reciprocal_division_perf.c
>> @@ -143,7 +143,7 @@ test_reciprocal_division_perf(void)
>> "result %"PRIu64"",
>> nresult_u64, rresult_u64);
>> result = 1;
>> - break;
>> + goto err;
>> }
>> }
>>
>> @@ -182,7 +182,7 @@ test_reciprocal_division_perf(void)
>> dividend_u64, divisor_u64,
>> nresult_u64, rresult_u64);
>> result = 1;
>> - break;
>> + goto err;
>> }
>> }
>> printf("64bit Division results:\n");
>> @@ -195,6 +195,7 @@ test_reciprocal_division_perf(void)
>> printf("Cycles per division(reciprocal) : %3.2f\n",
>> ((double)tot_cyc_r)/i);
>>
>> +err:
>> return result;
>> }
>>
> This looks correct as far as it goes, but I believe the same fix is needed
> at lines 66 and 106 too.
>
> One other thing I note is that currently the test will move on to the
> next test case on failure, due to break, but using the goto will change
> that behaviour. Therefore, I wonder if a better fix is to skip the
> printouts if i == 0 in each case?
>
Good point, fixed in v2, thanks Bruce.
> /Bruce
> .
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v2] test: fix division by zero
2021-05-13 1:10 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
@ 2021-05-13 8:23 ` Bruce Richardson
2021-05-19 7:20 ` Thomas Monjalon
0 siblings, 1 reply; 6+ messages in thread
From: Bruce Richardson @ 2021-05-13 8:23 UTC (permalink / raw)
To: Min Hu (Connor); +Cc: dev, ferruh.yigit, thomas
On Thu, May 13, 2021 at 09:10:37AM +0800, Min Hu (Connor) wrote:
> Variable i is used as a denominator which may be zero, and
> this may result in segmentation fault.
>
> This patch fixed it.
>
> Fixes: 948bc3d6d095 ("test: add reciprocal based division")
> Cc: stable@dpdk.org
>
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
> v2:
> * to skip the printouts if i == 0.
> ---
> app/test/test_reciprocal_division_perf.c | 41 +++++++++++++++++++-------------
> 1 file changed, 24 insertions(+), 17 deletions(-)
>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [dpdk-dev] [PATCH v2] test: fix division by zero
2021-05-13 8:23 ` Bruce Richardson
@ 2021-05-19 7:20 ` Thomas Monjalon
0 siblings, 0 replies; 6+ messages in thread
From: Thomas Monjalon @ 2021-05-19 7:20 UTC (permalink / raw)
To: Min Hu (Connor); +Cc: dev, ferruh.yigit, Bruce Richardson
13/05/2021 10:23, Bruce Richardson:
> On Thu, May 13, 2021 at 09:10:37AM +0800, Min Hu (Connor) wrote:
> > Variable i is used as a denominator which may be zero, and
> > this may result in segmentation fault.
> >
> > This patch fixed it.
> >
> > Fixes: 948bc3d6d095 ("test: add reciprocal based division")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> > ---
> > v2:
> > * to skip the printouts if i == 0.
> > ---
> > app/test/test_reciprocal_division_perf.c | 41 +++++++++++++++++++-------------
> > 1 file changed, 24 insertions(+), 17 deletions(-)
> >
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-05-19 7:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-23 7:35 [dpdk-dev] [PATCH] test: fix division by zero Min Hu (Connor)
2021-05-12 16:53 ` Bruce Richardson
2021-05-13 1:11 ` Min Hu (Connor)
2021-05-13 1:10 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
2021-05-13 8:23 ` Bruce Richardson
2021-05-19 7:20 ` Thomas Monjalon
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).