From patchwork Mon Mar 6 10:07:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 64567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1760857wrd; Mon, 6 Mar 2023 02:25:58 -0800 (PST) X-Google-Smtp-Source: AK7set+5wEIXj58jv1BRlafEiHzE09QsT1equ/FSACWeaY4BrTFXLV5pKm8wBx0GB6aAvC8+EJpf X-Received: by 2002:a17:907:9702:b0:82e:a57b:cc9b with SMTP id jg2-20020a170907970200b0082ea57bcc9bmr10657327ejc.24.1678098358709; Mon, 06 Mar 2023 02:25:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678098358; cv=none; d=google.com; s=arc-20160816; b=gf7KzDWKe3060Xb6fIloK7X4QD4iu5caBmeDnDcZ4Iq4JWRt+sMZufhZZsCWAoDxRo af+P3k7ekENlvovdbd3FY8FO4n9ncz8nVzvBnjd+qep4RqC6TatH8VTi26H9jJ5IUwaB jBAR14XsIRzMrcGVVNZa1IYctb14MFCPACKhHHTy/nWGtKSIc59ThgLquqzvmLEivFsc OSfkesOUQU/qF8fv3oF6NQsmMdagdeAY3WU+QEw25k0XPbCpuL4WTOeHGDcJgkct854a Yw44KZri7YSj8nldtBNhCf1D+6RMTaOVnC6d2fYLVKXiAxBT5lnotChGgyykxDjtFGLj KshA== 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=rUzi9VtIfxO5fFJyCiI4CE8G7paqLjzdWeXiiZIIcWI=; b=elxV5zvcI/qMRd6F8aMgWKEFkrqsakY2/kL4n4rr0tXNBFbeSD4+ylnP3HNiXE5cb3 6fPSR56lEKTGBNDkk/H9kwDkiP9pSa+Ul7pK88a1apCpO2pBVmb/nduLvV/rmHZ12fcy C3wsx0uS81SDq1gYIm6YtTGwfmz/RRCdOIw+aVLGejwE46cxuGGBtn50II6oSbMRolRd cCL1yRalU2BVPeMrHru8Qbw1Zm4aCU9e17DpNqAhe+8/lPimo+yKNJrMHVFT4bDLQIim 61r/vXx2L//5v9QQmiFI9aqA1jzCFNylPTb5AUQ/iYCX78DyO6O8r9Dpy/ylVsiMBfPj JYKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kgo+sXz7; 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=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x15-20020a170906134f00b00909ec650e04si8956495ejb.487.2023.03.06.02.25.19; Mon, 06 Mar 2023 02:25:58 -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=@kernel.org header.s=k20201202 header.b=kgo+sXz7; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbjCFKKG (ORCPT + 99 others); Mon, 6 Mar 2023 05:10:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230295AbjCFKJY (ORCPT ); Mon, 6 Mar 2023 05:09:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC72DBDD4; Mon, 6 Mar 2023 02:09:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9866AB80D7E; Mon, 6 Mar 2023 10:09:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1747C433B0; Mon, 6 Mar 2023 10:09:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678097358; bh=uqvw+1pPZqa3n7JUisPLnCC2+5ng04ROJJhyzn6R2aQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kgo+sXz7XTVxNF0eFyruT96oYiVmmTPThA28T0KckXZ4WWNJYYNzEQv2504qqdPfw dRIQJk/iNj7y5NxqWiKSljgClNgwB82YP2hgSzxfVqxL2Bu3v8PIKOD46X3rVYXUPL g+vZAt63IRSksCsoRyOd7I5QWyqF4AE4vXwZEZMehIZP/dS2OnnhVIWxQitO/LLQzj b3y59NTU3AGxYV02OVFYxQy3ALV8yyxzcdByiuz33ETmPBr+LJViAslA/MFwBUnE5Z ggzRuuTKM910iaTqBtC7NmHLDSxIizP0uxLankzyqGNDKSr/0oLw3JCMnXSkDHSAfa ohmugVe96Nceg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1pZ7n5-0007Qo-Er; Mon, 06 Mar 2023 11:09:59 +0100 From: Johan Hovold To: Rob Clark , Abhinav Kumar , Dmitry Baryshkov Cc: Sean Paul , David Airlie , Daniel Vetter , linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Craig Tatlor Subject: [PATCH 06/10] drm/msm: fix vram leak on bind errors Date: Mon, 6 Mar 2023 11:07:18 +0100 Message-Id: <20230306100722.28485-7-johan+linaro@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230306100722.28485-1-johan+linaro@kernel.org> References: <20230306100722.28485-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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?1759613664630020464?= X-GMAIL-MSGID: =?utf-8?q?1759613664630020464?= Make sure to release the VRAM buffer also in a case a subcomponent fails to bind. Fixes: d863f0c7b536 ("drm/msm: Call msm_init_vram before binding the gpu") Cc: stable@vger.kernel.org # 5.11 Cc: Craig Tatlor Signed-off-by: Johan Hovold Reviewed-by: Dmitry Baryshkov --- drivers/gpu/drm/msm/msm_drv.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c index 89634159ad75..41cc6cd690cd 100644 --- a/drivers/gpu/drm/msm/msm_drv.c +++ b/drivers/gpu/drm/msm/msm_drv.c @@ -51,6 +51,8 @@ #define MSM_VERSION_MINOR 10 #define MSM_VERSION_PATCHLEVEL 0 +static void msm_deinit_vram(struct drm_device *ddev); + static const struct drm_mode_config_funcs mode_config_funcs = { .fb_create = msm_framebuffer_create, .output_poll_changed = drm_fb_helper_output_poll_changed, @@ -260,12 +262,7 @@ static int msm_drm_uninit(struct device *dev) if (kms && kms->funcs) kms->funcs->destroy(kms); - if (priv->vram.paddr) { - unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING; - drm_mm_takedown(&priv->vram.mm); - dma_free_attrs(dev, priv->vram.size, NULL, - priv->vram.paddr, attrs); - } + msm_deinit_vram(ddev); component_unbind_all(dev, ddev); @@ -403,6 +400,19 @@ static int msm_init_vram(struct drm_device *dev) return ret; } +static void msm_deinit_vram(struct drm_device *ddev) +{ + struct msm_drm_private *priv = ddev->dev_private; + unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING; + + if (!priv->vram.paddr) + return; + + drm_mm_takedown(&priv->vram.mm); + dma_free_attrs(ddev->dev, priv->vram.size, NULL, priv->vram.paddr, + attrs); +} + static int msm_drm_init(struct device *dev, const struct drm_driver *drv) { struct msm_drm_private *priv = dev_get_drvdata(dev); @@ -449,7 +459,7 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) /* Bind all our sub-components: */ ret = component_bind_all(dev, ddev); if (ret) - goto err_put_dev; + goto err_deinit_vram; dma_set_max_seg_size(dev, UINT_MAX); @@ -547,6 +557,8 @@ static int msm_drm_init(struct device *dev, const struct drm_driver *drv) return ret; +err_deinit_vram: + msm_deinit_vram(ddev); err_put_dev: drm_dev_put(ddev);