From patchwork Tue Jun 25 10:05:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vinod Koul X-Patchwork-Id: 167689 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp5347403ilk; Tue, 25 Jun 2019 03:08:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyN/BxyWAemTeb0bQZI6nDgwn4DZ9lB3N+/3YcmtRq07ysXAPIH9AJddWCPzbp75A2VXEF5 X-Received: by 2002:a17:902:6848:: with SMTP id f8mr23275261pln.102.1561457321910; Tue, 25 Jun 2019 03:08:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561457321; cv=none; d=google.com; s=arc-20160816; b=o8eraQLKPAGAv7uha1sRrtkDNDBYOqMYtlFFkzqm8L1WvbztpXCTcpTayuWRR7bRiv ah4A6IjlRaovqiuSHBRvcr0L9c9VBNE81LpVhvuZCWWXk+jUFsbD4Tt1hmSTWBEjq/+W fRok320ESys62tqnSi37G53KebLLclSdb2LgrHPTbcyfacLqaH1ND97U+hXPu5N/xD0c uDWkP8CxaeD0NelqwWJElerBNeS52VNLvaVFp0092zdDBawE/RQkLe6rvCDAM6qOtwXZ CRytrBCCak8sOxJ8jwpFteIsZhHxnXHydq1Ddy7P7OVcK9X7ZRTcBfmVDwDZBPxAvZLV Kpsg== 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:dkim-signature; bh=TpFeSOGKFw9f/btEFNs21YhcNNNzrYPDPFswBYaVGiY=; b=wk7yZOSMtSslE8aXqO3b1dU6VmuCN3QuQFuTV+1vSaJHRYbH6goWCaZonXt5l6qRoJ NBdlBU4aBc2W8fV7i7e47MRIbhhChZhRcbE5PFZJ+R76Y38lrXbapHVvHaE4O3neqhy+ 5os4E4NP+zA0h1F/jsrLO+WGqbaiKCP3oUsHVDnEtzflCcDeecG2mOILekmt+0GqXwY7 wk5wqBcs7YnU4BGKLgrh53qyBjMDMVB3JJ8PSb/mroKluGb2fYf5PrWb3ol31xEg+zsd uGAgRSw/p1aPVKWndSToxmyAN20HHRDw6RWYmUGKGH//F2t4er6UZe3EmsMtp9BYOil6 dK/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="sO8n/Uql"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v19si2375803pjn.96.2019.06.25.03.08.41; Tue, 25 Jun 2019 03:08:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-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="sO8n/Uql"; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727463AbfFYKIl (ORCPT + 15 others); Tue, 25 Jun 2019 06:08:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:38832 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726827AbfFYKIl (ORCPT ); Tue, 25 Jun 2019 06:08:41 -0400 Received: from localhost.localdomain (unknown [106.201.40.23]) (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 436FD20644; Tue, 25 Jun 2019 10:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561457320; bh=SB0OifcBQQeaDTYy5h5HoqPRk/EuvqCl4qAhEEhDDoI=; h=From:To:Cc:Subject:Date:From; b=sO8n/UqlxK/WthcAyh59xyqW3dNdUNJQMjxDdaWM9FBFlQroBZnBKecPVpKbf1U3I 5IUlLiqbyvIK//yuz267HmhjHVcgwpHE6LS1iriSKljzRQYhulhQuFeDH1Fm4Dtgj0 z/fXhQYiJsjww6GKLUjXswZ+LkCXAmlVj0VIxDkc= From: Vinod Koul To: Andrew Morton Cc: linux-arm-msm@vger.kernel.org, Bjorn Andersson , Vinod Koul , Randy Dunlap , linux-kernel@vger.kernel.org Subject: [PATCH] linux/kernel.h: fix overflow for DIV_ROUND_UP_ULL Date: Tue, 25 Jun 2019 15:35:18 +0530 Message-Id: <20190625100518.30753-1-vkoul@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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. Signed-off-by: Vinod Koul --- include/linux/kernel.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.20.1 Signed-off-by: Andrew Morton Reviewed-by: Vinod Koul Tested-by: Vinod Koul diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 74b1ee9027f5..1214fb48cfc8 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -93,7 +93,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)