From patchwork Fri Aug 2 17:00:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13751798 Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010021.outbound.protection.outlook.com [52.101.69.21]) (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 269D216BE26 for ; Fri, 2 Aug 2024 17:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.21 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722618067; cv=fail; b=jKH+wHrTFpahJzWY5wkVK+eSWDEL5BCxprRmpDXJnLd/t1kkYNzRrRsL/9P1zkcLm4h/obAZJEYnmXVi31dlw3WVrm7c1Sghv+luUfhcyBnxrTQFj7KqeUGgvm2+VczISg80wuVQNvBETQQYrHEk+wqtXSHheC+17rtd5u7hPfc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722618067; c=relaxed/simple; bh=eF56HF5tAL06gaLRQFAx2/hUdVVqvDEmDOfGQX+IecI=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=Qzi4J6cWsmWGo13HwDWrFZF7DGP8jLOp/4aFiyt6FF7ML6dGtcO8FIpKLd6doEIN652K5XI4CpqE98aSklCbmfA465oFb62djjVnukX8sddxOGO+Lsy1mfH/D/0F8Pa9knJbrHHZKyo0mNEECMGTrfSusXBlzK+UuaxA2DfwuDo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=gPONwnhh; arc=fail smtp.client-ip=52.101.69.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="gPONwnhh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wFQUu/i3IYgg2TCJR6dg2hVUtbxF5086TZUZ2PwyWPB7XL3jCsIvWX4CGi6RWCiaYF5j5mvUFF882WyBr4DxftHF6utLrTXiMtxrw6SDWlIsHOsM6N3+Xo15AnRbAVDUZhttVqJi5C+3sPH4cOcWLW3UjEZBSbAAwxnYsg3fleP1wWEhIs44eW85ksO4jfH5ADiLHKdR8PaRXQRY2J01mDXqu5IQxi8NcWDUXB1hOqa0SO/K5ZJUVvEGauiNE0xWvxojkjUW8NMIp5n6o6Tk5M/SezTW5zYZKjPktESG6DGEnQsgki9MfihZupPErIoAu9DZIpt8bWx+YWVG9D93+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XQ6f5uwX2rUvdY4UFWIukT6zPlzeQvKl96SX4qqxlJo=; b=Fm/y1cN7RxPQ+FW5ADpL3XGdwCg/ENp0eiicbMSGEo76XDf+sjY3cDgmT15WJ9KOdAmBdUkuNgTxpIH0H/hvaDeHwSE3Gs5hZ6S1gZz7CsKuVonZyJQK/zZgkar/C+0URcP81+NOOKMJvDZAHwCckK8ROt6avqJaI66DxioCR3NwT8/H6OOU7pLn4uQIGDVN3+0UUOoYqEggtpSFC7Ht9uxYS1buk/84Diy66LoSJv9QUGq7Y6z9lu5M5FwvYoKXdNQQJ3p8KpMTg4uhizqJIIb0Q4hcRi1lyZiUKCZ80iyPlM0qvmqDO5pQRkjWENpDFZh+6ba8cXO9MOM2mxXAqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XQ6f5uwX2rUvdY4UFWIukT6zPlzeQvKl96SX4qqxlJo=; b=gPONwnhhmdY/+rlVZDaaludzI40P6zWsdFMA0eZO7vyyavqjFkrTObqcsdrjRj7+YgZg7j81yvgdnXua0rhiNoY0OSuEh7n97WM+HdvOtPzwvDgwm5RNFmKT/YxlEw5Mv8XJTAXMxLLC8TESlQJTQVPzsyyf+1Mt/x1yRgVnUX64M9QgcMyeJWVTJVKp7u/VaikQm2J497I/JX+jbUVK2SuzwA4QPHOt4GVCCpC0FECEjZx7aCKP4Wnjp/EQs7Oyl5qx3nFl5uVV1c02fd1o7AgxfKyt8SiNUUFnRlu+F3JAxixGPGm6KRQmggBizzkm4pfWzfNm0ux4L75DU3UM2A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by AS1PR04MB9336.eurprd04.prod.outlook.com (2603:10a6:20b:4dc::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.28; Fri, 2 Aug 2024 17:00:59 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.7828.021; Fri, 2 Aug 2024 17:00:59 +0000 From: Frank Li To: arnd@arndb.de Cc: Frank.li@nxp.com, akpm@linux-foundation.org, ast@kernel.org, imx@lists.linux.dev, jgg@ziepe.ca, kent.overstreet@linux.dev, linux-kernel@vger.kernel.org, schnelle@linux.ibm.com Subject: [PATCH v2 1/1] linux/io.h: Add cleanup defination for iounmap() and memunmap() Date: Fri, 2 Aug 2024 13:00:43 -0400 Message-Id: <20240802170043.2809545-1-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SJ0PR03CA0023.namprd03.prod.outlook.com (2603:10b6:a03:33a::28) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|AS1PR04MB9336:EE_ X-MS-Office365-Filtering-Correlation-Id: 04bd5fd8-b47c-4863-99d1-08dcb314aef5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|366016|1800799024|376014|38350700014; X-Microsoft-Antispam-Message-Info: 61JVnO4kLkaivqAPF3SwXMR8lO4hyE4Ipm/DEmLN/YdzfXnKtXtgoGy7w4m8IyVWcoNNdPj5QsKAdSgr+tm5o9lCRN/MWX5O9xWujhWyvANayF18yQIbCEagh/towJEQA2lk8ZC96ai89PymqEgVt+LJXWTNQPM1ObDzFta8q6b7DY6kYlkGK1UdrnC0YdJAunC/iP7TPhkUiGiYGQn8gUKJ5CLz7WKUqSy9jFGRBYA0XgybsVOO63EDdrCfdav+rZNICBlmFG9Rqps+mAINadNFgedbq/Pk4huOWeNk32++YN4KaGtCfNvdjBFfQE9SdeA5zAtQxEEQFTRbJCrsXTnL3h6pkuyGcQDQWzMcWG41yDp4YOMkxVYSyhWecVhUgPEpCSXz0OFrTqvS1MSIsTI6i49HF/meKpyBc+5mn/Gqw/3JM+zrSGuKXeZocUydojmmrAF8lPvhesqHsplzRUJl4W5ET2laIak4TiploU3RzbSO5t28vBWWux8auGe2UGozh+BS4nyKF8LL9nffiZk/eNgYteaOG40srgiGeM6uHUZDPbbUuanT/sjOiIIvoVp1o+88uMGGlVWt3FZLc/mT5hPhuRSq0QS7axs+JFv96l7mJVn/nO48yo6wLpR//Do4vpEHr/C8rQKQ7xQACnZHC1m3fe+sItpN15HMs3WJ3raf2PPEMcOjkQnbG0gZ3+rT6VWt0GUSnebCfO6wDs+3oU8CxLeA9QRaFd3v7MkbTvHU92cr1kKW7dOK8WqDuink1+ghiPHGB3LNdvGo5AfOCtYGyCDr5lQQCQVbSm17sh+GMMbzpMJ/ChWLOJQeXlBrs184JeLJzwKyNmr/J4CVkKUyAPNO+qrBqmZ7yIUGchzhUnG7U3JSCuo21k0fc+GMO68H8ScakwZXMLYintzLjHqTblHDF/WM0CggZtSyZUdv0S2sbptsWPX0vmgTBspo6s+5V7Iq1JJytxbctOVPAhx11hXXBPnhOFEjB5ZZeiFK5BNhMhZ4n2mCXEOpRWZDF+PNQokcpSUTzp9KzATrGVf+1jKsHmfj+4Lmd7Mv6BLmTM15BHT6NlkJcdVtvGTO7BsTzdgep1xMlHKCJlNY8ehIioL+KeVVdWyOvQMov5MCobgtuExe491zL/VJFp7Z47g9ZdyPyy1sJ7KNbqdnsXFfnW5ULI87W4BhAU9gjdyOWIF8EdkxOJhuAVe1BvqwJQAy9U8pHOupA2b3RHhOUUYILLwd3LiR2WEdZmVsqzkgAahTxXxk4F5rAM3cr7Agp5NkFn+nV+CYpNPr8z66xb36MpWp7BgLYhmFXrTCOk37uE6LeAvwrtaL1wG9iGqa6Pt5dLTX2Vb+vQAloShi+3v+YEHhHE7Hszc1z3c+afYk0oEzcHfsvcP5aX5OIEuYttEhjXAIViWZBpTX4g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(366016)(1800799024)(376014)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ZEtmDcXg9nYmN4M5YCEjSIlqS8qRHOy5SSHRUWGWe6aItFAErG20P512WVsxs0lCPIVxCX6wnIy0XKQPRSEA4jcWXepfPU0ijiaDUKR/z+NB08TS95y58ul7AWxdMKGHOhF1KjilYfTceYvZO9AmY5/XXIzxi5qQ2xoqZihU+QS3cHAiSCaIBI2GGqVdXLirPL9lY10n2EwhJQ6LVRGkzopyeEbtV7dhdBrLlNvW5lLCSRPGE08cLMup3b2uXV+7EC5kcyZJohLhJRDg9z0fW8PRoG3nKcywoZOsCkWp1l99bpsscux/Gzr+u8sNw5bvcmrdWIB3EKUTFMJAHETRHxpdM0sSZlE6wWvM865VpphCTDBIjlAAo8apw1m9pbc4fveeJCW80ssq1Ki1tI0Hm1WpV5B3ayNO2nBwZ013+dGSWzUC3Ibr2pTDzeHjSyOkXqGZAdi554nwntr1vwCiFs0RhadDR1Xk1urvhHgsJ5fGMzsK3YQzIlRhOhw8DYO9matQY0hbp+vQKHS3xuzZV3EZFFtJ/NvHk5di9TxQ1AgVB7P510BKuAoveX0fxKF0geMEO831I8TKmqs4G4enm X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04bd5fd8-b47c-4863-99d1-08dcb314aef5 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Aug 2024 17:00:59.8430 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4P8YTlLgZ7agqQ74NnLflgMP/rypCCnT0V9Hi2ZymnoIpiU3qp4PPTgze9pbKk2j7riosj9eJHHXdO6YhgNBUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9336 Add DEFINE_FREE for iounmap() and memunmap() to support scope based cleanup. Signed-off-by: Frank Li --- Change from v1 to v2 - Remove IS_ERR_OR_NULL() and just simple use !(_T) --- include/linux/io.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/io.h b/include/linux/io.h index 59ec5eea696c4..4cce787d52805 100644 --- a/include/linux/io.h +++ b/include/linux/io.h @@ -163,6 +163,9 @@ enum { void *memremap(resource_size_t offset, size_t size, unsigned long flags); void memunmap(void *addr); +DEFINE_FREE(iounmap, void __iomem *, if (!(_T)) iounmap(_T)) +DEFINE_FREE(memunmap, void *, if (!(_T)) memunmap(_T)) + /* * On x86 PAT systems we have memory tracking that keeps track of * the allowed mappings on memory ranges. This tracking works for