From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6D7C73101B6 for ; Tue, 27 Jan 2026 14:38:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.16 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524689; cv=none; b=NXNcs9U/Jo6Ok3nYLZ5Kel05XnZWrvIQUhbbLnz/5roMDfaIeZhw47FoaSGl3uzw0jD70LBowO3NTM4iqUDT2KQ0io/AqnL1In90lKWSb/hJIJrKbDp3cMriM6ZkR4cjnpUO7ojYyabKtaTv38djEeaKVNRSVt8oyNTq7E24GOo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769524689; c=relaxed/simple; bh=soGYrhFD8HGAA5+ovmTEgz6N7E7vcHr4DVLewwvW0nc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Xf4hrnw9w4kd1DDqK4ZUpZsFwn+IwSFouGn08BDhSiDIxz2zMMkxAcvk2UmDKkWcNtGcojbonvzs+cq1/EdpY25IFjCP5aiMzNYgtafZ+b0LzW7r5Bmpi/bUYJV+jS+Ev055JDPZZoQnYVpJsOXA6yOH8bhpDzDL0s+sUUF+vm4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=kQGEQl2P; arc=none smtp.client-ip=192.198.163.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kQGEQl2P" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769524687; x=1801060687; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=soGYrhFD8HGAA5+ovmTEgz6N7E7vcHr4DVLewwvW0nc=; b=kQGEQl2PbCbjwF+09B4hJD9ZNksZHiS0AP9joko6R+W749xKrnjouLE1 F+Q9o3p+IJQqQMAm+Zu/Aw+8FjbXYgJ+HJcGgiR3kO/MfBMCCBiKtXP/e uXfs/ytcABDU/oy5+NZZJfY4tHGDGN8kMbPnRSkEApyHz3MDlCU4gfQYM sSI1Jx2m4ptFcyl3h2zBCQQ7s9JxlSZQetMeDoKTh236ocjEXHHOYhwrd E0rZiLCPP7RGDzW8gk7o+l9prb/kSh9ZrYvlFuLq3kyDQfb21ZhJ/CTMT gKv/aOtmft80JffQoVHX+IJ8dpBnoByMzoHUzdaAC9BOW5rA3Mmuwn6hf Q==; X-CSE-ConnectionGUID: 4pHRsppySnmi/8bD7Ty9Nw== X-CSE-MsgGUID: gujbWL2eRiKtucuAK3cH6g== X-IronPort-AV: E=McAfee;i="6800,10657,11684"; a="58292629" X-IronPort-AV: E=Sophos;i="6.21,257,1763452800"; d="scan'208";a="58292629" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2026 06:38:06 -0800 X-CSE-ConnectionGUID: 6BEQmkULSjeFSgAkWi9eMw== X-CSE-MsgGUID: teVvWAdzRa+SiD5ECSvqPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,257,1763452800"; d="scan'208";a="207888513" Received: from egrumbac-mobl6.ger.corp.intel.com (HELO localhost) ([10.245.245.248]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2026 06:38:02 -0800 Date: Tue, 27 Jan 2026 16:38:00 +0200 From: Andy Shevchenko To: Jani Nikula Cc: Cristian Ciocaltea , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sandy Huang , Heiko =?iso-8859-1?Q?St=FCbner?= , Andy Yan , Louis Chauvet , Haneen Mohammed , Melissa Wen , Robert Mader , kernel@collabora.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, =?iso-8859-1?Q?N=EDcolas_F=2E_R=2E_A=2E?= Prado , Diederik de Haas Subject: Re: [PATCH v5 1/4] uapi: Provide DIV_ROUND_CLOSEST() Message-ID: References: <20260127-rk3588-bgcolor-v5-0-b25aa8613211@collabora.com> <20260127-rk3588-bgcolor-v5-1-b25aa8613211@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Tue, Jan 27, 2026 at 03:58:13PM +0200, Jani Nikula wrote: > On Tue, 27 Jan 2026, Cristian Ciocaltea wrote: > > Currently DIV_ROUND_CLOSEST() is only available for the kernel via > > include/linux/math.h. > > > > Expose it to userland as well by adding __KERNEL_DIV_ROUND_CLOSEST() as > > a common definition in uapi. > > > > Additionally, ensure it allows building ISO C applications by switching > > from the 'typeof' GNU extension to the ISO-friendly __typeof__. > > I am not convinced that it's a good idea to make the implementation of > kernel DIV_ROUND_CLOSEST() part of the kernel UAPI, which is what this > change effectively does. > > I'd at least like to get an ack from Andy Shevchenko first (Cc'd). Thanks for Cc'ing me! So, the history of the DIV_ROUND_UP() to appear in UAPI is a response to the ethtool change that missed the fact that this was a kernel internal macro. Giving a precedent there is no technical issues to add DIV_ROUND_CLOSEST() to UAPI as proposed. Main question here is: Does DRM headers in question (that are going to use it) really need this? Interestingly that DRM also started using __KERNEL_DIV_ROUND_UP() in UAPI at some point, which kinda makes an argument for allowing the other one. Also fun fact: this series plead for a new macro for division while ignoring existing (UAPI) macros for masks and bits. 0xffffU is effectively __GENMASK(15, 0). (And if you change the code, avoid using variables inside GENMASK() macros, it may generate an awful code, the GENMASK($HI, $LO) << foo is preferred over GENMASK(foo + $DELTA, foo) case. GENMASK(foo - 1, 0) OTOH is fine, however be always careful against overflows with left shifts, as BIT(foo) - 1 may not work for foo == 32, while GENMASK() may not work for foo == 0). So, I have no objections for either choice Acked-by: Andy Shevchenko ... But if you go that direction, please, fix up the style. > > +/* > > + * Divide positive or negative dividend by positive or negative divisor > > + * and round to closest integer. Result is undefined for negative > > + * divisors if the dividend variable type is unsigned and for negative > > + * dividends if the divisor variable type is unsigned. > > + */ > > +#define __KERNEL_DIV_ROUND_CLOSEST(x, divisor)( \ > > +{ \ Use ({ on this line together... > > + __typeof__(x) __x = x; \ > > + __typeof__(divisor) __d = divisor; \ + blank line here. > > + (((__typeof__(x))-1) > 0 || \ > > + ((__typeof__(divisor))-1) > 0 || \ > > + (((__x) > 0) == ((__d) > 0))) ? \ > > + (((__x) + ((__d) / 2)) / (__d)) : \ > > + (((__x) - ((__d) / 2)) / (__d)); \ > > +} \ > > +) ...as here join }) to be a single line. + blank line. > > #endif /* _UAPI_LINUX_CONST_H */ -- With Best Regards, Andy Shevchenko