From patchwork Fri Nov 11 03:38:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ChunyouTang X-Patchwork-Id: 18432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp520098wru; Thu, 10 Nov 2022 19:41:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf5QpEx5a9eLNItUS8TE5LEZJ+IVEbQuNPVXU/G+62vqoP6t6NwJBVPwu4EM5++ItM+t8lPz X-Received: by 2002:a17:906:4e16:b0:7ae:72ae:1f85 with SMTP id z22-20020a1709064e1600b007ae72ae1f85mr429685eju.133.1668138098269; Thu, 10 Nov 2022 19:41:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668138098; cv=none; d=google.com; s=arc-20160816; b=FH9M5MedlFnSidicSAdMpg+mORgaSp/AMoe2WZ8fif+i+/jxzd8kl7aPcb6VvqMIxf S+ZkuHHryVU5lKvEaM8myA8C1hRE3OtLP7l9bYpui0L4UGc2KrK+xgX2VOiW0nGGEWtx YDOQwNeF4BBoVopXy3CH+xNIC4JsYX94v1o6pBxxwu4pnSBVWn/ue9+bPI5DkAqlfdM7 bTH6dDenpYFlFF4cnOEIjV65uxnN5bf7A9PDfU0uB7wavarclJRrWXahn4oNjpQ9421q UKSeFNJ2wPlzHBfx602jAyf6s1BKCC1mPcJqXbrEjwjH2BhYWK4Tf6Crc02IPw9qlE2L 0UFA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=8SnPH5Qx6ge1EtKB0f/nVg1sCMMgt2pTaFXFocUqJa8=; b=TGovOdxtBQNOp5DBgyQsIsIvqPXwoGkw9InCYnVqq8Nxd0R8sdivoGvMn93jJ1d+Ll HKtJo0ynlniS9u8D0NzDuhPvVDQv5NIS7vGzM9UKyOyTOBrgz6fUv2rm4wZ12Xc3MJkm N8Q79OYCOEu6NnQVVJl0XZs4dBLy8lSh1OPxeo4qhLuHpzREu5U3+aAMty3uy9zTpJUn LPPR/o8+m1lUaUQRGFhaqgzZwuG2Y+vTvxniHFHqlAFGYESzoAAWYT1Wu6HWRHKsrNHA Eo4e9xp3WJ2+7GrWV+ZHvMDXL3Wic8fb8u6D2PXODR6PPtMPx/7HyC1bIudH5/AeokJ0 O4Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=c5Zqxv7R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw24-20020a1709066a1800b007807e1f3d9dsi1077174ejc.842.2022.11.10.19.41.15; Thu, 10 Nov 2022 19:41:38 -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=pass header.i=@163.com header.s=s110527 header.b=c5Zqxv7R; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231955AbiKKDjV (ORCPT + 99 others); Thu, 10 Nov 2022 22:39:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbiKKDjU (ORCPT ); Thu, 10 Nov 2022 22:39:20 -0500 Received: from m12-14.163.com (m12-14.163.com [220.181.12.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 77C2514D07; Thu, 10 Nov 2022 19:39:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=8SnPH 5Qx6ge1EtKB0f/nVg1sCMMgt2pTaFXFocUqJa8=; b=c5Zqxv7RjLUYIxVx+RVnW DwURkjfLUI5XBmNpLX8cpiPNSs3ueEPl19EMAeGrpTlwsJPfVknBFld3Oc4dILfB ppgfO/V0tg6DzqCfunszw3zq9IFS9zDZfj2GyBcD4INCR8F/ICS6AxsL9+4FdeDm i2hcRxAuX/Qu9K4sQcTd84= Received: from localhost.localdomain (unknown [114.221.197.143]) by smtp10 (Coremail) with SMTP id DsCowABH7bG4w21jBvxXMA--.32326S2; Fri, 11 Nov 2022 11:38:39 +0800 (CST) From: ChunyouTang To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch, sumit.semwal@linaro.org, christian.koenig@amd.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, ChunyouTang Subject: [PATCH v2] drm/gem-shmem: When drm_gem_object_init failed, should release object Date: Fri, 11 Nov 2022 11:38:17 +0800 Message-Id: <20221111033817.366-1-tangchunyou@163.com> X-Mailer: git-send-email 2.30.0.windows.1 MIME-Version: 1.0 X-CM-TRANSID: DsCowABH7bG4w21jBvxXMA--.32326S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAw4DXw1ruF43JryxZFW7XFb_yoW5Wryrpa nxAry7KrW8KFZFgrZ7XF4kCa43Gw40gF4xWaySq3yakr10yF1DXFn8Cr1DAFW3Jr17Xr1a q3sFkFySyrWjkF7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0z_6wuUUUUUU= X-Originating-IP: [114.221.197.143] X-CM-SenderInfo: 5wdqwu5kxq50rx6rljoofrz/1tbiYwC2UVaEMNUQPwAAsc X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1749169574666542664?= X-GMAIL-MSGID: =?utf-8?q?1749169574666542664?= when goto err_free, the object had init, so it should be release when fail. Signed-off-by: ChunyouTang --- drivers/gpu/drm/drm_gem.c | 19 ++++++++++++++++--- drivers/gpu/drm/drm_gem_shmem_helper.c | 4 +++- include/drm/drm_gem.h | 1 + 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c index 8b68a3c1e6ab..cba32c46bb05 100644 --- a/drivers/gpu/drm/drm_gem.c +++ b/drivers/gpu/drm/drm_gem.c @@ -169,6 +169,21 @@ void drm_gem_private_object_init(struct drm_device *dev, } EXPORT_SYMBOL(drm_gem_private_object_init); +/** + * drm_gem_private_object_fini - Finalize a failed drm_gem_object + * @obj: drm_gem_object + * + * Uninitialize an already allocated GEM object when it initialized failed + */ +void drm_gem_private_object_fini(struct drm_gem_object *obj) +{ + WARN_ON(obj->dma_buf); + + dma_resv_fini(&obj->_resv); + drm_gem_lru_remove(obj); +} +EXPORT_SYMBOL(drm_gem_private_object_fini); + /** * drm_gem_object_handle_free - release resources bound to userspace handles * @obj: GEM object to clean up. @@ -930,14 +945,12 @@ drm_gem_release(struct drm_device *dev, struct drm_file *file_private) void drm_gem_object_release(struct drm_gem_object *obj) { - WARN_ON(obj->dma_buf); + drm_gem_private_object_fini(obj); if (obj->filp) fput(obj->filp); - dma_resv_fini(&obj->_resv); drm_gem_free_mmap_offset(obj); - drm_gem_lru_remove(obj); } EXPORT_SYMBOL(drm_gem_object_release); diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 35138f8a375c..845e3d5d71eb 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -79,8 +79,10 @@ __drm_gem_shmem_create(struct drm_device *dev, size_t size, bool private) } else { ret = drm_gem_object_init(dev, obj, size); } - if (ret) + if (ret) { + drm_gem_private_object_fini(obj) goto err_free; + } ret = drm_gem_create_mmap_offset(obj); if (ret) diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h index bd42f25e449c..9b1feb03069d 100644 --- a/include/drm/drm_gem.h +++ b/include/drm/drm_gem.h @@ -405,6 +405,7 @@ int drm_gem_object_init(struct drm_device *dev, struct drm_gem_object *obj, size_t size); void drm_gem_private_object_init(struct drm_device *dev, struct drm_gem_object *obj, size_t size); +void drm_gem_private_object_fini(struct drm_gem_object *obj); void drm_gem_vm_open(struct vm_area_struct *vma); void drm_gem_vm_close(struct vm_area_struct *vma); int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,