Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp3510902ioa; Tue, 26 Apr 2022 05:10:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYLYua6/i0jG5wYzcHLGchU9AiB1GxFH+fXORkZvZdQIkkmHwq5uPW19JsdltCBD9AXwZb X-Received: by 2002:a17:907:7b96:b0:6f0:2922:7ff8 with SMTP id ne22-20020a1709077b9600b006f029227ff8mr20848253ejc.398.1650975019781; Tue, 26 Apr 2022 05:10:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650975019; cv=none; d=google.com; s=arc-20160816; b=Qcd+VIYqFG/Z9f+yfyGrW33hLeUJekkyX1YXeohBGxqh0Qt26Zmks20idUiEW/KwKx lz2R3QHQTAnUP4BEkelUPegVTyKg/OclknBrWSFxSz2X8bHCeeOsxU5gXXkOWmyy2PTQ UPpk5F7FUqNTZWt7qRfq22i1ZUrCNell4xY54SFLxD9tDHamV+UlunVNAkW11BxZ0J/d hnjCa3Y/7z09519rjuk0A9zHqPsHe/Jl6MRi+Dn5AoV34drU9qGY7e20Zq1n0s0HELqd fwsVkkwd41+E9FO47PpfBXG3YmIUkR2WukFr+d8IrbE08IOcKyVGLnJM25uklAH/6AUV 8UIQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2qsCBIu17x7l/RoXFrc5otSAkn0d1vOw6717eQixxIo=; b=G3K9lTX/RqYRlEOpwE+MFpkDIhFOe/IE/8FjlHRQTQR2cHJBoyv+i/bK8cnbAStbtJ C18YlMkMQNJzQIXfgjo3OTz11Ylpayc+fD2ecUj7X5t0y6Wj/ag6BCjoHqAeoDPNXRIR fhZqT6Ss1mNosnICjPZBcA+VBMkFvKmW1RaUQGZDu3Up+BikbAFRIVNGCQAciIyqTA54 gdYw3BpWj7C6Esa0EGrGB+FZKHYKdfD60XgmnPGKR27I7Tps0l8scECnNKEZg38ADe2e U64OGlqYPgJ7mmLfQV7ltB/MrqGGVfbVYYnHBcZ16pq05DWyPaHTjY8KyCo2w65KqR5a m3gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=SGvrIUIg; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q26-20020a1709066ada00b006e01f1d9677si15637887ejs.532.2022.04.26.05.09.43; Tue, 26 Apr 2022 05:10:19 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=SGvrIUIg; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345313AbiDZJBv (ORCPT + 99 others); Tue, 26 Apr 2022 05:01:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346955AbiDZIpk (ORCPT ); Tue, 26 Apr 2022 04:45:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 445BF3DDD8; Tue, 26 Apr 2022 01:36:58 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 21818618E8; Tue, 26 Apr 2022 08:36:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DBBB0C385A4; Tue, 26 Apr 2022 08:36:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962217; bh=+2Fi1ILVgr/TXV+c7AXwJyqn3eo8rkvAxRa7kZL1PaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SGvrIUIgPCHbe/uA5RP1C47y6okoqHtb5PfTNM1dsiYON6KYELtx2o8JhnVIJS/dg 5u4DJ2H8vwyH2h+2WFXp3v4xFAYl1NB+wlgEYq1y4Oii8EfPJynxl5rovOQ5gFm2Yv 2k6srU7HE5811mWU5o3rTKW7t8OakllT4fd3QXE0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Qilong , Vinod Koul , Sasha Levin Subject: [PATCH 5.15 024/124] dmaengine: mediatek:Fix PM usage reference leak of mtk_uart_apdma_alloc_chan_resources Date: Tue, 26 Apr 2022 10:20:25 +0200 Message-Id: <20220426081747.992031554@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081747.286685339@linuxfoundation.org> References: <20220426081747.286685339@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: zhangqilong [ Upstream commit 545b2baac89b859180e51215468c05d85ea8465a ] pm_runtime_get_sync will increment pm usage counter even it failed. Forgetting to putting operation will result in reference leak here. We fix it: 1) Replacing it with pm_runtime_resume_and_get to keep usage counter balanced. 2) Add putting operation before returning error. Fixes:9135408c3ace4 ("dmaengine: mediatek: Add MediaTek UART APDMA support") Signed-off-by: Zhang Qilong Link: https://lore.kernel.org/r/20220319022142.142709-1-zhangqilong3@huawei.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/mediatek/mtk-uart-apdma.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/dma/mediatek/mtk-uart-apdma.c b/drivers/dma/mediatek/mtk-uart-apdma.c index 375e7e647df6..a1517ef1f4a0 100644 --- a/drivers/dma/mediatek/mtk-uart-apdma.c +++ b/drivers/dma/mediatek/mtk-uart-apdma.c @@ -274,7 +274,7 @@ static int mtk_uart_apdma_alloc_chan_resources(struct dma_chan *chan) unsigned int status; int ret; - ret = pm_runtime_get_sync(mtkd->ddev.dev); + ret = pm_runtime_resume_and_get(mtkd->ddev.dev); if (ret < 0) { pm_runtime_put_noidle(chan->device->dev); return ret; @@ -288,18 +288,21 @@ static int mtk_uart_apdma_alloc_chan_resources(struct dma_chan *chan) ret = readx_poll_timeout(readl, c->base + VFF_EN, status, !status, 10, 100); if (ret) - return ret; + goto err_pm; ret = request_irq(c->irq, mtk_uart_apdma_irq_handler, IRQF_TRIGGER_NONE, KBUILD_MODNAME, chan); if (ret < 0) { dev_err(chan->device->dev, "Can't request dma IRQ\n"); - return -EINVAL; + ret = -EINVAL; + goto err_pm; } if (mtkd->support_33bits) mtk_uart_apdma_write(c, VFF_4G_SUPPORT, VFF_4G_SUPPORT_CLR_B); +err_pm: + pm_runtime_put_noidle(mtkd->ddev.dev); return ret; } -- 2.35.1