Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3489315rwb; Fri, 30 Sep 2022 04:29:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM49DnUefxmYnKei9Wqj92gUgk0rc5Qwn6W6yXBGccIZyMqAj+4oNoFSOvi0jTOAq1pRygQv X-Received: by 2002:a17:906:58ce:b0:787:8744:8316 with SMTP id e14-20020a17090658ce00b0078787448316mr6144970ejs.267.1664537360959; Fri, 30 Sep 2022 04:29:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664537360; cv=none; d=google.com; s=arc-20160816; b=GN7bAneS4BTSLkxTVWQpnzphidFFxPSx7f0AGYZYfGXcw2IyjMrVT1O584BUnwUReC FtSz0GUX9XQecH3RlESw0KDXwFkg/Esmbdy9WJ/yTWvtiXmYsETKuNgrp5Vb5a3umiSW YeN0cyiVNEnU7cBFYrsAPltH3PN+zjDOFvauMhZcrvQUJs7SCmCw507JDx+qYxYeBNZ7 WRSaYjOD2MPAx0UIvcJ53sUhdjpD/NZ+MZh6Nw9oFctNWYsuVufHdfTGetXNR9aUKl+z f3H7/0lgZxHX3BMdcjTO0Xl+EVZtN528sCKe7Xb541YYGEd5/yQEjPpS0h2AkaVB69OJ gDhw== 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=VCeIfBYJvbHF9N/yTcdYAzolGLjNoSJfm/NyFwIg6fg=; b=YSeW2eDhuJpO0aSHP2wJTA64HEJPq61YUUyC5OeeUq8QyfzT9UosWY5UatXhJ3o2s+ LCMpo2WLBNI5w3XdEbokOkAWBsqR1AUT+IBXMNupxC6TnfRJPHmulkECxYhab34XcF+p V3geEfP3Wr2t89AbXZ4sRlGnAS8bvxbT+cQBIafGOBOlf1LFKB89YMNiM8pyCoto6lMT tUApM2/Wnwt7ZFJmegs9hnrWxMF8BLcW8BJ+R5zVgs6HlR+regA0/rFe4keUgR7Qhuhm GfkO1ICNTnAwOJEVY/05RJGpIG3480wAofyf8M/f6dHOR04d7Kby8ypEAW8eFMwOd/kC ZVWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=lpojIz3D; 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 s22-20020a50ab16000000b00457463e2dfbsi1501265edc.512.2022.09.30.04.28.53; Fri, 30 Sep 2022 04:29:20 -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=lpojIz3D; 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 S231924AbiI3LFi (ORCPT + 99 others); Fri, 30 Sep 2022 07:05:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231805AbiI3LFJ (ORCPT ); Fri, 30 Sep 2022 07:05:09 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6CC81A9A78; Fri, 30 Sep 2022 03:42:21 -0700 (PDT) X-UUID: 55ed115861054af7a5d0543c0e88b55e-20220930 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=VCeIfBYJvbHF9N/yTcdYAzolGLjNoSJfm/NyFwIg6fg=; b=lpojIz3Du4WTNvq97yMniY4UnZ8wf+AExImO969wL6oPz/dNWrrw3ywTjjmgAOVGMziuezAA0xxjudgsDjIySXsQgNvLyu1jarpVUaFuvDatRMbwUBoErn+k4/kAbA+i5OY5q+9I+IspaEcus+D4ADuJDPLyVwPmJAKMJ3nZkQA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11,REQID:57402be2-8e77-43c6-a3fd-1ec0d5790f8d,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:57402be2-8e77-43c6-a3fd-1ec0d5790f8d,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:2f4dc8e4-87f9-4bb0-97b6-34957dc0fbbe,B ulkID:2209301823115VTNFMG1,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48|823| 824,TC:nil,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:nil,QS:nil,BEC:nil, COL:0 X-UUID: 55ed115861054af7a5d0543c0e88b55e-20220930 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1753874022; Fri, 30 Sep 2022 18:23:09 +0800 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Fri, 30 Sep 2022 18:23:08 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 30 Sep 2022 18:23:07 +0800 From: Moudy Ho To: Mauro Carvalho Chehab , Matthias Brugger , Hans Verkuil CC: , , , , Moudy Ho Subject: [PATCH v1 2/2] media: platform: mtk-mdp3: fix error handling about components clock_on Date: Fri, 30 Sep 2022 18:23:06 +0800 Message-ID: <20220930102306.13201-3-moudy.ho@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220930102306.13201-1-moudy.ho@mediatek.com> References: <20220930102306.13201-1-moudy.ho@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.0 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_CSS 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 --- .../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..fe6a39315e88 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_unwind; } } return 0; + +err_unwind: + 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