From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (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 535E7359FB3 for ; Tue, 27 Jan 2026 13:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769522305; cv=none; b=sfyo1pCu3BUQt4KKociHYg9QGBcb2oYcX5qwXlWgNufteUyWLEZQ9BGgHwLfhjEn+WxA4XCmEh49B5m7+mwsEUo9P3T0J1sA/T/CeK0wDPOWXMCrnyapTnLvA/gu3WVnfnB2I0z/YmQ6nKnLrnnnH/NtMOtMvGVTcMNRjU44Gqc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769522305; c=relaxed/simple; bh=og59pwZnyOqe7PNgzDbUl3i3pkVIgIempTHbdxTELvk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=NMgbu/ton+EFvx8+UXjc6TvohuV650Z9/rWSyXozIxHkAuvgkA1dUJGN68ANOWerS8g2fD5275gLdHCvD43TwKW2SUqOmm/9e+9IkkTi6Ko7fOjX9TxUi+aqm2dylq2VZtXNBPhBRBMev1lBASTgA5ggp1HKtn/ZfiH8Pfe71+c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=EEgLb6eg; arc=none smtp.client-ip=192.198.163.13 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=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="EEgLb6eg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1769522303; x=1801058303; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=og59pwZnyOqe7PNgzDbUl3i3pkVIgIempTHbdxTELvk=; b=EEgLb6egniyOnIDvGY0jN361Q+wfxPCsbD/uvJ+of0q9Zcvbs8NZpO+y CnLnc1vs8uHdqCiMqFlHU1Ikn0A8U8QGA1mp7kcgP+3ujjC1JJaiE4p+O g5xtw58+0EnVbWV6lh8A+2D2JeN15aYNWtW3bC8hUczfazqHhqbATdCQp Vhh4KsHMvxytfk2Z/dRMBJHLrXwfwzcmRtqmzG6Z60HsOu0dmKJjR23XP rBIloMw2l7095IApbaeFyPvcbXpMUaD5pmKZMEN9/GBP6X2TufTPdQ4Hp +nFah58JgEDPE4XzatieMNdgmFsVzqYrqGNyPsYPT5H6SYRslzQU3YAkt g==; X-CSE-ConnectionGUID: 5OVQbeyCRwOKLqPGUZ5k8w== X-CSE-MsgGUID: 5XHsyETLSfG0hWfKn8cbkw== X-IronPort-AV: E=McAfee;i="6800,10657,11684"; a="73302719" X-IronPort-AV: E=Sophos;i="6.21,257,1763452800"; d="scan'208";a="73302719" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2026 05:58:22 -0800 X-CSE-ConnectionGUID: BCzws0wPRNOMRGWv4OMbDg== X-CSE-MsgGUID: 9fMvMzQpQUu7qdSrTcjCXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,257,1763452800"; d="scan'208";a="207876830" Received: from mjarzebo-mobl1.ger.corp.intel.com (HELO localhost) ([10.245.246.148]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2026 05:58:16 -0800 From: Jani Nikula To: Cristian Ciocaltea , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Sandy Huang , Heiko =?utf-8?Q?St=C3=BCbner?= , Andy Yan , Louis Chauvet , Haneen Mohammed , Melissa Wen Cc: 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, =?utf-8?Q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= , Diederik de Haas , Andy Shevchenko Subject: Re: [PATCH v5 1/4] uapi: Provide DIV_ROUND_CLOSEST() In-Reply-To: <20260127-rk3588-bgcolor-v5-1-b25aa8613211@collabora.com> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs Bertel Jungin Aukio 5, 02600 Espoo, Finland References: <20260127-rk3588-bgcolor-v5-0-b25aa8613211@collabora.com> <20260127-rk3588-bgcolor-v5-1-b25aa8613211@collabora.com> Date: Tue, 27 Jan 2026 15:58:13 +0200 Message-ID: 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=utf-8 Content-Transfer-Encoding: quoted-printable 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). BR, Jani. > Reviewed-by: N=C3=ADcolas F. R. A. Prado > Tested-by: Diederik de Haas > Signed-off-by: Cristian Ciocaltea > --- > include/linux/math.h | 18 +----------------- > include/uapi/linux/const.h | 17 +++++++++++++++++ > 2 files changed, 18 insertions(+), 17 deletions(-) > > diff --git a/include/linux/math.h b/include/linux/math.h > index 6dc1d1d32fbc..1e8fb3efbc8c 100644 > --- a/include/linux/math.h > +++ b/include/linux/math.h > @@ -89,23 +89,7 @@ > } \ > ) >=20=20 > -/* > - * 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 DIV_ROUND_CLOSEST(x, divisor)( \ > -{ \ > - typeof(x) __x =3D x; \ > - typeof(divisor) __d =3D divisor; \ > - (((typeof(x))-1) > 0 || \ > - ((typeof(divisor))-1) > 0 || \ > - (((__x) > 0) =3D=3D ((__d) > 0))) ? \ > - (((__x) + ((__d) / 2)) / (__d)) : \ > - (((__x) - ((__d) / 2)) / (__d)); \ > -} \ > -) > +#define DIV_ROUND_CLOSEST __KERNEL_DIV_ROUND_CLOSEST > /* > * Same as above but for u64 dividends. divisor must be a 32-bit > * number. > diff --git a/include/uapi/linux/const.h b/include/uapi/linux/const.h > index b8f629ef135f..471877322f47 100644 > --- a/include/uapi/linux/const.h > +++ b/include/uapi/linux/const.h > @@ -50,4 +50,21 @@ >=20=20 > #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) >=20=20 > +/* > + * 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)( \ > +{ \ > + __typeof__(x) __x =3D x; \ > + __typeof__(divisor) __d =3D divisor; \ > + (((__typeof__(x))-1) > 0 || \ > + ((__typeof__(divisor))-1) > 0 || \ > + (((__x) > 0) =3D=3D ((__d) > 0))) ? \ > + (((__x) + ((__d) / 2)) / (__d)) : \ > + (((__x) - ((__d) / 2)) / (__d)); \ > +} \ > +) > #endif /* _UAPI_LINUX_CONST_H */ --=20 Jani Nikula, Intel