Patch "[PKT_SCHED]: PSCHED_TADD() and PSCHED_TADD2() can result,tv_usec >= 1000000" seems wrong
Subsystems (3)
Hello,
looks wrong.
In PSCHED_TADD2, if delta is less than tv.tv_usec (so, less than USEC_PER_SEC too) then tv_res will be before tv. The affectation (tv_res).tv_usec = __delta; is wrong. The same applies to PSCHED_TADD.
I think the correct fix is simply to restore the original code and change the 'if' in a 'while'.
So here are two patches for the two possible solutions :
o Reverting the commit and applying from_before_patch_to_correct.diff
o Applying from_tip_to_correct.diff
Thanks.
Signature · 1 line
Guillaume
include/net/pkt_sched.h renamed from include/net/pkt_sched.h.before +2 -2
@@ -171,14 +171,14 @@ ({ \int __delta = (tv).tv_usec + (delta); \ (tv_res).tv_sec = (tv).tv_sec; \ -if (__delta >USEC_PER_SEC ) { (tv_res).tv_sec++; __delta -=USEC_PER_SEC ; } \ +while (__delta >USEC_PER_SEC ) { (tv_res).tv_sec++; __delta -=USEC_PER_SEC ; } \ (tv_res).tv_usec = __delta; \ })#define PSCHED_TADD (tv, delta) \ ({ \ (tv).tv_usec += (delta); \ - if ((tv).tv_usec > USEC_PER_SEC) { (tv).tv_sec++; \ + while ((tv).tv_usec > USEC_PER_SEC) { (tv).tv_sec++; \ (tv).tv_usec -= USEC_PER_SEC; } \ })
Signature · 1 line
Signed-off-by: Guillaume Chazarain <[email protected]>
include/net/pkt_sched.h +6 -12
@@ -169,23 +169,17 @@ psched_tod_diff(int delta_sec, int bound#define PSCHED_TADD2 (tv, delta, tv_res) \ ({ \ - int __delta = (delta); \ - (tv_res) = (tv); \ - while(__delta >= USEC_PER_SEC){ \ - (tv_res).tv_sec++; \ - __delta -= USEC_PER_SEC; \ - } \ + int __delta = (tv).tv_usec + (delta); \ + (tv_res).tv_sec = (tv).tv_sec; \ + while (__delta > USEC_PER_SEC) { (tv_res).tv_sec++; __delta -= USEC_PER_SEC; } \ (tv_res).tv_usec = __delta; \ })#define PSCHED_TADD (tv, delta) \ ({ \ - int __delta = (delta); \ - while(__delta >= USEC_PER_SEC){ \ - (tv).tv_sec++; \ - __delta -= USEC_PER_SEC; \ - } \ - (tv).tv_usec = __delta; \ + (tv).tv_usec += (delta); \ + while ((tv).tv_usec > USEC_PER_SEC) { (tv).tv_sec++; \ + (tv).tv_usec -= USEC_PER_SEC; } \ })/* Set/check that time is in the "past perfect";
Signature · 1 line
Signed-off-by: Guillaume Chazarain <[email protected]>
Hello.
Quoted 2 lines
In
PSCHED_TADD2, if delta is less than tv.tv_usec (so, less thanUSEC_PER_SECtoo) thentv_reswill be before tv. The affectation (tv_res).tv_usec =__delta; is wrong. The same applies toPSCHED_TADD.
You are right. It is my mistake.
Quoted 1 line
I think the correct fix is simply to restore the original code and change the 'if' in a 'while'.
In Guillaume's patch,
"while (__delta > USEC_PER_SEC){ ... }", but I think it should be "while (__delta >= USEC_PER_SEC){ ... }". Is it right?
Thank you very much.
Signature · 1 line
Shuya MAEDA
Quoted 2 lines · Shuya MAEDA
"while (
__delta> USEC_PER_SEC){ ... }", but I think it should be "while (__delta>= USEC_PER_SEC){ ... }". Is it right?
I agree, good catch :-)
Thanks.
Signature · 1 line
Guillaume
In PSCHED_TADD and PSCHED_TADD2, if delta is less than tv.tv_usec (so, less than USEC_PER_SEC too) then tv_res will be smaller than tv. The affectation "(tv_res).tv_usec = __delta;" is wrong.
The fix is to revert to the original code before 4ee303dfeac6451b402e3d8512723d3a0f861857 and change the 'if' in 'while'.
[Shuya MAEDA: "while (__delta >= USEC_PER_SEC){ ... }" instead of "while (__delta > USEC_PER_SEC){ ... }"]
---
pkt_sched.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
include/net/pkt_sched.h +6 -12
@@ -169,23 +169,17 @@ psched_tod_diff(int delta_sec, int bound#define PSCHED_TADD2 (tv, delta, tv_res) \ ({ \ - int __delta = (delta); \ - (tv_res) = (tv); \ - while(__delta >= USEC_PER_SEC){ \ - (tv_res).tv_sec++; \ - __delta -= USEC_PER_SEC; \ - } \ + int __delta = (tv).tv_usec + (delta); \ + (tv_res).tv_sec = (tv).tv_sec; \ + while (__delta >= USEC_PER_SEC) { (tv_res).tv_sec++; __delta -= USEC_PER_SEC; } \ (tv_res).tv_usec = __delta; \ })#define PSCHED_TADD (tv, delta) \ ({ \ - int __delta = (delta); \ - while(__delta >= USEC_PER_SEC){ \ - (tv).tv_sec++; \ - __delta -= USEC_PER_SEC; \ - } \ - (tv).tv_usec = __delta; \ + (tv).tv_usec += (delta); \ + while ((tv).tv_usec >= USEC_PER_SEC) { (tv).tv_sec++; \ + (tv).tv_usec -= USEC_PER_SEC; } \ })/* Set/check that time is in the "past perfect";
From: Guillaume Chazarain <[email protected]>
Date: Wed, 19 Jul 2006 14:47:34 +0200
Quoted 5 lines
Quoted 2 lines · Shuya MAEDA
"while (
__delta> USEC_PER_SEC){ ... }", but I think it should be "while (__delta>= USEC_PER_SEC){ ... }". Is it right?I agree, good catch :-)
Applied, thanks a lot.