From nobody Fri Nov 29 18:38:44 2024
Received: from APC01-SG2-obe.outbound.protection.outlook.com
(mail-sgaapc01on2078.outbound.protection.outlook.com [40.107.215.78])
(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 6BEBD15C139;
Wed, 18 Sep 2024 02:53:07 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org;
arc=fail smtp.client-ip=40.107.215.78
ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
t=1726627989; cv=fail;
b=bFJPIIDRGoNBF+hR8ygmh37gfuqzlzqzEG4twBKibz2jEf4+geH+Nfb7htdFfkfV8+ZB+dWyod2QsYedwHoGY48vwvGxYpmoc+HTKGwVGuAZH7y5w0JFb11j7hCkPQPlHfo64kVKSWQklBppCXeX2B1k0k1t6jnRsqTlncF9+ug=
ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org;
s=arc-20240116; t=1726627989; c=relaxed/simple;
bh=DX5+CF8hi7M0+XwIdf34umZzR0svoNwA8zFM256CrR0=;
h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
Content-Type:MIME-Version;
b=kcPZy8rPJzWeBexgreSd1IOdtKsbvzG4djxlBqwZTd8cDdtvT9Ct03Gmp99bti43vMEG8hO6NaW4uwq8swONQdPQS8Rxpunsde5cNw9qjnx09lQe6Y3KTa894/KnlOI21QcwlASldzk2U22LLzPh9PZRs701IsvS9goux31Mll0=
ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dmarc=pass (p=quarantine dis=none) header.from=vivo.com;
spf=pass smtp.mailfrom=vivo.com;
dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com
header.b=gI3k0aEW; arc=fail smtp.client-ip=40.107.215.78
Authentication-Results: smtp.subspace.kernel.org;
dmarc=pass (p=quarantine dis=none) header.from=vivo.com
Authentication-Results: smtp.subspace.kernel.org;
spf=pass smtp.mailfrom=vivo.com
Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com
header.b="gI3k0aEW"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
b=XgQ2rx2cUP0TG2IHW2DbCU6oUAj0knOYh14dY48u7EZ/qhWzW4xuhaOU6lPOHBQv+cKr07yJo7n4J/DECYUuxWOi4vEUmXQZSKvtzMDOayMEDQf5lAhCJcxOkq4V2FQDvEzrHEyiVhWDfJivoZFjxTL4DRmcCOdC/AGykG7KRtAch3Es3+xIuWksrod4XcHSrQYT1FR8hvYEZsRWIMpgBQofUbnr/eZGHK2bWHl4o7oBiJuenMYiNki6G9taUSzRdfYsVKDHMMkjBh5wfx24aIw85Cz9/Vf8cvGPfzkSu+f6260OvyHKoCQYJ7kvLMCrUVVjzAApSX5gTs+e9PmyZA==
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=qP85JJ7XhHxUZ0bL0II6CGxMXuUorY5CUTQpLmn9RwI=;
b=lMZ4IPyuuELt3vSYe3OdOjaLO/zQh/gUxnIfDj9LFrOcZH/ycVnzFKGslZ0UfLUnlxl3ELpi+UqCSYWz/DShlNhMLn4CDbJz9kCM92LD4HlGLKVsjnv5QmyY2yseuI+5T1KlEwkZ3si2jfovzKotQEsjmqZwngBtuRUE/oNqelowY/hBchWNxcRZOy4VghrOmxj1lfq6XFF1N/bEY81/HptlpJHYq15D/qWvxIpw80Ws51gP9o5E+52+UmsqsEkUgV2IVEgXoQRlwMxTFnUEMBMMaVtbDGeks2SuCnq5GcnQ0n7koJU5EdJNwS8wbO2HnVtjc5Go3MDM44ducjHh3g==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com;
dkim=pass header.d=vivo.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=qP85JJ7XhHxUZ0bL0II6CGxMXuUorY5CUTQpLmn9RwI=;
b=gI3k0aEWi0rwSlwwgnoP5tggGMEITs03lOLVmL3YyOHXpxhmUCZP0w5r3NBPktIiFxCCIR39p+rdWUA0XY8NxwY2nXIFMPXlHb3Do6SMcbUlVOlGXihmWBWnr7McvGpv6vKYyJT3+9vgrC11gXl22I9CBpNC7v5qWA+38BnYlSuDwYdyVjaDuoYUMx/4vccXaP9ysSEwdSXtsXO5FTDBWtxoQ5tYdtcxKmCDEBOAYhfoBaavhwN3iqAD+Zbj39eT+ReuTRYNRuegXDXlzG/GIQzK24vRtvHm76MReEvsNSfXP/RgI8B5TZp2KJX804J8Gd8oJDlHulIIFfInP4AJXg==
Authentication-Results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=vivo.com;
Received: from SEYPR06MB5672.apcprd06.prod.outlook.com (2603:1096:101:bc::11)
by KL1PR06MB6236.apcprd06.prod.outlook.com (2603:1096:820:d7::11) with
Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.23; Wed, 18 Sep
2024 02:53:04 +0000
Received: from SEYPR06MB5672.apcprd06.prod.outlook.com
([fe80::2f0c:5cf2:abb0:d852]) by SEYPR06MB5672.apcprd06.prod.outlook.com
([fe80::2f0c:5cf2:abb0:d852%5]) with mapi id 15.20.7962.022; Wed, 18 Sep 2024
02:53:04 +0000
From: Huan Yang
To: vivek.kasireddy@intel.com,
Sumit Semwal ,
=?UTF-8?q?Christian=20K=C3=B6nig?= ,
Gerd Hoffmann ,
Dave Airlie ,
Andrew Morton ,
linux-media@vger.kernel.org,
dri-devel@lists.freedesktop.org,
linaro-mm-sig@lists.linaro.org,
linux-kernel@vger.kernel.org
Cc: opensource.kernel@vivo.com,
Huan Yang
Subject: [PATCH v7 5/7] udmabuf: introduce udmabuf init and deinit helper
Date: Wed, 18 Sep 2024 10:52:28 +0800
Message-ID: <20240918025238.2957823-6-link@vivo.com>
X-Mailer: git-send-email 2.45.2
In-Reply-To: <20240918025238.2957823-1-link@vivo.com>
References: <20240918025238.2957823-1-link@vivo.com>
Content-Transfer-Encoding: quoted-printable
X-ClientProxiedBy: SI2P153CA0014.APCP153.PROD.OUTLOOK.COM (2603:1096:4:140::6)
To SEYPR06MB5672.apcprd06.prod.outlook.com (2603:1096:101:bc::11)
Precedence: bulk
X-Mailing-List: linux-kernel@vger.kernel.org
List-Id:
List-Subscribe:
List-Unsubscribe:
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: SEYPR06MB5672:EE_|KL1PR06MB6236:EE_
X-MS-Office365-Filtering-Correlation-Id: 9069a733-c9a9-406b-11ef-08dcd78d0482
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam:
BCL:0;ARA:13230040|1800799024|52116014|366016|376014|7416014|38350700014|921020;
X-Microsoft-Antispam-Message-Info:
=?us-ascii?Q?X+8aT7cWW7GxHcgK2k84niAdw/UJ9Sa0uRqRlWS1kaOStHaP81y90aGyfxrs?=
=?us-ascii?Q?2tMjQebSX0mhFTnZy55qegrlLIVebf6FKBLYHLKqhnI97kNb2IaMnOSBBVFQ?=
=?us-ascii?Q?6ufAbC+hcmSRYtrYMV1QcCodq42HE337hsn8a3QMUXQWcM2KU1dw0zAmw0fB?=
=?us-ascii?Q?LbH6zOqC2LqiU2229kWMuSmWKu5LlXszAEeN4h1b2iqEdm3SUSo+nAmSdA1r?=
=?us-ascii?Q?94G9qKhYDtkfs4U7ZjZO8uIiDvMsEIl8G8drysu5fsq9spKnGJdAgPQEJ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km5OWXfTwt+gNO7L2bQa151UgOKs+UO02JWcqmaMIMQhBLN3FySYmhm?=
=?us-ascii?Q?vxmq3zmouIQP4B5uDPeVIAcC04wMoiiUqH6iMwlTSUt+ONo2oqjk5FPYIKfR?=
=?us-ascii?Q?CdQO/j+f38TsqZIEZNO0aU8Xzk8GyU7usbWenTNsid6DuKiSSsGC4kLmeFtB?=
=?us-ascii?Q?+U6LB/UDToTvyH/+2GUZWnWff+Bw+6+hcMwPXxurvriMUQ9AqrFkYBSfAtpT?=
=?us-ascii?Q?b2RcyqRuowbKT9pW1OhMIFaZehSXd0WkhTY6rDKKeCAYmpeJFIvysuJIrMaU?=
=?us-ascii?Q?8r8R3eMLnKs=3D?=
X-Forefront-Antispam-Report:
CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SEYPR06MB5672.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(52116014)(366016)(376014)(7416014)(38350700014)(921020);DIR:OUT;SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0:
=?us-ascii?Q?5StMi5Zvrykufibcz8X7cp7yyhy7riryR+888ZigI5El0vW4GDG0itK0UvLh?=
=?us-ascii?Q?N6iOeT9ULN1JLzqhL04svOa1ZFHnkXZ1Ax44XKOYaalFx/hGKkZThkhCRiNg?=
=?us-ascii?Q?LfSUYdDSyqSrFQxgVsOBTBrRERYXcNm0vTsLaG6bOaq4+L6IjqoIFYBqbZIe?=
=?us-ascii?Q?P5UWk4NkfcZvK9XS6AhRkNRoVW3swwI+g/yM0UWBGhwWhtsEdcNxSEDU7nKb?=
=?us-ascii?Q?fO0zxTTSwMK9YdDcLssDS/zMpugarWYlT1Yb8w2rwWEaZnXhxMjSBWl/lt9G?=
=?us-ascii?Q?UpAey5dgw6hg2V3iptOeAjqzCBs84iB6ieKLgjc32Os9okGSlc1xl4KPKy2n?=
=?us-ascii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EMRdu5tQOpjXpeuzkshcWGayksu73n6Fnq3hue?=
=?us-ascii?Q?4tO2zRM4f7gj4o5jTcVW9bFAqOouh/fAKBMFwfMCzdizgGL1NLzY1JwLGTlV?=
=?us-ascii?Q?pduLezVyOcYem9k34RrmsD1Yyj65F30Qs5apZBklLN5pkvUhnY82wVkRy0yY?=
=?us-ascii?Q?XUZhLXNeylXvXAvrtRpN5/y1aZ1Gm19yK/oqINnbeE31yfeXkIWMURCDvBnc?=
=?us-ascii?Q?imZ3a19kQ96xNTtPUaWJzmUk8aKJ1gOP8LmlCVkv7fXeDhy1Pm/4Ufrhw/gR?=
=?us-ascii?Q?X3Mp6X+I8JptuT9R4uSGpLtEAZRq3L3a8Pm3aCimIlHIytf0VcXm+cuvnHcy?=
=?us-ascii?Q?fQaxm2KLcSte/84rJxQU16vRE2MxzEn3qo8wVESU?=
X-OriginatorOrg: vivo.com
X-MS-Exchange-CrossTenant-Network-Message-Id:
9069a733-c9a9-406b-11ef-08dcd78d0482
X-MS-Exchange-CrossTenant-AuthSource: SEYPR06MB5672.apcprd06.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2024 02:53:04.7254
(UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName:
axWcyLdZBYdW7NnfGHm31Ke9qrx8cezqvoSAZVYyIDxAa5uWkUkh61dfSyTLODq86eufN3qS8rsFKAvMTvcuSQ==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB6236
Content-Type: text/plain; charset="utf-8"
After udmabuf is allocated, its resources need to be initialized,
including various array structures. The current array structure has
already been greatly expanded.
Also, before udmabuf needs to be kfree, the occupied resources need to
be released.
This part is repetitive and maybe overlooked.
This patch give a helper function when init and deinit, by this,
reduce duplicate code.
Signed-off-by: Huan Yang
Acked-by: Vivek Kasireddy
---
drivers/dma-buf/udmabuf.c | 52 +++++++++++++++++++++++----------------
1 file changed, 31 insertions(+), 21 deletions(-)
diff --git a/drivers/dma-buf/udmabuf.c b/drivers/dma-buf/udmabuf.c
index 9d58c045b8eb..40ebff2c77f4 100644
--- a/drivers/dma-buf/udmabuf.c
+++ b/drivers/dma-buf/udmabuf.c
@@ -224,6 +224,28 @@ static int add_to_unpin_list(struct list_head *unpin_l=
ist,
return 0;
}
=20
+static __always_inline int init_udmabuf(struct udmabuf *ubuf, pgoff_t pgcn=
t)
+{
+ INIT_LIST_HEAD(&ubuf->unpin_list);
+
+ ubuf->folios =3D kvmalloc_array(pgcnt, sizeof(*ubuf->folios), GFP_KERNEL);
+ if (!ubuf->folios)
+ return -ENOMEM;
+
+ ubuf->offsets =3D kvcalloc(pgcnt, sizeof(*ubuf->offsets), GFP_KERNEL);
+ if (!ubuf->offsets)
+ return -ENOMEM;
+
+ return 0;
+}
+
+static __always_inline void deinit_udmabuf(struct udmabuf *ubuf)
+{
+ unpin_all_folios(&ubuf->unpin_list);
+ kvfree(ubuf->offsets);
+ kvfree(ubuf->folios);
+}
+
static void release_udmabuf(struct dma_buf *buf)
{
struct udmabuf *ubuf =3D buf->priv;
@@ -232,9 +254,7 @@ static void release_udmabuf(struct dma_buf *buf)
if (ubuf->sg)
put_sg_table(dev, ubuf->sg, DMA_BIDIRECTIONAL);
=20
- unpin_all_folios(&ubuf->unpin_list);
- kvfree(ubuf->offsets);
- kvfree(ubuf->folios);
+ deinit_udmabuf(ubuf);
kfree(ubuf);
}
=20
@@ -392,33 +412,24 @@ static long udmabuf_create(struct miscdevice *device,
if (!ubuf)
return -ENOMEM;
=20
- INIT_LIST_HEAD(&ubuf->unpin_list);
pglimit =3D (size_limit_mb * 1024 * 1024) >> PAGE_SHIFT;
for (i =3D 0; i < head->count; i++) {
if (!PAGE_ALIGNED(list[i].offset))
- goto err;
+ goto err_noinit;
if (!PAGE_ALIGNED(list[i].size))
- goto err;
+ goto err_noinit;
=20
pgcnt +=3D list[i].size >> PAGE_SHIFT;
if (pgcnt > pglimit)
- goto err;
+ goto err_noinit;
}
=20
if (!pgcnt)
- goto err;
+ goto err_noinit;
=20
- ubuf->folios =3D kvmalloc_array(pgcnt, sizeof(*ubuf->folios), GFP_KERNEL);
- if (!ubuf->folios) {
- ret =3D -ENOMEM;
+ ret =3D init_udmabuf(ubuf, pgcnt);
+ if (ret)
goto err;
- }
-
- ubuf->offsets =3D kvcalloc(pgcnt, sizeof(*ubuf->offsets), GFP_KERNEL);
- if (!ubuf->offsets) {
- ret =3D -ENOMEM;
- goto err;
- }
=20
for (i =3D 0; i < head->count; i++) {
struct file *memfd =3D fget(list[i].memfd);
@@ -449,9 +460,8 @@ static long udmabuf_create(struct miscdevice *device,
return ret;
=20
err:
- unpin_all_folios(&ubuf->unpin_list);
- kvfree(ubuf->offsets);
- kvfree(ubuf->folios);
+ deinit_udmabuf(ubuf);
+err_noinit:
kfree(ubuf);
return ret;
}
--=20
2.45.2