Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2491555rwb; Mon, 3 Oct 2022 01:13:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7LrxCnUbyfDuY4zLjFPsjjV0tWMQQCBwKV+g5FKa/pDZTvA3s0/ZsNptaBpus9hiRrhnNa X-Received: by 2002:a05:6402:3485:b0:451:f615:321f with SMTP id v5-20020a056402348500b00451f615321fmr17914248edc.65.1664784798344; Mon, 03 Oct 2022 01:13:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664784798; cv=none; d=google.com; s=arc-20160816; b=Cs6F/Y+syavE/osqduo+xCjUIAjVw7GUuRVBKmcCmrpLKgAa2/Rtw54c6PplgQ3odd LtzjvJlnmQ+err2BGnV0jCo7Gqq+VX8wnUVr+oed9acpqGBJNcIjuS7ejTLoHvW5DJEc 73L49OMcw0ooBwlJHXi2bWd57XAYjf5jgahreR1r4/FEo0NQnpwPA4UtUUwfDpPwjguG +/zM1hT9X3xdvujFwBf+F5mfJTHTA6fBMC7wG3xVqaCET9LEyF1ES5Q5Mi14XAyAyHJo tMTK1/3v6mIGlnx/pWypwNrGQpNmaa7v+e0SZDIRJpfkJups7DANOoaObRbtyxfaDcEC FAVQ== 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=jvg4aCiyWw1VzxOrEJk07xqkVY906QHloJRYSRWJyrE=; b=ZBmB0iz0S4k9biX8XvWjs30Hq258ynesChynN/8oe9LGcqfx2Pkt2Vht6gSuSfbv5f qT/v4tc0jgZVUODGXXROV+5EIKtqJFxuRNPqBRIPPhEXSbZBAnbSX0Er9t1VtRd4lAAw yk3uSSjMKzMqbslUN3vo/+pb2T6WaJuLQq1dGVYX5g/xGQcILFltdaYsErxYfCgWmSjt NqHABMct9yKYZyVJwQiLBiDsj7uYHmKd6dK6krJ3RHZt6GlnWa2c2kIFRt0d6yZJe5wy WcO6tWJyRlbgEe4fpB053zhUQ2wT/yptPF9yuFa6xBBar3iZcUXWkxdBNa+3WK0i5UB6 AJMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=AnRuNSOo; 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 e22-20020a17090658d600b007813594dc31si6966027ejs.523.2022.10.03.01.12.52; Mon, 03 Oct 2022 01:13:18 -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=AnRuNSOo; 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 S229763AbiJCHIt (ORCPT + 99 others); Mon, 3 Oct 2022 03:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiJCHIo (ORCPT ); Mon, 3 Oct 2022 03:08:44 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 655B0357CB; Mon, 3 Oct 2022 00:08:39 -0700 (PDT) X-UUID: 8c8bfd03c1494ae68241001d4bdd836d-20221003 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=jvg4aCiyWw1VzxOrEJk07xqkVY906QHloJRYSRWJyrE=; b=AnRuNSOoetn++VTQ0jhhCz4pxnTN4o7T06yi1p/bSdPUJu2h7flGvwGVnWAh/n633k/k1F89yupCwJ0OJ22f3ZGVviHB44xysorZEMsRWYCbKejJ5kjSy1C1jevVnmkUr9rR/ZFjM2NRZatS1V6upqc2FEZtp2cHrG3HwDGRg4s=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:48db2a15-051b-42e7-92b8-2edeb3dda6b0,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:95 X-CID-INFO: VERSION:1.1.11,REQID:48db2a15-051b-42e7-92b8-2edeb3dda6b0,IP:0,URL :0,TC:0,Content:0,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTION :quarantine,TS:95 X-CID-META: VersionHash:39a5ff1,CLOUDID:f644fde4-87f9-4bb0-97b6-34957dc0fbbe,B ulkID:221003150834U8UHIKE9,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 8c8bfd03c1494ae68241001d4bdd836d-20221003 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 390451375; Mon, 03 Oct 2022 15:08:33 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Mon, 3 Oct 2022 15:08:32 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Mon, 3 Oct 2022 15:08:32 +0800 From: Moudy Ho To: Mauro Carvalho Chehab , Matthias Brugger , Hans Verkuil CC: Chun-Kuang Hu , , , , , Moudy Ho Subject: [PATCH v2 2/2] media: platform: mtk-mdp3: fix error handling about components clock_on Date: Mon, 3 Oct 2022 15:08:30 +0800 Message-ID: <20221003070830.23697-3-moudy.ho@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20221003070830.23697-1-moudy.ho@mediatek.com> References: <20221003070830.23697-1-moudy.ho@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,RDNS_NONE, SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY,URIBL_CSS autolearn=no 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 --- .../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