Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2397192ybl; Mon, 20 Jan 2020 02:06:47 -0800 (PST) X-Google-Smtp-Source: APXvYqxxYL47wQjnC0TReWaV1XcWQPPO4uZ6MKnZlFZAWHtCkF6OHU0bUn1nckTdsTaGpYL35KKa X-Received: by 2002:aca:f1d4:: with SMTP id p203mr12126395oih.116.1579514807396; Mon, 20 Jan 2020 02:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579514807; cv=none; d=google.com; s=arc-20160816; b=e0bptsqFymVNPNldsA+cJaJVZUysp9G6vzGBmzZeNqajroktP5AZ7faBb2HUr9MaNC /Scfky3VrshmE2K9HF5NdG7IdO0HAcH3lJwMY5AU+YqB5xuC684hiz/bSUDbvKY9vSsx t+4a421RmBdSrJnBa+LBCSBsZSGyHNEOBovfP5CUfTJYpTtPKts/t0O61zqGdHG57TnH LW92dwCnae9gz50ug+3+OflaB1xybeM2t0YUeZCFFxbxxqQJ6o1KYXdiXK4RuM7DKkWs A6PotfoW5/KRjPYBprSA/jkoYA2ZdQKMx+LjN+NiaNPBVqEbzTlWJp3BN73uw0Ejszm+ Cmvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=KeUneX0KiT8MqfkzwmrDMGwJ8J60BMYWvtDVEk5hfR0=; b=Adtv3KAA7OHmUVQvdRvkLPEO//3wOLkt2T8u6f5Mpvm9h4QG3MDmUzmMxpdk+wIrcn BVyPInmyNTPwHkC3aLFCqXZlD2h85DPXjwNnqP70TZ/Me2JdoYviLb45r0rTKQQGcorU hC6LjniyTWj7JtvW/bCWyfJZApG1XAEMZqiIwkHRAOL5NCPtOH3oOPVJfcB9+GpY+iG4 TvQnIp6GUJLQKyTgTS1hECKjyh/h74scFcYUc2yEsFA48NRVH8QdN/w4/7Ek5F3OxVyK aYlYPSHwtU133LoTafpP/loGWq49UfdcehPdhY/v8iShYQfSCnHXptZXo8ATZJUREY/b KbEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si18052270otn.108.2020.01.20.02.06.35; Mon, 20 Jan 2020 02:06:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727580AbgATKFg (ORCPT + 99 others); Mon, 20 Jan 2020 05:05:36 -0500 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:57535 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726075AbgATKFg (ORCPT ); Mon, 20 Jan 2020 05:05:36 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0ToDeF5-_1579514727; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0ToDeF5-_1579514727) by smtp.aliyun-inc.com(127.0.0.1); Mon, 20 Jan 2020 18:05:34 +0800 From: Wen Yang To: John Stultz , Thomas Gleixner Cc: Wen Yang , Stephen Boyd , linux-kernel@vger.kernel.org Subject: [PATCH] timekeeping: improve arithmetic division in scale64_check_overflow() Date: Mon, 20 Jan 2020 18:05:23 +0800 Message-Id: <20200120100523.45656-1-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org do_div() does a 64-by-32 division. Use div64_u64() instead of it if the divisor is u64, to avoid truncation to 32-bit. And as a nice side effect also cleans up the function a bit. Signed-off-by: Wen Yang Cc: John Stultz Cc: Thomas Gleixner Cc: Stephen Boyd Cc: linux-kernel@vger.kernel.org --- kernel/time/timekeeping.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ca69290bee2a..4fc2af4367a7 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1005,9 +1005,8 @@ static int scale64_check_overflow(u64 mult, u64 div, u64 *base) ((int)sizeof(u64)*8 - fls64(mult) < fls64(rem))) return -EOVERFLOW; tmp *= mult; - rem *= mult; - do_div(rem, div); + rem = div64_u64(rem * mult, div); *base = tmp + rem; return 0; } -- 2.23.0