From patchwork Fri Dec 23 00:09:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tyler Hicks X-Patchwork-Id: 636519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8C8DC4332F for ; Fri, 23 Dec 2022 00:10:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231484AbiLWAKY (ORCPT ); Thu, 22 Dec 2022 19:10:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231278AbiLWAKV (ORCPT ); Thu, 22 Dec 2022 19:10:21 -0500 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 062EA2315E; Thu, 22 Dec 2022 16:10:18 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 722E55C011A; Thu, 22 Dec 2022 19:10:17 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 22 Dec 2022 19:10:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tyhicks.com; h= cc:cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1671754217; x=1671840617; bh=TU q6QLAfgtkzRFmgm+1eHv8sP3D0VwkxRhMPteL5eRU=; b=jQ1Ho8O+fV6KYMif/M xtG8bmIxTiCYGIS2cit8HIiaePY8NDhLhFm3ROhswgkSWEltJcrFGHIVsMxfiBEn Ndu31gu7llLeBgHvGK3nA2XCuQH+wAUUw+3PGv1ihbfJ2LSzLVkjqVmIrzYqqCTy QKCHE4Yw0dr21XME2H+ZaBcP1VbxQvJsF4e02CUPHHg3uqKserLn3wFtAzelAYos sjeE8qpw7cxKjaAkSPXw00ET6xPIjOVVn0HkZNAs/VDXVvRCZkiJtQedbVhKXncC F3Dpj8KCJUX6m+yuuGahL6yhhhfOzAygAh3qhREE1pIxoFKwoKOA9XPFOSc+W36w EDAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1671754217; x=1671840617; bh=TUq6QLAfgtkzR Fmgm+1eHv8sP3D0VwkxRhMPteL5eRU=; b=vPZeXw+fazvtT5Bn/tw8lVIxb9VCy FUmnCZCig0cx4f1aXy8UkP9c8UozVrBahRFCf4UhoqZ29p4mljFH19Xr5q3n7u4d bKhCy28nWgc+mApB6NkMc1eN9tg73Mr2c/cPwJ8LgT7RA7zL88kzq2yR2zbNwwOB YPwEvMG29QmE4zdvLjKMh2NRjfQRGKy0goRiRVCHjL4JYodytkPh3UbhvWJuWXqx bW/53ESeE/vYe3eQ4BIZMS6Biit/X4NLKWKoCqCQEE//YVIKhvoTUDHyqaPJTIJ6 kxEpe17tizF3ZLMaifyEBk+xgCvWw0PYS/wScYHyUkYaU/Kq4cmel+Srw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrhedugddulecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefvhihlvghr ucfjihgtkhhsuceotghouggvsehthihhihgtkhhsrdgtohhmqeenucggtffrrghtthgvrh hnpefhvddukeefleefffekuedvvdelheevkedugfefgedvfeffudfguedutdefueeujeen ucffohhmrghinhepkhgvrhhnvghlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomheptghouggvsehthihhihgtkhhsrdgtohhm X-ME-Proxy: Feedback-ID: i78e14604:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 22 Dec 2022 19:10:16 -0500 (EST) From: Tyler Hicks To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Karolina Drobnik , Paolo Bonzini , Shuah Khan , kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Gavin Shan , Marc Zyngier , Mike Rapoport , Tyler Hicks Subject: [PATCH 5.15 1/2] tools/include: Add _RET_IP_ and math definitions to kernel.h Date: Thu, 22 Dec 2022 18:09:57 -0600 Message-Id: <20221223000958.729256-2-code@tyhicks.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221223000958.729256-1-code@tyhicks.com> References: <20221223000958.729256-1-code@tyhicks.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Karolina Drobnik commit 5cf67a6051ea2558fd7c3d39c5a808db73073e9d upstream. Add max_t, min_t and clamp functions, together with _RET_IP_ definition, so they can be used in testing. Signed-off-by: Karolina Drobnik Signed-off-by: Mike Rapoport Link: https://lore.kernel.org/r/230fea382cb1e1659cdd52a55201854d38a0a149.1643796665.git.karolinadrobnik@gmail.com [tyhicks: Backport around contextual differences due to the lack of v5.16 commit d6e6a27d960f ("tools: Fix math.h breakage"). That commit fixed a commit that was merged in v5.16-rc1 and, therefore, doesn't need to go back to the stable branches.] Signed-off-by: Tyler Hicks (Microsoft) --- tools/include/linux/kernel.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h index a7e54a08fb54..c2e109860fbc 100644 --- a/tools/include/linux/kernel.h +++ b/tools/include/linux/kernel.h @@ -14,6 +14,8 @@ #define UINT_MAX (~0U) #endif +#define _RET_IP_ ((unsigned long)__builtin_return_address(0)) + #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) #define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1) @@ -52,6 +54,10 @@ _min1 < _min2 ? _min1 : _min2; }) #endif +#define max_t(type, x, y) max((type)x, (type)y) +#define min_t(type, x, y) min((type)x, (type)y) +#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) + #ifndef roundup #define roundup(x, y) ( \ { \