Skip to content

Commit c0c1a6b

Browse files
Vitaliy Shevtsovhverkuil
authored andcommitted
media: cec: use us_to_ktime() where appropriate
[Why] There are several ns_to_ktime() calls that require using nanoseconds. It is better to replace them with us_to_ktime() to make code clear, getting rid of multiplication by 1000. Also the timer function code may have an integer wrap-around issue. Since both tx_custom_low_usecs and tx_custom_high_usecs can be set to up to 9999999 from the user space via cec_pin_error_inj_parse_line(), this may cause usecs to be overflowed when adap->monitor_pin_cnt is zero and usecs is multiplied by 1000. [How] Take advantage of using an appropriate helper func us_to_ktime() instead of ns_to_ktime() to improve readability and to make the code clearer. And this also mitigates possible integer wrap-arounds when usecs value is too large and it is multiplied by 1000. Found by Linux Verification Center (linuxtesting.org) with Svace. Signed-off-by: Vitaliy Shevtsov <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent e49563c commit c0c1a6b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/media/cec/core/cec-pin.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,19 +873,19 @@ static enum hrtimer_restart cec_pin_timer(struct hrtimer *timer)
873873
if (pin->wait_usecs > 150) {
874874
pin->wait_usecs -= 100;
875875
pin->timer_ts = ktime_add_us(ts, 100);
876-
hrtimer_forward_now(timer, ns_to_ktime(100000));
876+
hrtimer_forward_now(timer, us_to_ktime(100));
877877
return HRTIMER_RESTART;
878878
}
879879
if (pin->wait_usecs > 100) {
880880
pin->wait_usecs /= 2;
881881
pin->timer_ts = ktime_add_us(ts, pin->wait_usecs);
882882
hrtimer_forward_now(timer,
883-
ns_to_ktime(pin->wait_usecs * 1000));
883+
us_to_ktime(pin->wait_usecs));
884884
return HRTIMER_RESTART;
885885
}
886886
pin->timer_ts = ktime_add_us(ts, pin->wait_usecs);
887887
hrtimer_forward_now(timer,
888-
ns_to_ktime(pin->wait_usecs * 1000));
888+
us_to_ktime(pin->wait_usecs));
889889
pin->wait_usecs = 0;
890890
return HRTIMER_RESTART;
891891
}
@@ -1020,13 +1020,12 @@ static enum hrtimer_restart cec_pin_timer(struct hrtimer *timer)
10201020
if (!adap->monitor_pin_cnt || usecs <= 150) {
10211021
pin->wait_usecs = 0;
10221022
pin->timer_ts = ktime_add_us(ts, usecs);
1023-
hrtimer_forward_now(timer,
1024-
ns_to_ktime(usecs * 1000));
1023+
hrtimer_forward_now(timer, us_to_ktime(usecs));
10251024
return HRTIMER_RESTART;
10261025
}
10271026
pin->wait_usecs = usecs - 100;
10281027
pin->timer_ts = ktime_add_us(ts, 100);
1029-
hrtimer_forward_now(timer, ns_to_ktime(100000));
1028+
hrtimer_forward_now(timer, us_to_ktime(100));
10301029
return HRTIMER_RESTART;
10311030
}
10321031

0 commit comments

Comments
 (0)