Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2664028pxa; Mon, 17 Aug 2020 15:56:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWAtxN563zP/D/sI/zfTWsVvOfHlzLMTvUsfg/q+VZ0OAsSKsfRo8sRPZk0wOFdDZLtrNZ X-Received: by 2002:a17:906:eca4:: with SMTP id qh4mr16941308ejb.255.1597705000831; Mon, 17 Aug 2020 15:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597705000; cv=none; d=google.com; s=arc-20160816; b=S4PCVEOXnI78fN3dpKI5FzYNMInWKXyqQ2GDmZKYOQUOK+p9fx5A96oLS+8GxFoPHn vc9sZCzbAsYU1m44St/054VioCsxWHqkJij9drHii1epM31u/0eLSzC7yuVFGWXn0HCK zpNVaqsbnl7U65PYyg0Z/HzR7g2bFJcQrG4PV8EtVxdkBP07FIyhAJoMfkUyMk0XI1/h K9RR3c6xSbT5REOnkYuS3KOBBN1ri+gYuEPxzt4SMBCeJXBVNQCxjUpa/25XK+B/hqta XCWO5tdZF322jhmdWgnt2XtNz8w99NqEfxkD561uAwxpVwnfgSLV4o0RZ0cknlr/bUU0 jRRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SIcyt7y4MfUAS9vXBNj5Ymjx8kpz/M/A1ftFXqmZkNg=; b=yS57OalZMtje8j3Ih2lqHw1STVyWPsElwt3nLNyGNJGaoF6jt2UykVh8K0E4QQjbiF fPf7Ulv4CsBMAzR4eINUllaES5DzMAGLh1KGFKonT5hCaa5c8/DbYLtrXchEgQkWs/QS SEOkbru4VEHjYVfdb5Dp0CxQiAs6fWVyH94pbX1ezqw4wtoiglDxdGfjUngwiKAlRvMw ZyEvI/84OcWIY3GrlEy+WbPPqn+gAjkMWpqv3u4ELn+NllBK+qBrawihPQvFEeKOOIY4 RJ/Mdlpa27U6AjaaQpSUdm8IhR+hqTXZnmoKs8I2fDz72Cvvn96MdeJUqxGKWAifpqgz c/nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G3Pl5pkX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f9si11597870edw.239.2020.08.17.15.56.17; Mon, 17 Aug 2020 15:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=G3Pl5pkX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404358AbgHQTpI (ORCPT + 99 others); Mon, 17 Aug 2020 15:45:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:46764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729223AbgHQPWb (ORCPT ); Mon, 17 Aug 2020 11:22:31 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0EFC320709; Mon, 17 Aug 2020 15:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597677749; bh=1hUmOdoEj32TW0X8WVtmQHKVAglxkLerFvsfjtaXHtE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G3Pl5pkXg9hWZjmx3FpUiKlRjWWaQkLNq/FME+o9Y7dUna5Vyu1oSmbFG1WuHij6p Iffo6uptZZPFHgG9LdcOlI0WlwEdLD6oOxQRSp5mNJMrMs6kS9Ryb28ymyWn43WKDF wz6iwYATTeQ+oOFCtF/OzByBys+ygA4KIGgQWADA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Navid Emamdoost , Lucas Stach , Sasha Levin Subject: [PATCH 5.8 095/464] drm/etnaviv: fix ref count leak via pm_runtime_get_sync Date: Mon, 17 Aug 2020 17:10:48 +0200 Message-Id: <20200817143838.342436778@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Navid Emamdoost [ Upstream commit c5d5a32ead1e3a61a07a1e59eb52a53e4a6b2a7f ] 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 Signed-off-by: Lucas Stach Signed-off-by: Sasha Levin --- 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 a31eeff2b297a..7c9f3f9ba1235 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.25.1