Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2280785ybm; Thu, 23 May 2019 14:23:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzr2SXzPGLzMKEgQc/dtr1X2hnGuyRFKV+rUyxZ3HLcmKrPukUBlsUT2N43XOxCFoffKB9b X-Received: by 2002:a17:90a:35c:: with SMTP id 28mr4225638pjf.110.1558646589462; Thu, 23 May 2019 14:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558646589; cv=none; d=google.com; s=arc-20160816; b=Akb0nDcLPPNoPpyl8klsSOMaOvRJ+sFxT2MCK0i5fAc79mpqGXpMCH645dPY3tjqT8 hAbGyaW+zKQW43l30tWnF+1jhWFzXSbwRcLpGmBD6Oe8NwPxNSSJQB2tSq+J7ZPIrMer sBxMIvxugxhQBNpV+Nh22OnCMMEIOwQDsRl2vv/eeQex9vHCW3895jRH9xz90pEy3jMf N7kYxQt0KUuVgmhFt/JjYsR23s3tNlboN81uqKQDyA+3LXSu18ENovAvjjeciaa4fcZi m1pzApRB2YJquRYN9OkhOQLjcteMj0k3vGaVDsjfF6ixJTj4B7djuNVylIx7793CE/WU SLng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zDS3Ns71UvqAxo/Ziy/UlngEZ1rvpeIhNyX6PGvAAp8=; b=p01dENcR2wow+ewynjvFI8hfVsEY/ixKtGCnxx3QRtNf4TyeYE8Yz03AKJ0aGzJN4k reStsUQsJTYcdA+Mx6yx38jPgHxh0qZsYwFxpdjkjKXJIZtXiH6U6HQpCGTEUkrksbWi Dny66NxywclYSp0MYQgAxLt5hPj96e31pg6jl+V+yuJIeffKdwsthuxCvvkI5BFjUJek PZeVFztie3RcmMa4xPW4yPVrI3QlHuISsUgqz4mg0ktkxxGyIedaF/f8E3mlvTFtVhKU YDsL7V0a+eJ3kcIAQKhycq4/+LnV75jijfmANYP7WAPDFwcxNwyp1+3HJkqdogMzQvWx raqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=H4gjzqmp; 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 f11si1042970pgs.335.2019.05.23.14.22.53; Thu, 23 May 2019 14:23:09 -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=@linux-foundation.org header.s=google header.b=H4gjzqmp; 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 S1731632AbfEWVTq (ORCPT + 99 others); Thu, 23 May 2019 17:19:46 -0400 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33593 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729797AbfEWVTq (ORCPT ); Thu, 23 May 2019 17:19:46 -0400 Received: by mail-lf1-f65.google.com with SMTP id x132so5478194lfd.0 for ; Thu, 23 May 2019 14:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zDS3Ns71UvqAxo/Ziy/UlngEZ1rvpeIhNyX6PGvAAp8=; b=H4gjzqmptwunXRqYKn250eOT7ZJCydxukVmu4abj4LD8/gbMEVOPhuM7deCH1oNhln IhAnoulFRb3ISTB2HVOGL4lwyjS9ysrUvrNhplgIj/dCVrMGGG7bNKPjDw5bsLNtt6oh ZXbn+4T7bsuWw2xhN1jJiH7ToSUE6NWp3vTNg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zDS3Ns71UvqAxo/Ziy/UlngEZ1rvpeIhNyX6PGvAAp8=; b=TtW1SiXWjNTVHC7CTWQfWPJHgErgaAqUeC5mAocHqYDW1TKtlEFTCFIoXoBAziBIe/ HLas8Lus/pVLlX4dkNttCVAQHe652uARobo1E6YgcjcG5SRSsXxDscZqd3RQpLftGc9K 7kD8tHdJtF9Q7Afev+kHvOlwGy8pq6i+rGe5SO0N+0oIKxatVCE+I5GAyu808GkU5OTW lvVGmP8q7di245M6qxjzvBc/PqdkQ/vJBQi9Kh9roabTCToKJt7VhPhz/DLYyyLHHyvk X2ojS9xaVeZGiv1PTP9ZzKPqhD/HHvH7EVtWKmz5kUVDDpEcZcH/w+FKmwztA6i9sIaq 7RGQ== X-Gm-Message-State: APjAAAWP7EdJIe+eMSRa+P9ldPvZu7yoTtqEv0SG3wZgOkcIpDConhJQ BO15n9gNZb2jBxqFJwe6Cg4JSwgQt30= X-Received: by 2002:a19:740e:: with SMTP id v14mr42946009lfe.144.1558646382999; Thu, 23 May 2019 14:19:42 -0700 (PDT) Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com. [209.85.208.169]) by smtp.gmail.com with ESMTPSA id k16sm135116lje.30.2019.05.23.14.19.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 14:19:41 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id h11so6839792ljb.2 for ; Thu, 23 May 2019 14:19:41 -0700 (PDT) X-Received: by 2002:a2e:9f41:: with SMTP id v1mr12462152ljk.66.1558646380884; Thu, 23 May 2019 14:19:40 -0700 (PDT) MIME-Version: 1.0 References: <20190523100013.52a8d2a6@gandalf.local.home> <20190523112740.7167aba4@gandalf.local.home> <20190523133648.591f9e78@gandalf.local.home> In-Reply-To: <20190523133648.591f9e78@gandalf.local.home> From: Linus Torvalds Date: Thu, 23 May 2019 14:19:25 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC][PATCH] kernel.h: Add generic roundup_64() macro To: Steven Rostedt Cc: LKML , Ben Skeggs , David Airlie , Daniel Vetter , Leon Romanovsky , Doug Ledford , Jason Gunthorpe , "Darrick J. Wong" , linux-xfs@vger.kernel.org, dri-devel , nouveau@lists.freedesktop.org, linux-rdma , Andrew Morton Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 10:36 AM Steven Rostedt wrote: > > > > > Of course, you probably want the usual "at least use 'int'" semantics, > > in which case the "type" should be "(x)+0": > > > > #define round_up(x, y) size_fn((x)+0, round_up_size, x, y) > > > > and the 8-bit and 16-bit cases will never be used. > > I'm curious to what the advantage of that is? Let's say that you have a structure with a 'unsigned char' member, because the value range is 0-255. What happens if you do x = round_up(p->member, 4); and the value is 255? Now, if you stay in 'unsigned char' the end result is 0. If you follow the usual C integer promotion rules ("all arithmetic promotes to at least 'int'"), you get 256. Most people probably expect 256, and that implies that even if you pass an 'unsigned char' to an arithmetic function like this, you expect any math to be done in 'int'. Doing the "(x)+0" forces that, because the "+0" changes the type of the expression from "unsigned char" to "int" due to C integer promotion. Yes. The C integer type rules are subtle and sometimes surprising. One of the things I've wanted is to have some way to limit silent promotion (and silent truncation!), and cause warnings. 'sparse' does some of that with some special-case types (ie __bitwise), but it's pretty limited. Linus