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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D538ECAAD8 for ; Fri, 23 Sep 2022 06:25:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:CC:To: Subject:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uKrkKE5Kh11NW1Kr8+F3zgEw0NFRTmFA2wcjR5zrI8I=; b=KB+CYNlII0FBJCGkxgdoa/8a6b JoLtezI3+k/QFSU5go7YsPOUDKGJ21xQ28XD5b9vXG4v1LvRjsq316nqRoJlxhl97NNtvtt5OUzds Kc5gFOIeZodpbu7L+nI56V2YohMSgbXTU4lfHkTjKFB8/rnWbm5FvMdhO80BxhidQDPfKLm/tKNtm DNR00K+WM54L8OA7mmkSgLFDffHaCv4afK8T8LPnXjlT98AjBsOw6zDUC1LVlV18LrGy6oQq03+Uu gK6KA70NLpklJ1h6o93E17R/Yp74gMXxQqHAQE/bMB2DbviVlb8Cn7LBu98Ur+UDoUm2BmArk7IXE hUCGb2Ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1obc7t-002Rcq-83; Fri, 23 Sep 2022 06:25:29 +0000 Received: from szxga02-in.huawei.com ([45.249.212.188]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1obc7i-002RYO-1C; Fri, 23 Sep 2022 06:25:19 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MYhpb5MpdzMp1N; Fri, 23 Sep 2022 14:20:23 +0800 (CST) Received: from kwepemm600010.china.huawei.com (7.193.23.86) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 23 Sep 2022 14:25:06 +0800 Received: from [10.174.178.31] (10.174.178.31) by kwepemm600010.china.huawei.com (7.193.23.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 23 Sep 2022 14:25:05 +0800 Subject: Re: [PATCH 2/3] media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on() To: , , , , , CC: , , , References: <20220902085820.3777360-1-sunke32@huawei.com> <20220902085820.3777360-3-sunke32@huawei.com> From: Sun Ke Message-ID: <38c78ee6-8b7e-34fb-1dc0-8b2d28acdd3d@huawei.com> Date: Fri, 23 Sep 2022 14:25:05 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20220902085820.3777360-3-sunke32@huawei.com> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.31] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600010.china.huawei.com (7.193.23.86) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220922_232518_267080_E8DA8872 X-CRM114-Status: GOOD ( 13.12 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org ping... ÔÚ 2022/9/2 16:58, Sun Ke дµÀ: > mdp_comp_clock_on will increase runtime PM usage counter, > and mdp_comp_clock_off will decrease the runtime PM usage counter. > so, if mdp_comp_clock_on failed after increment runtime PM usage > counter, it should decrease it before return a error code. > > pm_runtime_get_sync will increment pm usage counter even it failed. > Forgetting to putting operation will result in reference leak here. > Fix it by replacing it with pm_runtime_resume_and_get to keep usage > counter balanced. > > And if failed to enable clk, add pm_runtime_put() to decrease the > runtime PM usage counter. > > Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver") > Signed-off-by: Sun Ke > --- > drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c > index 9a6ba5851ccb..d3eaf8884412 100644 > --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c > +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c > @@ -682,7 +682,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp) > int i, ret; > > if (comp->comp_dev) { > - ret = pm_runtime_get_sync(comp->comp_dev); > + ret = pm_runtime_resume_and_get(comp->comp_dev); > if (ret < 0) { > dev_err(dev, > "Failed to get power, err %d. type:%d id:%d\n", > @@ -699,6 +699,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp) > dev_err(dev, > "Failed to enable clk %d. type:%d id:%d\n", > i, comp->type, comp->id); > + pm_runtime_put(comp->comp_dev); > return ret; > } > } >