From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753258AbbJaKVm (ORCPT ); Sat, 31 Oct 2015 06:21:42 -0400 Received: from [119.145.14.65] ([119.145.14.65]:63179 "EHLO szxga02-in.huawei.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752858AbbJaKVl (ORCPT ); Sat, 31 Oct 2015 06:21:41 -0400 Subject: [PATCH resend] clocksource: modify the cycle_last validation to fit for non-64bit clocksourece mask To: Thomas Gleixner References: <1445952073-7260-1-git-send-email-yangyingliang@huawei.com> <1445952073-7260-2-git-send-email-yangyingliang@huawei.com> CC: , From: Yang Yingliang Message-ID: <56349607.6070708@huawei.com> Date: Sat, 31 Oct 2015 18:20:55 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.19.219] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Yingliang Check the delta of now and last to make sure it's not negative while the clocksource mask is not 64-bits. Suggested-by: Thomas Gleixner Signed-off-by: Yang Yingliang --- kernel/time/timekeeping_internal.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/time/timekeeping_internal.h b/kernel/time/timekeeping_internal.h index 4ea005a..cbfcd2d 100644 --- a/kernel/time/timekeeping_internal.h +++ b/kernel/time/timekeeping_internal.h @@ -16,8 +16,9 @@ extern void tk_debug_account_sleep_time(struct timespec64 *t); static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask) { cycle_t ret = (now - last) & mask; + cycle_t negative = ret & ~(mask >> 1); - return (s64) ret > 0 ? ret : 0; + return negative ? 0 : ret; } #else static inline cycle_t clocksource_delta(cycle_t now, cycle_t last, cycle_t mask) -- 2.5.0