From patchwork Thu Feb 21 11:14:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Qian Wang X-Patchwork-Id: 10823699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E3286C2 for ; Thu, 21 Feb 2019 11:14:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B59B283E7 for ; Thu, 21 Feb 2019 11:14:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E7B4284FF; Thu, 21 Feb 2019 11:14:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A7557283E7 for ; Thu, 21 Feb 2019 11:14:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 16701891C5; Thu, 21 Feb 2019 11:14:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130078.outbound.protection.outlook.com [40.107.13.78]) by gabe.freedesktop.org (Postfix) with ESMTPS id E45BC891C5 for ; Thu, 21 Feb 2019 11:14:06 +0000 (UTC) Received: from DB6PR0801MB1990.eurprd08.prod.outlook.com (10.168.81.21) by DB6PR0801MB1814.eurprd08.prod.outlook.com (10.169.225.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1643.16; Thu, 21 Feb 2019 11:14:02 +0000 Received: from DB6PR0801MB1990.eurprd08.prod.outlook.com ([fe80::1167:5c79:88ab:7a7c]) by DB6PR0801MB1990.eurprd08.prod.outlook.com ([fe80::1167:5c79:88ab:7a7c%7]) with mapi id 15.20.1643.014; Thu, 21 Feb 2019 11:14:02 +0000 From: "james qian wang (Arm Technology China)" To: Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "maxime.ripard@bootlin.com" , "sean@poorly.run" Subject: [PATCH] drm: Fix writeback_job leak when state is check only or check failed Thread-Topic: [PATCH] drm: Fix writeback_job leak when state is check only or check failed Thread-Index: AQHUydaNjeiL3C8urU2BnDwUE772lw== Date: Thu, 21 Feb 2019 11:14:02 +0000 Message-ID: <20190221111304.846-1-james.qian.wang@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [113.29.88.7] x-clientproxiedby: HK0PR01CA0008.apcprd01.prod.exchangelabs.com (2603:1096:203:92::20) To DB6PR0801MB1990.eurprd08.prod.outlook.com (2603:10a6:4:6c::21) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 97568516-8531-475a-3887-08d697edaf55 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600110)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB6PR0801MB1814; x-ms-traffictypediagnostic: DB6PR0801MB1814: nodisclaimer: True x-microsoft-exchange-diagnostics: 1; DB6PR0801MB1814; 20:nsBElDmj3FlKI40VqWUJObVpQ2UjcWcsEuMGrFxk/Vx58BYupsy6sPWdIKB5h6ikacOTVFOTbaxaAyjkW7kwXhWQS/pPeBrayjK/19nnOKrci5ECR79JRfsSYX/lFaPfOTGVGioFiww7P0g8kXI9oAW83F24UBpwdHYlv8wEosY= x-microsoft-antispam-prvs: x-forefront-prvs: 09555FB1AD x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(346002)(396003)(366004)(39860400002)(136003)(189003)(199004)(36756003)(81156014)(186003)(81166006)(71200400001)(7736002)(316002)(71190400001)(305945005)(54906003)(486006)(8936002)(256004)(110136005)(86362001)(476003)(2616005)(2201001)(2501003)(14444005)(8676002)(3846002)(26005)(6116002)(478600001)(14454004)(105586002)(106356001)(66066001)(25786009)(2906002)(103116003)(68736007)(50226002)(4326008)(6486002)(6512007)(386003)(52116002)(1076003)(6506007)(97736004)(55236004)(5660300002)(99286004)(102836004)(6436002)(53936002); DIR:OUT; SFP:1101; SCL:1; SRVR:DB6PR0801MB1814; H:DB6PR0801MB1990.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 7ZsRZIu8wNGDWU2Mu4zxFKSB0jqoZVuocQS4vIrx6x4ttCJWg5xHoyR8KPKiTnK53gUlLDQMHscxW9LURUutcxe+/O8YWuw/oJUN0ZbqsnFKPXwFf01/Bz7U4I+Zh+J7BSeU8B143Ph/tVOc0zMDmGh/byO5wKbxcybYU+W9Bsd6UBzLXu8EGYFcpNA6k7J0K1iV41Tx1F+g18vwblwgUX8VvUA293co0Q33Suum07B4xx5rQ+ja5N1Xa6zE6rGO2LyVFTp5Sy1ZZXhOG3jtWwqAeeERvRQFBlnLUU2NG+U53PbB4ScJCQJVKMN4xERUqGFh29IcLKVV96mWvsiYCEaOreii570B4WrJTwZz1PveKnLyr7FQf70doanY/AESmrC5A1y2RTu0QlrgPsaeTVxnxJLVG7Z2Z5OKu6Qjuk0= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97568516-8531-475a-3887-08d697edaf55 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Feb 2019 11:13:58.5502 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1814 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/pXpdt17+SxnhqRGO2ln7ilzxehH0GFIrG+2ZCg2N7M=; b=BxQs/M2mPPM2n8qZNfBpY2gYWpYRiTIYElXCpj2rDp5ap6unBCjO2mAjfTG6XzDGBFx94E9u1YkCchwrSoxvGTF4PwZBvy/Hvd/gh6OfY/BXtBRA7H/P47Ud5L6oJ5P2K+al+jldbTvGIq+ZSzTnCjVfWUYSSFvuukjBw4K+oOc= X-Mailman-Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Jonathan Chai \(Arm Technology China\)" , "dri-devel@lists.freedesktop.org" , "Julien Yin \(Arm Technology China\)" , "james qian wang \(Arm Technology China\)" , nd Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The writeback job will not be added to writeback queue if the state is check only or check failed, to avoid leak, need to cleanup writeback job in connector_destroy_state if the job existed. Signed-off-by: James Qian Wang (Arm Technology China) --- drivers/gpu/drm/drm_atomic_state_helper.c | 4 ++++ drivers/gpu/drm/drm_writeback.c | 21 ++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c index 4985384e51f6..6a8e414233de 100644 --- a/drivers/gpu/drm/drm_atomic_state_helper.c +++ b/drivers/gpu/drm/drm_atomic_state_helper.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -407,6 +408,9 @@ EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state); void __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state) { + if (state->writeback_job) + drm_writeback_cleanup_job(state->writeback_job); + if (state->crtc) drm_connector_put(state->connector); diff --git a/drivers/gpu/drm/drm_writeback.c b/drivers/gpu/drm/drm_writeback.c index c20e6fe00cb3..486121150eaa 100644 --- a/drivers/gpu/drm/drm_writeback.c +++ b/drivers/gpu/drm/drm_writeback.c @@ -268,6 +268,22 @@ void drm_writeback_queue_job(struct drm_writeback_connector *wb_connector, } EXPORT_SYMBOL(drm_writeback_queue_job); +/** + * drm_writeback_cleanup_job - cleanup a writeback job + * @job: The job to cleanup + */ +void drm_writeback_cleanup_job(struct drm_writeback_job *job) +{ + if (job->fb) + drm_framebuffer_put(job->fb); + + if (job->out_fence) + dma_fence_put(job->out_fence); + + kfree(job); +} +EXPORT_SYMBOL(drm_writeback_cleanup_job); + /* * @cleanup_work: deferred cleanup of a writeback job * @@ -280,11 +296,9 @@ static void cleanup_work(struct work_struct *work) struct drm_writeback_job *job = container_of(work, struct drm_writeback_job, cleanup_work); - drm_framebuffer_put(job->fb); - kfree(job); + drm_writeback_cleanup_job(job); } - /** * drm_writeback_signal_completion - Signal the completion of a writeback job * @wb_connector: The writeback connector whose job is complete @@ -319,6 +333,7 @@ drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector, dma_fence_set_error(job->out_fence, status); dma_fence_signal(job->out_fence); dma_fence_put(job->out_fence); + job->out_fence = NULL; } } spin_unlock_irqrestore(&wb_connector->job_lock, flags);