From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B307CC76186 for ; Thu, 18 Jul 2019 03:06:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E99B21841 for ; Thu, 18 Jul 2019 03:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419201; bh=EVusKffBVu8ERw1y8wdsB9QLIF/vjsr8TRZpFxqs4+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=LPJ01EM286uGzp31thlQZ+gLlJVe+OeWf3bOXAGL4f1322p0IBeRtdP0r0tOrGjSu xMvZ+4eq/+EaD1I/oi0op/8RLZSCwK3560yVL8KH+CZBz9jaAdLq/hs02NcsAgoYak YrDEZoabTPmW7VLjIcYP4AZb0GwIoawAfx0Alqg8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390230AbfGRDGb (ORCPT ); Wed, 17 Jul 2019 23:06:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390218AbfGRDG2 (ORCPT ); Wed, 17 Jul 2019 23:06:28 -0400 Received: from localhost (115.42.148.210.bf.2iij.net [210.148.42.115]) (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 890252053B; Thu, 18 Jul 2019 03:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419187; bh=EVusKffBVu8ERw1y8wdsB9QLIF/vjsr8TRZpFxqs4+Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LUZ7xPjSAa4lyLw2bmjfhTvK+SrtSn3HJV7g05ezYsTxruDrUB+5OQDRT56yfpM11 P0PtAVadWcIknKzdLbJXh9kDr9+RMWngsViCHacXU9CjS64oozpA+4MZSYNRYH1rN1 t3EV6Jq5lUNBvL5XQygnujrcD0FB1svOIdB21uto= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vinod Koul , Andrew Morton , Bjorn Andersson , Randy Dunlap , Linus Torvalds , Sasha Levin Subject: [PATCH 5.1 40/54] linux/kernel.h: fix overflow for DIV_ROUND_UP_ULL Date: Thu, 18 Jul 2019 12:01:35 +0900 Message-Id: <20190718030056.293165729@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030053.287374640@linuxfoundation.org> References: <20190718030053.287374640@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 8f9fab480c7a87b10bb5440b5555f370272a5d59 ] DIV_ROUND_UP_ULL adds the two arguments and then invokes DIV_ROUND_DOWN_ULL. But on a 32bit system the addition of two 32 bit values can overflow. DIV_ROUND_DOWN_ULL does it correctly and stashes the addition into a unsigned long long so cast the result to unsigned long long here to avoid the overflow condition. [akpm@linux-foundation.org: DIV_ROUND_UP_ULL must be an rval] Link: http://lkml.kernel.org/r/20190625100518.30753-1-vkoul@kernel.org Signed-off-by: Vinod Koul Reviewed-by: Andrew Morton Cc: Bjorn Andersson Cc: Randy Dunlap Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- include/linux/kernel.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 2d14e21c16c0..4330cecd2237 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -92,7 +92,8 @@ #define DIV_ROUND_DOWN_ULL(ll, d) \ ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; }) -#define DIV_ROUND_UP_ULL(ll, d) DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d)) +#define DIV_ROUND_UP_ULL(ll, d) \ + DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d)) #if BITS_PER_LONG == 32 # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) -- 2.20.1