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: 29698 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2284290wrr; Mon, 5 Dec 2022 06:25:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf7vMaE/pxzNDKs2B062j5CkaWvMX0oD6N8AYRYHtJMOJl1/dc7rCc6y2R9iCocEu6ZvtRkX X-Received: by 2002:a17:906:f05:b0:7b2:c575:2ee8 with SMTP id z5-20020a1709060f0500b007b2c5752ee8mr54329044eji.136.1670250311884; Mon, 05 Dec 2022 06:25:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670250311; cv=none; d=google.com; s=arc-20160816; b=atHdwtK7oRdx4x55Qp3L4JXaRzkn4Wdm6CRVcLIAlpj/ENb7Aoj1+EJrcGJl7EcLS0 JStHfQm9/XLYHyTz4BTocaLG6PyKhe65RpgLbUHvKBugF+1mTknD5UcAedO+xTpzu7dG zhEaCsgdETxvfDift6PEFRC/uyeHPjiyx+x+Kh3dm6k8xmKndoM0tywKF90K+NXMgZhf tv0WvJZui9ox2KJMUTyq1wWJcha8eHhmCgV9YO84Xy+IQD6hbbswj+WtMUOFUVWDFhPk tnpjX7ojr+1tl7NoYCT+MWD4KlZf468s0m1sPIL6dGQO0QJto40UpFhn8RawG4Pt9TnK +DSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KsNzkwVwgR+cEA5X8iXb1kE6xx18RGkmAb0qmlWlRgg=; b=rfVvs/Vg4/85x/n4MzupecOoyiDUf3tSLFtDM3UqAG1ygwSy6zjqnjtzmjFVgD9L00 lcckE65WXg/MmACP+oVFyCCJsgsxdieq0ijAP9otlLbhDIQ70cm/P9p1YUgjbdsCZSMZ lD561Rob9HHcf0A19U0Pv1UzrHl6TVUlt62V9xKh5ewzBM17gPl6bFW6Nf6yDEwDBP0I 6OafG51mURKoUIXgbyBFfDwSuQNFZu/8J56kpIKMRQxnjPqB27H0yi2KlzFE7/zsqyBA WsUH0cUCnXg5ZXsWitp1O44Y5KfOOK86c4w0UFHfjkFEJ5y5nPTXBrUNsIo6LInzXXcJ jOYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=GjaCbrow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho35-20020a1709070ea300b0078277d265bcsi13038361ejc.204.2022.12.05.06.24.46; Mon, 05 Dec 2022 06:25:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=GjaCbrow; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232115AbiLEN4i (ORCPT + 99 others); Mon, 5 Dec 2022 08:56:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230381AbiLEN4a (ORCPT ); Mon, 5 Dec 2022 08:56:30 -0500 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16661257 for ; Mon, 5 Dec 2022 05:56:30 -0800 (PST) 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 Cc: Maxime Ripard , Maarten Lankhorst , Thomas Zimmermann , Maira Canal , kernel-dev@igalia.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751384391265302156?= X-GMAIL-MSGID: =?utf-8?q?1751384391265302156?= 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: 29697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2282978wrr; Mon, 5 Dec 2022 06:22:39 -0800 (PST) X-Google-Smtp-Source: AA0mqf4GdX7/9q/UP+NstDBsCPifpn35POlOheGxGD+D9+IW4A37M96C3jsoJ7mADsIPfbeexHJI X-Received: by 2002:a17:906:594d:b0:7c0:d6ba:c937 with SMTP id g13-20020a170906594d00b007c0d6bac937mr8532378ejr.296.1670250159465; Mon, 05 Dec 2022 06:22:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670250159; cv=none; d=google.com; s=arc-20160816; b=v2TNE9UsZiU9V8t+GQFS6ho0Pdok2c9UJlcQPVfQsPsoBG+XxrAb0AjRfLfJZFhEpH cm91N/NavDWh2W/bf3Jt0J7JlQl37BQdTKTkiM5iGismngcVhBOKzssxqWSKLgF81nzu 2l/7GbnJBKXSZ8TFB29DGvy7mRlaD2llqxOepbOvYHzF43arcniU/wnLg8JU9BpIS38W 8gxS3ddZtTygLcUro/SXPd2DiHXZ10Y5Qz08E+88gLyeMv5S6O7sS2cBLGB6HumqsXjS dy6lkfVTT1VoS02KvIlHC0urIHJRUOhjnXgzj876J54ANx8gY1YrUY36J5OatExn3obS CYkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uZS2YlPKAGNQfivHgbSmAIM4sCwER+o4TAV8vJgXz8w=; b=Thwxdp8lZP60KTlkM3+n6kGFd8Ldx73Vu4Ju3riXVl99GPMc2Dm5DJ7QImtJxIha2i s1xVpwImhRzWyT0juWuhTMI7DT6QYCb7r0IW5tKzUk6H/aS70gh4v+sNQwlebICaWyIH lGi4wY9nNsaec3dMVN1aoXmLHnina2n7oSFCLCZtoj0wlFpVRVbF891QUyMPU5NSNBVV c0+4xYaseEyb43Zxit5Z4zpJWEYDf0KtajdiS7Fx8ruQssDF8ALtG8jOKkNfsL7PCkSG Z9TZmXKoMu4hyIuIe/PFKICxMgSSb1omiZKpldkFwEA1oJEtiTviH+kzvKfJBImuL0YZ 0+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=HQzjLtss; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020aa7d845000000b004674aa77346si11198292eds.72.2022.12.05.06.22.14; Mon, 05 Dec 2022 06:22:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@igalia.com header.s=20170329 header.b=HQzjLtss; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231998AbiLEN4c (ORCPT + 99 others); Mon, 5 Dec 2022 08:56:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231416AbiLEN4a (ORCPT ); Mon, 5 Dec 2022 08:56:30 -0500 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01A593B8 for ; Mon, 5 Dec 2022 05:56:27 -0800 (PST) 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 Cc: Maxime Ripard , Maarten Lankhorst , Thomas Zimmermann , Maira Canal , kernel-dev@igalia.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751384231183209255?= X-GMAIL-MSGID: =?utf-8?q?1751384231183209255?= 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