Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <v.shevtsov@mt-integration.ru>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>

authored by

Vitaliy Shevtsov and committed by
Hans Verkuil
c0c1a6bf e49563c3

+5 -6
+5 -6
drivers/media/cec/core/cec-pin.c
··· 873 873 if (pin->wait_usecs > 150) { 874 874 pin->wait_usecs -= 100; 875 875 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)); 877 877 return HRTIMER_RESTART; 878 878 } 879 879 if (pin->wait_usecs > 100) { 880 880 pin->wait_usecs /= 2; 881 881 pin->timer_ts = ktime_add_us(ts, pin->wait_usecs); 882 882 hrtimer_forward_now(timer, 883 - ns_to_ktime(pin->wait_usecs * 1000)); 883 + us_to_ktime(pin->wait_usecs)); 884 884 return HRTIMER_RESTART; 885 885 } 886 886 pin->timer_ts = ktime_add_us(ts, pin->wait_usecs); 887 887 hrtimer_forward_now(timer, 888 - ns_to_ktime(pin->wait_usecs * 1000)); 888 + us_to_ktime(pin->wait_usecs)); 889 889 pin->wait_usecs = 0; 890 890 return HRTIMER_RESTART; 891 891 } ··· 1020 1020 if (!adap->monitor_pin_cnt || usecs <= 150) { 1021 1021 pin->wait_usecs = 0; 1022 1022 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)); 1025 1024 return HRTIMER_RESTART; 1026 1025 } 1027 1026 pin->wait_usecs = usecs - 100; 1028 1027 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)); 1030 1029 return HRTIMER_RESTART; 1031 1030 } 1032 1031