Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp1801468ybm; Thu, 23 May 2019 07:01:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqyc+qLD0Vl4FVcnqVqamFgY5F/PhcwExrW9rKmJdfxERc6M0VegETsgXPK1JFWea87sJJ1N X-Received: by 2002:a63:5211:: with SMTP id g17mr67026946pgb.405.1558620105004; Thu, 23 May 2019 07:01:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558620104; cv=none; d=google.com; s=arc-20160816; b=spDW2G4opwacFxMqR6jUoDhzRFrQidBk+m4YSALdq/6afxWZOaZ5Dj7am9qhFr8XKr RV3J+WJrdCCQnAlYkQUb6U69OlyH9gQOCb2Q0a+uFWYMoxBYWpDFSHgY/ogxKCoQhbRs o1k1LEBknLIbqqSt4LAgmiCiUDVrDOKivtrS5VPa1l+Oqno6O5BvL0e+buNLZnm+BAnz F3Ckez/og2n43YF3boiFmwVoPDZ1JrpTWZMHb/9kiYO6a3rmcIH2TeHqP8YXuZNUyoQo X/p4ofKY2vIZIQvqxqaNU3lMa3BmpFpHropnwbYiATdW2QpHGN+IeGxWyiWq6UYbmNJ1 RD1A== 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:subject:cc:to:from:date; bh=ot4sZp58UEubpfxT+ZuNJ1nmuyPQop0lwNxLdcuK6Yc=; b=ojjPR/qgApG8crwO2KkrrE18orlGVgVhLMh8XiFDGNn5aksYo9KKD3I64v8TOEihQy vnkUq+nIg2ZLZLWt2fxD2XBChzgQF4Mma3xixTjHUEyivmDNp08cTwVaK06zjHTF9bkx pTSZXu+sIvPNGOZhWsBuIlz+7elJ3SwEPns2mM+aURDKNS/qw23neM0SCFPtojr9kS/H 4TZHhw9K4c5vFb6CJ2gUPEQEITKqcHk4jKOyCaGp3av+/aEuHlErw3BzeW3CemWrFRZp 4mtixMwNB8FCS9+k+XYD7wBLBxFwnQUnYhVGsHjs+m4RDfeG9enBrU2ilcNVrcUP90As Gc8g== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 65si29416607plb.39.2019.05.23.07.01.25; Thu, 23 May 2019 07:01:44 -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; 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 S1730741AbfEWOAQ (ORCPT + 99 others); Thu, 23 May 2019 10:00:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:52550 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730323AbfEWOAQ (ORCPT ); Thu, 23 May 2019 10:00:16 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (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 B777F2133D; Thu, 23 May 2019 14:00:14 +0000 (UTC) Date: Thu, 23 May 2019 10:00:13 -0400 From: Steven Rostedt To: LKML Cc: Ben Skeggs , David Airlie , Daniel Vetter , Leon Romanovsky , Doug Ledford , Jason Gunthorpe , "Darrick J. Wong" , linux-xfs@vger.kernel.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-rdma@vger.kernel.org, Linus Torvalds , Andrew Morton Subject: [RFC][PATCH] kernel.h: Add generic roundup_64() macro Message-ID: <20190523100013.52a8d2a6@gandalf.local.home> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) In discussing a build failure on x86_32 due to the use of roundup() on a 64 bit number, I realized that there's no generic equivalent roundup_64(). It is implemented in two separate places in the kernel, but there really should be just one that all can use. Although the other implementations are a static inline function, this implementation is a macro to allow the use of typeof(x) to denote the type that is being used. If the build is on a 64 bit machine, then the roundup_64() macro will just default back to roundup(). But for 32 bit machines, it will use the version that is will not cause issues with dividing a 64 bit number on a 32 bit machine. Link: http://lkml.kernel.org/r/20190522145450.25ff483d@gandalf.local.home Signed-off-by: Steven Rostedt (VMware) --- diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c index 34a998012bf6..cdacfe1f732c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bo.c +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c @@ -143,14 +143,6 @@ nouveau_bo_del_ttm(struct ttm_buffer_object *bo) kfree(nvbo); } -static inline u64 -roundup_64(u64 x, u32 y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - static void nouveau_bo_fixup_align(struct nouveau_bo *nvbo, u32 flags, int *align, u64 *size) diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h index edbd5a210df2..13de9d49bd52 100644 --- a/fs/xfs/xfs_linux.h +++ b/fs/xfs/xfs_linux.h @@ -207,13 +207,6 @@ static inline xfs_dev_t linux_to_xfs_dev_t(dev_t dev) #define xfs_sort(a,n,s,fn) sort(a,n,s,fn,NULL) #define xfs_stack_trace() dump_stack() -static inline uint64_t roundup_64(uint64_t x, uint32_t y) -{ - x += y - 1; - do_div(x, y); - return x * y; -} - static inline uint64_t howmany_64(uint64_t x, uint32_t y) { x += y - 1; diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 74b1ee9027f5..cd0063629357 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -115,6 +115,20 @@ (((x) + (__y - 1)) / __y) * __y; \ } \ ) + +#if BITS_PER_LONG == 32 +# define roundup_64(x, y) ( \ +{ \ + typeof(y) __y = y; \ + typeof(x) __x = (x) + (__y - 1); \ + do_div(__x, __y); \ + __x * __y; \ +} \ +) +#else +# define roundup_64(x, y) roundup(x, y) +#endif + /** * rounddown - round down to next specified multiple * @x: the value to round