Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp452886rwi; Thu, 20 Oct 2022 00:29:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4NepSM/i7Wru7TRrrhlxEPOeVA3IetIuWozC7yFAoNcjY3pqUxOaWuJlTCXsJRJmSvCwHG X-Received: by 2002:a17:906:eec1:b0:782:6384:76be with SMTP id wu1-20020a170906eec100b00782638476bemr9887927ejb.756.1666250949005; Thu, 20 Oct 2022 00:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666250949; cv=none; d=google.com; s=arc-20160816; b=fuJlyRshAGb2Jy3A6B51xu03StzeDEhi801vzGpBJ8McQtbKwOVunN+FGY93kaoL66 eMeoHMqTneq0S8Ae/AloeHKRo213k5hPeWPsbu52lNjhgxnAJ4DTW5+HswDY7pHtSlPF z8q5KfN1+YCQibxvSyCbVMJKMPeyvL26eRePSyiUEmX7Ers4bwbKIxUisCVeTYDfpE2L tyAavFamgP9gbGhbZm+AFCq413qmLFbeXGMKEmGeu8pbg0sNCzAR3nL6ti+hCDTOsCyf +r+l71Js5O0eCf4zoZVaYpuUfxbauxziffmG+vuN7oGx5jc2ZWrjDNJUR0lM1vFUjjPD Xj1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Nu8CkHwHdOQOx7g9RjxSew+cd3IBxJ5lzu2JmyM7sys=; b=EJmBzeoF6WljxLtibB2vg6mUJ5367Dbrfshbfcb+QfV+H3HXIl9dN9ETt5W2CrUzLF cbh2xc0BhcUIjbfATCY4wjoI/sSVSo5JamuUtIcCJCS3dsx9mhD2EprcaFYDg8QJyGeR ioIsJ4tWvrR/Ca/hr1Xc2/WEEZrZztuiOad3NJ53Uz+XAqQcbvdS46FuvI0aal9gi+8E gsQk5s1sITYSPpYXexdljOXrVAxnDDiXrW1LpQ/1BHcxPgYNrYy3Zn/t+e39hYWQyLF6 gmaEBzEANlexWVVho3dlpBMEKx9rA8cosGb7gR/Bwx80n6g0jNy2RklnsM7u+biIPCBM 8L8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=phAgXv7G; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a170906578500b0078a19032c70si14635178ejq.334.2022.10.20.00.28.43; Thu, 20 Oct 2022 00:29:08 -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=@mediatek.com header.s=dk header.b=phAgXv7G; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbiJTHS5 (ORCPT + 99 others); Thu, 20 Oct 2022 03:18:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbiJTHSd (ORCPT ); Thu, 20 Oct 2022 03:18:33 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0293316E28A; Thu, 20 Oct 2022 00:18:16 -0700 (PDT) X-UUID: 290b9489e2ba47dfab88a0062c69811b-20221020 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=Nu8CkHwHdOQOx7g9RjxSew+cd3IBxJ5lzu2JmyM7sys=; b=phAgXv7GnpmYWnKoLipNW/je0X4bJyaPQwZz5czIkl0T2j8AUHsWDFIAEFpLHRZwlcFUV5eeSteYAIXojKe1lPaH6Hi5h9FFlu2OQO2GGxYtWSAt6Jvweqzj77Uu1QD8feFrWVPnY0JSnQLIWm8MaqI8G+isKPBypnDrthoVOCI=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.12,REQID:7fc3df9a-5f23-4374-9dc4-9874d07179d6,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:62cd327,CLOUDID:f7cd64a3-73e4-48dd-a911-57b5d5484f14,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 290b9489e2ba47dfab88a0062c69811b-20221020 Received: from mtkmbs11n1.mediatek.inc [(172.21.101.185)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 949885667; Thu, 20 Oct 2022 15:18:03 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Thu, 20 Oct 2022 15:18:02 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Thu, 20 Oct 2022 15:18:02 +0800 From: Moudy Ho To: Mauro Carvalho Chehab , Matthias Brugger , Hans Verkuil CC: Chun-Kuang Hu , , , , , Moudy Ho Subject: [PATCH v3 2/3] media: platform: mtk-mdp3: fix error handling about components clock_on Date: Thu, 20 Oct 2022 15:17:59 +0800 Message-ID: <20221020071800.20487-3-moudy.ho@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20221020071800.20487-1-moudy.ho@mediatek.com> References: <20221020071800.20487-1-moudy.ho@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY,URIBL_BLOCKED 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 Add goto statement in mdp_comp_clock_on() to avoid error code not being propagated or returning positive values. This change also performs a well-timed clock_off when an error occurs, and reduces unnecessary error logging in mdp_cmdq_send(). Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver") Signed-off-by: Moudy Ho Reviewed-by: AngeloGioacchino Del Regno --- .../platform/mediatek/mdp3/mtk-mdp3-cmdq.c | 4 +--- .../platform/mediatek/mdp3/mtk-mdp3-comp.c | 24 ++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c index e194dec8050a..124c1b96e96b 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-cmdq.c @@ -433,10 +433,8 @@ int mdp_cmdq_send(struct mdp_dev *mdp, struct mdp_cmdq_param *param) cmd->mdp_ctx = param->mdp_ctx; ret = mdp_comp_clocks_on(&mdp->pdev->dev, cmd->comps, cmd->num_comps); - if (ret) { - dev_err(dev, "comp %d failed to enable clock!\n", ret); + if (ret) goto err_free_path; - } dma_sync_single_for_device(mdp->cmdq_clt->chan->mbox->dev, cmd->pkt.pa_base, cmd->pkt.cmd_buf_size, diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c index d3eaf8884412..7bc05f42a23c 100644 --- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c +++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c @@ -699,12 +699,22 @@ 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; + goto err_revert; } } return 0; + +err_revert: + while (--i >= 0) { + if (IS_ERR_OR_NULL(comp->clks[i])) + continue; + clk_disable_unprepare(comp->clks[i]); + } + if (comp->comp_dev) + pm_runtime_put_sync(comp->comp_dev); + + return ret; } void mdp_comp_clock_off(struct device *dev, struct mdp_comp *comp) @@ -723,11 +733,13 @@ void mdp_comp_clock_off(struct device *dev, struct mdp_comp *comp) int mdp_comp_clocks_on(struct device *dev, struct mdp_comp *comps, int num) { - int i; + int i, ret; - for (i = 0; i < num; i++) - if (mdp_comp_clock_on(dev, &comps[i]) != 0) - return ++i; + for (i = 0; i < num; i++) { + ret = mdp_comp_clock_on(dev, &comps[i]); + if (ret) + return ret; + } return 0; } -- 2.18.0