From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.3 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6CC29C433DF for ; Mon, 15 Jun 2020 07:29:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3FFE52068E for ; Mon, 15 Jun 2020 07:29:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R9dTqLFq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3FFE52068E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBF716E29E; Mon, 15 Jun 2020 07:27:24 +0000 (UTC) Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75B0989B57; Mon, 15 Jun 2020 06:12:32 +0000 (UTC) Received: by mail-io1-xd41.google.com with SMTP id r2so16595781ioo.4; Sun, 14 Jun 2020 23:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MpaNV/qQKz10iqV54hZ3d06qChO86uOpWp9hsgu+lWY=; b=R9dTqLFqtzTAkZcs7wraz0nABjqsFyXZgImHWAjW/JRpifRBjCvM4fhxHp9/gej4n5 DNMG3Ht6UnmJefKwqtmlhhw6gIS51mdT1Y03Dnl9+jenWXLpeSk0+rwg8O4nQtCext1X nN6yPFGPJ+ELR06ivu2dPofx7LFNSa56L2y+2g3mphJQsRxGkMX1+fAFWN3JLabu4yBa O0YY12KchtNRz8i9AUYqDcaxqSQcOnKPDZ8O/HCnOaFRm4DSY0kKjelxhtlSXgZ0kMnS I1pPgussUNro4NKXQN6Zm8TzPLvyU8Ak5siiRMN+2tg6y27KxK1az6mPo3c1JgSpplOw J5oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MpaNV/qQKz10iqV54hZ3d06qChO86uOpWp9hsgu+lWY=; b=RH5hX2PlB0zVqRH8nMJmklCSMj6UaST9flAdfeqPTVMubiTAG4kyo/F11bScP8jefU 4jdgLcT69duIAI+HhhI43vAMEqtfBQHANPDhvRhWM/5tzsejXr4FhWeOJYZk4GJQ0TrK dzI86r6kYc1ovwWZ2N0EwS5B/CK0x6kyn7B1t/E66gONmpN8Z8QI25kK1K374ibRuIId ihiHBHD60tIjKzmQY9KoC7VTaImy5HUyV6OwlzLEQKv6ZZFmsuvxaR9/mK+GhRGnpP7M uxZ6sqNOcWoK+0SP1olwmKLlwk/YHEnQn94/rNICwwQ77jKRWrRR32yQ920hNTuqZOmt ffkg== X-Gm-Message-State: AOAM530tQP3kElqTzUajemxmhIZ9WmIk39nhozI2zOU/mOCX2c//pXxJ +JJB3oinT+NXMzxuJQFY/fA= X-Google-Smtp-Source: ABdhPJyzcnYLaAIqOamesc01+OyA8JCS1/7QXApZEWy/YVtyVV5vBZBB6DNo4QZqY8CgYo+qQnFOqw== X-Received: by 2002:a05:6638:d05:: with SMTP id q5mr19398438jaj.2.1592201551850; Sun, 14 Jun 2020 23:12:31 -0700 (PDT) Received: from cs-u-kase.dtc.umn.edu (cs-u-kase.cs.umn.edu. [160.94.64.2]) by smtp.googlemail.com with ESMTPSA id c3sm7421822ilr.45.2020.06.14.23.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 23:12:31 -0700 (PDT) From: Navid Emamdoost To: Lucas Stach , Russell King , Christian Gmeiner , David Airlie , Daniel Vetter , etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm/etnaviv: fix ref count leak via pm_runtime_get_sync Date: Mon, 15 Jun 2020 01:12:20 -0500 Message-Id: <20200615061220.68711-1-navid.emamdoost@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-Mailman-Approved-At: Mon, 15 Jun 2020 07:27:17 +0000 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: kjlu@umn.edu, mccamant@cs.umn.edu, andy.shevchenko@gmail.com, emamd001@umn.edu, wu000273@umn.edu, Navid Emamdoost MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" in etnaviv_gpu_submit, etnaviv_gpu_recover_hang, etnaviv_gpu_debugfs, and etnaviv_gpu_init the call to pm_runtime_get_sync increments the counter even in case of failure, leading to incorrect ref count. In case of failure, decrement the ref count before returning. Signed-off-by: Navid Emamdoost --- Changes in v2: - replace pm_runtime_put with pm_runtime_put_noidle --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index a31eeff2b297..7c9f3f9ba123 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -722,7 +722,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) ret = pm_runtime_get_sync(gpu->dev); if (ret < 0) { dev_err(gpu->dev, "Failed to enable GPU power domain\n"); - return ret; + goto pm_put; } etnaviv_hw_identify(gpu); @@ -819,6 +819,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) fail: pm_runtime_mark_last_busy(gpu->dev); +pm_put: pm_runtime_put_autosuspend(gpu->dev); return ret; @@ -859,7 +860,7 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m) ret = pm_runtime_get_sync(gpu->dev); if (ret < 0) - return ret; + goto pm_put; dma_lo = gpu_read(gpu, VIVS_FE_DMA_LOW); dma_hi = gpu_read(gpu, VIVS_FE_DMA_HIGH); @@ -1003,6 +1004,7 @@ int etnaviv_gpu_debugfs(struct etnaviv_gpu *gpu, struct seq_file *m) ret = 0; pm_runtime_mark_last_busy(gpu->dev); +pm_put: pm_runtime_put_autosuspend(gpu->dev); return ret; @@ -1016,7 +1018,7 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu) dev_err(gpu->dev, "recover hung GPU!\n"); if (pm_runtime_get_sync(gpu->dev) < 0) - return; + goto pm_put; mutex_lock(&gpu->lock); @@ -1035,6 +1037,7 @@ void etnaviv_gpu_recover_hang(struct etnaviv_gpu *gpu) mutex_unlock(&gpu->lock); pm_runtime_mark_last_busy(gpu->dev); +pm_put: pm_runtime_put_autosuspend(gpu->dev); } @@ -1308,8 +1311,10 @@ struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit) if (!submit->runtime_resumed) { ret = pm_runtime_get_sync(gpu->dev); - if (ret < 0) + if (ret < 0) { + pm_runtime_put_noidle(gpu->dev); return NULL; + } submit->runtime_resumed = true; } @@ -1326,6 +1331,7 @@ struct dma_fence *etnaviv_gpu_submit(struct etnaviv_gem_submit *submit) ret = event_alloc(gpu, nr_events, event); if (ret) { DRM_ERROR("no free events\n"); + pm_runtime_put_noidle(gpu->dev); return NULL; } -- 2.17.1 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel