From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4B91AA0C4B; Mon, 22 Nov 2021 17:31:49 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1679D4014E; Mon, 22 Nov 2021 17:31:49 +0100 (CET) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2060.outbound.protection.outlook.com [40.107.236.60]) by mails.dpdk.org (Postfix) with ESMTP id 6570F4003C for ; Mon, 22 Nov 2021 17:31:48 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SEKz0O/fljBNS1ZLpCFsJjhoq8lfRlQCDI2Z7yuNTPLAj1NdoftQDb9E6dBsaMOAvgD0vB3nS4heDJcSj3XMVItibwqTu87A7I3+jO9wvyIXruy2OqBdL7RHCIjnhHpjaOq4Hq8J/60IFk9h/QUKKNRm09D1JNGoIBeAavbrqMaRxh4oQTxcSNGL4LdUoQWrNxbTp6HmFRlh7s4NeWVZ3a4rVy+uH9aaKuTunFaKIKzJ5s3H1xWLtDub1MLPbHr/HUTwRyZY8k3jMgixFIKI/jGCUCLHnXRoMrqEMF9bTIoZyfqcQZDmXn4UVMjEwrnPfTpLcAmTZ1gVzM6OHCRGBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=4R4nnb7pmrRXAm+GgxUXlnLJR/jDDKukCE4MlEc/k8c=; b=c74n5wUlzEX2Nab2MCaS7EWNdF1fP/1pDlYrVTT5rw39EJWKhz+RekNnk4opwHujrdng+FihNFFMx//tT8l5cxdxSoqHQ9dzB6jM8+mlwaezsdrOYIXJBhhZcCbRSQbVRe/wHpOUg0Rtm6c74JRb5eSvoIoD/IFpDBAwlUQVbC+z0q+/52eCfJIpoCLaFiMcxhzSjdygcXLrcIt7j/+fv+7H1P8AweN63tUM6loBYu214LEB0iE9y8VRRS7oW9n4Zse0TGQyCY+M+5XRoaX44snNM+6kTtqPmIpJ2neD8j0EuylDoCmJO8rmFWujgzbcfZqX8aV+8Vay1uTZi9vvFw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4R4nnb7pmrRXAm+GgxUXlnLJR/jDDKukCE4MlEc/k8c=; b=Df5Wyv9Q5UtRaE2f1aPoA0WPJFc6AHkoteF6qRG4VyYC5EMyg8tOMTrszt2G6qQEJDfp142lrbQbSZ2e7WCR04ZgqzLmzzoC9eCtxJ7uuwyf/pg/rbPH1+LDc2MABcZEgnw8wxzz7skwGktDzgK/VpPJk6pVahKjdGH9Q66/gPlD4ZCxtyR0gADpEVUii9X14X6oKkgJWNWVqnkCvsF8HHoutj8mLKviYHwfpLY16NT9VoU4QB3R3LRMDxvBSLYHELcnHl7eN3Gf9vccaOOleHEVTTs3m24NdlSguec6Lh6m0n/7NLddYgU6dNlLllQp+HS6Uu5Pwn3SLHtM2MR6VA== Received: from DM5PR18CA0082.namprd18.prod.outlook.com (2603:10b6:3:3::20) by CH0PR12MB5265.namprd12.prod.outlook.com (2603:10b6:610:d0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21; Mon, 22 Nov 2021 16:31:47 +0000 Received: from DM6NAM11FT041.eop-nam11.prod.protection.outlook.com (2603:10b6:3:3:cafe::f0) by DM5PR18CA0082.outlook.office365.com (2603:10b6:3:3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.19 via Frontend Transport; Mon, 22 Nov 2021 16:31:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT041.mail.protection.outlook.com (10.13.172.98) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4713.20 via Frontend Transport; Mon, 22 Nov 2021 16:31:46 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 22 Nov 2021 16:31:45 +0000 From: To: CC: Elena Agostini Subject: [PATCH v7] gpudev: manage NULL pointer Date: Tue, 23 Nov 2021 00:42:07 +0000 Message-ID: <20211123004207.24733-1-eagostini@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211118192802.23955-1-eagostini@nvidia.com> References: <20211118192802.23955-1-eagostini@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 48146abf-2f72-4153-df63-08d9add593b0 X-MS-TrafficTypeDiagnostic: CH0PR12MB5265: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2958; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ok5AFE2cRkx/8HXZpwbhVi8kHUOaO+ppkAW4FSBaSJmmEVQFFayw0aCYRXaC/TMe/5z239zPnBPpIbpfUuj+R9TjUCYSkLQhF1qxRV1SUc85AHGqD7fMqrC5NoCOnxk37eF+X+BvqYSb2p1EHeozCg/l0QrtTk2XogapxWwwfNptn+TUk1Ku5V0z0FnLnudb0aX6nP0+hTcbR4QR64/zn9ih8NK0vaOhArV9S1S/0qvtJRFTbR/myCT01/70r2yMce7dn8v1pwDaAwvdbxUS9/WwzIIqaK5AB0SSe3OkGVO7GvBPH0CUTumrR7WkcCtUbev4YZ8ZNNTO9jGEJ5L+n6D5EcnQ0233zVbrPUM/xxo/1FLgXr4iVpwillD71Z0i2OUToKpS+FTjN3OXFchAdzQFrOgPCRqqvldNLJgIIU83Tp3FuH0HqWr8pEvAii0hK2UnFODmgVNEjhy+wQWImBBWPl2nFB4jNzuzqMsP/73ska0uqfYuCqTAYBRLEwIzBSAgrmpwiVI6rkgUqCAei95nepEep2P/GPEHnUAiIJBnj9181ZTDQnXirhswpjW+7XCS4T0g+FccjR74j9o3BudRaMRRHZiLHpwQ7doZfg06lQ9Z4BTCEr11RJ0SzsSutVWTPZSdE+SleWfB/rRkSriaOjQxfGy5c4GCtoVIQCuu5lRcHeuUJIgaE41VfmzaRYgV1/tpB6IzDg01365d4w== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(186003)(2906002)(107886003)(8676002)(8936002)(47076005)(16526019)(26005)(36756003)(7696005)(356005)(83380400001)(4326008)(7636003)(86362001)(2616005)(70586007)(316002)(6666004)(2876002)(55016002)(426003)(336012)(6916009)(6286002)(82310400003)(1076003)(36906005)(70206006)(36860700001)(508600001)(5660300002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2021 16:31:46.5998 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 48146abf-2f72-4153-df63-08d9add593b0 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT041.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR12MB5265 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Elena Agostini gpudev free and unregister functions return gracefully if input pointer is NULL because API doc was indicating NULL as a no-op accepted value. cuda driver checks are removed because redundant with the checks added in gpudev library. Fixes: e818c4e2bf50 ("gpudev: add memory API") Signed-off-by: Elena Agostini --- drivers/gpu/cuda/cuda.c | 11 ----------- lib/gpudev/gpudev.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c index 24ae630d04..a4869da186 100644 --- a/drivers/gpu/cuda/cuda.c +++ b/drivers/gpu/cuda/cuda.c @@ -569,8 +569,6 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) if (dev == NULL) return -ENODEV; - if (size == 0) - return -EINVAL; /* Store current ctx */ res = pfn_cuCtxGetCurrent(¤t_ctx); @@ -652,9 +650,6 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) if (dev == NULL) return -ENODEV; - if (size == 0 || ptr == NULL) - return -EINVAL; - /* Store current ctx */ res = pfn_cuCtxGetCurrent(¤t_ctx); if (res != 0) { @@ -764,9 +759,6 @@ cuda_mem_free(struct rte_gpu *dev, void *ptr) if (dev == NULL) return -ENODEV; - if (ptr == NULL) - return -EINVAL; - hk = get_hash_from_ptr((void *)ptr); mem_item = mem_list_find_item(hk); @@ -803,9 +795,6 @@ cuda_mem_unregister(struct rte_gpu *dev, void *ptr) if (dev == NULL) return -ENODEV; - if (ptr == NULL) - return -EINVAL; - hk = get_hash_from_ptr((void *)ptr); mem_item = mem_list_find_item(hk); diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c index 2b174d8bd5..1d8200e71b 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -580,6 +580,10 @@ rte_gpu_mem_free(int16_t dev_id, void *ptr) rte_errno = ENOTSUP; return -rte_errno; } + + if (ptr == NULL) /* dry-run */ + return 0; + return GPU_DRV_RET(dev->ops.mem_free(dev, ptr)); } @@ -601,8 +605,8 @@ rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr) return -rte_errno; } - if (size == 0 || ptr == NULL) /* dry-run */ - return -EINVAL; + if (ptr == NULL || size == 0) /* dry-run */ + return 0; return GPU_DRV_RET(dev->ops.mem_register(dev, size, ptr)); } @@ -623,6 +627,10 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr) rte_errno = ENOTSUP; return -rte_errno; } + + if (ptr == NULL) /* dry-run */ + return 0; + return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr)); } -- 2.17.1