Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp891063yba; Thu, 18 Apr 2019 11:17:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLGJ0UK3mj60wsyqaH+fM/YL4s+5MmEA0FERQ5Szh9Eozmkx49wQZ3aacJukV/qwsWfWng X-Received: by 2002:a65:6148:: with SMTP id o8mr91088800pgv.153.1555611446645; Thu, 18 Apr 2019 11:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611446; cv=none; d=google.com; s=arc-20160816; b=w3Tc7qTYTD3KnP8qU68+HVJudNWT5m8AwRl/rzDc9VwH7IqHJm2V2WCraqrRLsSbpB 1lRpbbYoV5xdtoRySS+F2P71KMYug8giHAqH+vEojIdHUzwgO8gE7vWQaFi1RtCtRKNv 3W5Hu08T76mIZqMvIh47bTsldNRvUb6AMg13nbfO3AaboUB8V34CwJ46kGgcZZw+AK2f 5A/TRIVNyfnLpJzAy1p0yP04LwmOjLxivlJrXdzavm/r3rP+yKH5KzwXEE83FM/8UFqb x1SFsNqAiQZdKKrbt58JdCDv7nNfcG2DEpfhGYA4kp1ZIQ4QnGMj3C0NLLjdK429C/s9 jMdg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RL6lcf1upUAefNLUa1l+UYeVlOm1nucFXdHmeLi2Aqs=; b=TManZwy7uvLHkbKccQcf3nGrliEYOzfm5OaWM06WjbXeBEzk6Hk66e0OhX9Lk0yoEu Gl3vslFfvqGND/OGMWlmE0yWsjt1Gb+/j1MD6ufr973tyRsBI8OY7h2fJVdt/kRfOYn0 B33vOjgyq/4Go+9xylR0kpNdRbwsVMgppQLkaOerqg+FRuRv1XtFyyppNzOLdpgwfRFF RJ1dxae2ovutTlDGz36l+oaI6IyT4IlU3sZvrf3bUXnbfsfWLNLTMDgNWj2aCHDLwhO7 vlLmlXN3Bw7+lM7bueGsbjAcYVTjWWiX9VogTFuxpGyZ/z4VY1vu0IpIT50WdSZzOkJS ybVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JpmsM9vj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si2856675pfh.162.2019.04.18.11.17.11; Thu, 18 Apr 2019 11:17:26 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=JpmsM9vj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404173AbfDRSM5 (ORCPT + 99 others); Thu, 18 Apr 2019 14:12:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:45514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404351AbfDRSMy (ORCPT ); Thu, 18 Apr 2019 14:12:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2277121871; Thu, 18 Apr 2019 18:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555611173; bh=nACJVCZPYKuwKcjuFEBrHctyut3FoHo30skNPHK7+ss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JpmsM9vjJevdWlILdX98/vv7xen/Dnagf0+W4ZTzjaIa2vhPhDSKLq75TE/vzDxT+ YliYlXB6ySKRPsisGWnzOaNuhPXIQe0L9ghihN3cMWmp7Li1NHQdc+/GIw+Gt7mnB6 6+t2Hd/31uGhg7kOKNvPTOW/u2GknnXUrlrdHToA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stanislaw Gruszka , Siarhei Volkau , Oleg Nesterov , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.0 86/93] lib/div64.c: off by one in shift Date: Thu, 18 Apr 2019 19:58:04 +0200 Message-Id: <20190418160445.542131030@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160436.781762249@linuxfoundation.org> References: <20190418160436.781762249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit cdc94a37493135e355dfc0b0e086d84e3eadb50d ] fls counts bits starting from 1 to 32 (returns 0 for zero argument). If we add 1 we shift right one bit more and loose precision from divisor, what cause function incorect results with some numbers. Corrected code was tested in user-space, see bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=202391 Link: http://lkml.kernel.org/r/1548686944-11891-1-git-send-email-sgruszka@redhat.com Fixes: 658716d19f8f ("div64_u64(): improve precision on 32bit platforms") Signed-off-by: Stanislaw Gruszka Reported-by: Siarhei Volkau Tested-by: Siarhei Volkau Acked-by: Oleg Nesterov Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- lib/div64.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/div64.c b/lib/div64.c index 01c8602bb6ff..ee146bb4c558 100644 --- a/lib/div64.c +++ b/lib/div64.c @@ -109,7 +109,7 @@ u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder) quot = div_u64_rem(dividend, divisor, &rem32); *remainder = rem32; } else { - int n = 1 + fls(high); + int n = fls(high); quot = div_u64(dividend >> n, divisor >> n); if (quot != 0) @@ -147,7 +147,7 @@ u64 div64_u64(u64 dividend, u64 divisor) if (high == 0) { quot = div_u64(dividend, divisor); } else { - int n = 1 + fls(high); + int n = fls(high); quot = div_u64(dividend >> n, divisor >> n); if (quot != 0) -- 2.19.1