media: platform: mtk-mdp3: fix PM reference leak in mdp_comp_clock_on()

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: 61890ccaef ("media: platform: mtk-mdp3: add MediaTek MDP3 driver")
Signed-off-by: Sun Ke <sunke32@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
This commit is contained in:
Sun Ke 2022-09-02 10:58:19 +02:00 committed by Mauro Carvalho Chehab
parent dec7920e55
commit ff464745e4

View File

@ -682,7 +682,7 @@ int mdp_comp_clock_on(struct device *dev, struct mdp_comp *comp)
int i, ret; int i, ret;
if (comp->comp_dev) { if (comp->comp_dev) {
ret = pm_runtime_get_sync(comp->comp_dev); ret = pm_runtime_resume_and_get(comp->comp_dev);
if (ret < 0) { if (ret < 0) {
dev_err(dev, dev_err(dev,
"Failed to get power, err %d. type:%d id:%d\n", "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, dev_err(dev,
"Failed to enable clk %d. type:%d id:%d\n", "Failed to enable clk %d. type:%d id:%d\n",
i, comp->type, comp->id); i, comp->type, comp->id);
pm_runtime_put(comp->comp_dev);
return ret; return ret;
} }
} }
@ -930,7 +931,7 @@ void mdp_comp_destroy(struct mdp_dev *mdp)
if (mdp->comp[i]) { if (mdp->comp[i]) {
pm_runtime_disable(mdp->comp[i]->comp_dev); pm_runtime_disable(mdp->comp[i]->comp_dev);
mdp_comp_deinit(mdp->comp[i]); mdp_comp_deinit(mdp->comp[i]);
kfree(mdp->comp[i]); devm_kfree(mdp->comp[i]->comp_dev, mdp->comp[i]);
mdp->comp[i] = NULL; mdp->comp[i] = NULL;
} }
} }