From patchwork Mon Dec 5 13:55:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Melissa Wen X-Patchwork-Id: 13064546 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 29A26C4321E for ; Mon, 5 Dec 2022 13:56:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED70410E098; Mon, 5 Dec 2022 13:56:39 +0000 (UTC) Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F90C89023 for ; Mon, 5 Dec 2022 13:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KsNzkwVwgR+cEA5X8iXb1kE6xx18RGkmAb0qmlWlRgg=; b=GjaCbrowCd99kPgE8d3uiGCQIr 6lWgGfXrOvIJMSd6HmKjc3AEHsywMdG+njahJ4aK4JwBp7AoC1q1v2MAJVODBj0oAwa2KvZLEzoNi pQCUVZdwWcjupRhxNsTy2WZ40edBWOkF+hUebAkO81TGO9aIcwbV4JXZlxoPUnVtu1/+ERS4oWoKm ZkBMRuSyeoglvZ/aDZc3/Hpw9AHjZxvz+VBfCq8vviLl2pfRDXQj2F4Ic2rdpj1rGrWSwFMiho99u /ovJnDL6QqX9jR9CMu9gBYw3+9xKrr9TT4FtGOOAco3UCasbCk2Q4Q14HhAYNpCVyO+ErIZnF2MkL 2WX8WtFw==; Received: from [41.74.137.107] (helo=killbill.home) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1p2Bx7-00FUSn-1Q; Mon, 05 Dec 2022 14:56:13 +0100 From: Melissa Wen To: emma@anholt.net, mwen@igalia.com, airlied@gmail.com, daniel@ffwll.ch Subject: [PATCH v2 1/2] drm/v3d: cleanup BOs properly when lookup_bos fails Date: Mon, 5 Dec 2022 12:55:37 -0100 Message-Id: <20221205135538.3545051-2-mwen@igalia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221205135538.3545051-1-mwen@igalia.com> References: <20221205135538.3545051-1-mwen@igalia.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , Maira Canal , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, kernel-dev@igalia.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" When v3d_lookup_bos fails to `allocate validated BO pointers`, job->bo_count was already set to args->bo_count, but job->bo points to NULL. In this scenario, we must verify that job->bo is not NULL before iterating on it to proper clean up a job. Also, drm_gem_object_put already checks that the object passed is not NULL, doing the job->bo[i] checker redundant. Signed-off-by: Melissa Wen Reviewed-by: Maíra Canal --- drivers/gpu/drm/v3d/v3d_gem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c index 96af1cb5202a..31a37572c11d 100644 --- a/drivers/gpu/drm/v3d/v3d_gem.c +++ b/drivers/gpu/drm/v3d/v3d_gem.c @@ -363,11 +363,11 @@ v3d_job_free(struct kref *ref) struct v3d_job *job = container_of(ref, struct v3d_job, refcount); int i; - for (i = 0; i < job->bo_count; i++) { - if (job->bo[i]) + if (job->bo) { + for (i = 0; i < job->bo_count; i++) drm_gem_object_put(job->bo[i]); + kvfree(job->bo); } - kvfree(job->bo); dma_fence_put(job->irq_fence); dma_fence_put(job->done_fence); From patchwork Mon Dec 5 13:55:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Melissa Wen X-Patchwork-Id: 13064544 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1784EC4321E for ; Mon, 5 Dec 2022 13:56:32 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 36FD089023; Mon, 5 Dec 2022 13:56:30 +0000 (UTC) Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id CAF0310E073 for ; Mon, 5 Dec 2022 13:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=uZS2YlPKAGNQfivHgbSmAIM4sCwER+o4TAV8vJgXz8w=; b=HQzjLtssEbTdGTtTKrUBJwnOTz MiF8nXG+Hezn7PDo6Ng86NCQen4xchs8gTaWqFbsDdFlu8PvGHvbdSgl0ol3PimDCDQ3Ocqyf1EIH P9HoMg/vYHx3tJkDPD7iohCTszKcCixnTxgeqqa+Ere+AAKmfu6ym+82OZSMaBzQPn9m+olJywzkW zzvIZtAmwo1KJSJF5fAmYb3KjKRNQ1miuEF0SivIYU4Q4XcLQx8lHQKJeHPWiA93c1A7xSaxy5qGG 9xuk+luZKmMQFkjRnFU2UlrJ2wdQK/ZbPwQJ4RlFbCJJIPmK8HZra7I/np8xCk3zbNNuZf9m+eKa+ biuln9zA==; Received: from [41.74.137.107] (helo=killbill.home) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1p2Bx9-00FUSn-Vl; Mon, 05 Dec 2022 14:56:16 +0100 From: Melissa Wen To: emma@anholt.net, mwen@igalia.com, airlied@gmail.com, daniel@ffwll.ch Subject: [PATCH v2 2/2] drm/v3d: replace obj lookup steps with drm_gem_objects_lookup Date: Mon, 5 Dec 2022 12:55:38 -0100 Message-Id: <20221205135538.3545051-3-mwen@igalia.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221205135538.3545051-1-mwen@igalia.com> References: <20221205135538.3545051-1-mwen@igalia.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Zimmermann , Maira Canal , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, kernel-dev@igalia.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" As v3d_lookup_bos() performs the same steps as drm_gem_objects_lookup(), replace the explicit code in v3d to simply use the DRM function. Signed-off-by: Melissa Wen Reviewed-by: Maíra Canal --- drivers/gpu/drm/v3d/v3d_gem.c | 49 +++-------------------------------- 1 file changed, 3 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c index 31a37572c11d..6e152ef26358 100644 --- a/drivers/gpu/drm/v3d/v3d_gem.c +++ b/drivers/gpu/drm/v3d/v3d_gem.c @@ -299,10 +299,6 @@ v3d_lookup_bos(struct drm_device *dev, u64 bo_handles, u32 bo_count) { - u32 *handles; - int ret = 0; - int i; - job->bo_count = bo_count; if (!job->bo_count) { @@ -313,48 +309,9 @@ v3d_lookup_bos(struct drm_device *dev, return -EINVAL; } - job->bo = kvmalloc_array(job->bo_count, - sizeof(struct drm_gem_dma_object *), - GFP_KERNEL | __GFP_ZERO); - if (!job->bo) { - DRM_DEBUG("Failed to allocate validated BO pointers\n"); - return -ENOMEM; - } - - handles = kvmalloc_array(job->bo_count, sizeof(u32), GFP_KERNEL); - if (!handles) { - ret = -ENOMEM; - DRM_DEBUG("Failed to allocate incoming GEM handles\n"); - goto fail; - } - - if (copy_from_user(handles, - (void __user *)(uintptr_t)bo_handles, - job->bo_count * sizeof(u32))) { - ret = -EFAULT; - DRM_DEBUG("Failed to copy in GEM handles\n"); - goto fail; - } - - spin_lock(&file_priv->table_lock); - for (i = 0; i < job->bo_count; i++) { - struct drm_gem_object *bo = idr_find(&file_priv->object_idr, - handles[i]); - if (!bo) { - DRM_DEBUG("Failed to look up GEM BO %d: %d\n", - i, handles[i]); - ret = -ENOENT; - spin_unlock(&file_priv->table_lock); - goto fail; - } - drm_gem_object_get(bo); - job->bo[i] = bo; - } - spin_unlock(&file_priv->table_lock); - -fail: - kvfree(handles); - return ret; + return drm_gem_objects_lookup(file_priv, + (void __user *)(uintptr_t)bo_handles, + job->bo_count, &job->bo); } static void