From patchwork Fri May 1 17:46:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 47896 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6E9DC2121F for ; Fri, 1 May 2015 17:46:56 +0000 (UTC) Received: by wgiv13 with SMTP id v13sf29385853wgi.3 for ; Fri, 01 May 2015 10:46:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=wcTw+K3vLbNOZLC2il63ovZTQ9z3ynAgu34qdj/DK0c=; b=GqsxG06VMgEObIM0NUvBwLELjcRQDGxZwdkAPUBnV/yYxaZ3yeveMh3PGofuld0L1z 64nmxA/6A48dWdg7Otihz1Zgf8Zd3wUj06mzGge34cgULtNOyrczatsLR8XzV+Z1Ez4Y 1UpR+pJNjfK2ajHiE35Kxa9QFqogQSLKZNHQt53Z+gfb5eKAPqYGXbFiPUkpNMlNE2M4 BW41sEF0jNhyy9qkrV1b+8I7H78TTIwkDMaidnKKYkO2dVre07Cyo15VdsxEv0tMO7zs o9Sp7ytian36PzeB5r6yLc+fOOVPUxknetgyzCr/ClyyJhA79e0tQUlwYDwwRT+59VL9 9TsQ== X-Gm-Message-State: ALoCoQmOMLulerU6bBnvQsxavva3c9zr63EFl3eJBV3POJT0rkJFyXfEIVOgbzhZEoccUDVYOKYf X-Received: by 10.180.96.6 with SMTP id do6mr8418488wib.4.1430502412829; Fri, 01 May 2015 10:46:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.121.98 with SMTP id lj2ls509576lab.94.gmail; Fri, 01 May 2015 10:46:52 -0700 (PDT) X-Received: by 10.152.182.167 with SMTP id ef7mr9109897lac.109.1430502412603; Fri, 01 May 2015 10:46:52 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id i4si4407614laf.44.2015.05.01.10.46.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 May 2015 10:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbcga7 with SMTP id ga7so69026219lbc.1 for ; Fri, 01 May 2015 10:46:52 -0700 (PDT) X-Received: by 10.152.2.227 with SMTP id 3mr8967037lax.73.1430502412470; Fri, 01 May 2015 10:46:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.67.65 with SMTP id l1csp413372lbt; Fri, 1 May 2015 10:46:51 -0700 (PDT) X-Received: by 10.67.13.140 with SMTP id ey12mr20147843pad.67.1430502410684; Fri, 01 May 2015 10:46:50 -0700 (PDT) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com. [209.85.220.52]) by mx.google.com with ESMTPS id pp4si8837968pbb.58.2015.05.01.10.46.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 May 2015 10:46:50 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.52 as permitted sender) client-ip=209.85.220.52; Received: by pacwv17 with SMTP id wv17so96820138pac.0 for ; Fri, 01 May 2015 10:46:49 -0700 (PDT) X-Received: by 10.67.3.3 with SMTP id bs3mr9074999pad.51.1430502409676; Fri, 01 May 2015 10:46:49 -0700 (PDT) Received: from localhost.localdomain (c-67-170-153-23.hsd1.or.comcast.net. [67.170.153.23]) by mx.google.com with ESMTPSA id y2sm5410578pbt.46.2015.05.01.10.46.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 01 May 2015 10:46:48 -0700 (PDT) From: John Stultz To: Trevor Cordes Cc: John Stultz Subject: [PATCH v3.19] ktime: Fix ktime_divns to do signed division Date: Fri, 1 May 2015 10:46:45 -0700 Message-Id: <1430502405-13378-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 1.9.1 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: john.stultz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , It was noted that the 32bit implementation of ktime_divns was doing unsgined division adn didn't properly handle negative values. This patch fixes the problem by checking and preserving the sign bit, and then reapplying it if appropriate after the division. Reported-by: Trevor Cordes Signed-off-by: John Stultz --- kernel/time/hrtimer.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c index d8c724c..aaf44a07 100644 --- a/kernel/time/hrtimer.c +++ b/kernel/time/hrtimer.c @@ -266,12 +266,17 @@ lock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags) /* * Divide a ktime value by a nanosecond value */ -u64 ktime_divns(const ktime_t kt, s64 div) +s64 ktime_divns(const ktime_t kt, s64 div) { - u64 dclc; + s64 dclc; int sft = 0; + int neg = 0; dclc = ktime_to_ns(kt); + if (dclc < 0) { + neg = 1; + dclc = -dclc; + } /* Make sure the divisor is less than 2^32: */ while (div >> 32) { sft++; @@ -280,6 +285,8 @@ u64 ktime_divns(const ktime_t kt, s64 div) dclc >>= sft; do_div(dclc, (unsigned long) div); + if (neg) + dclc = -dclc; return dclc; } EXPORT_SYMBOL_GPL(ktime_divns);