From patchwork Wed Feb 2 13:48:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 12732989 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 27F4DC433F5 for ; Wed, 2 Feb 2022 14:08:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4yMyoo2yQzk001AyO3v9C0QXQrpTA39pSQ3VtE0L8P8=; b=jfLv+2pywWMxc5 zntP2RbydteLs9XEQxm0jPvF2NlBelLrUFvSotF1Q6JiDWlmylXThrEO2QTqJJmFv17CZvfkRL88a zK5oyLyxpOJcw00GGn3Y2J/lhUB3jdU/dzbrTx4qc0OZtjBAOXnTikSzlXyXWjJSgcZqozNKe3H5l pDYuMcg7HmBZyc22IM1H6gdTrb64vCRMhkyuJxCVpdbWoxi+sHmKdsreDgSPGtxDkqwUYQK4Qs/by RYQZvZe5qBJFQTWO+SQ+kFhkSdbS7okvUKK1jv4SWQ0m5Dqp5NibQ15dKSxxRQnGIF2O2mEM8j63r RzweAfgZQA/3qZ330hAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFGHb-00FXhc-2I; Wed, 02 Feb 2022 14:06:51 +0000 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nFG1f-00FPLy-58 for linux-arm-kernel@lists.infradead.org; Wed, 02 Feb 2022 13:50:24 +0000 Received: by mail-pg1-x52f.google.com with SMTP id 133so18388484pgb.0 for ; Wed, 02 Feb 2022 05:50:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UVzLtEErhGtWV1STn1xNEVEnPyyTfBz7V3UiBlfriHg=; b=XQ+2EGR/cYRsPyHfBXXF9d1J9msyxxFm800JBKViuiIz+3BmpFAaHWZHT90R5nj5x+ RaqgfY9Y0tqPoUWPg2ezdtqs+0Lh9Ps6Fnt4cv1CWcOg3OPidhT3t5iYomsoxjX1Z05a 5RVDJ7Jhed3DlnGH/zsGsgqiHzv4xNt29Wx44= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UVzLtEErhGtWV1STn1xNEVEnPyyTfBz7V3UiBlfriHg=; b=1H8hXLPG2Y5GkHUZiqM9qkRnhlBltkBuPA59aV+pqbJfMp7IpjAKOhdySvPOad1NK3 etXlqi4asd72Hq5MnsNSSOilHsVA1M9tx2rlrx0QwlHLq21weWnNhlo6eAo/rwsLrwE3 i1dXmYW0CirvwpvcHQZjt2FLBcdfGvcNBgGQw0cI8nlUCGaWxXcYO2yPyCWlGVZiZtX+ 8AEaAzxI3m3jdb7Wg+mBWCrXXrSCFrJZV860u9hVvP9fuo9cdzmYnNS1ESb2q62e1ksX DCb78BwefHF+kjgeqp2lnLFU2v4ooMzZqjd5s5AOCHJ+4EiZftKctWifEu7pfmCwgdji L/Xg== X-Gm-Message-State: AOAM5308iUlcyB/mSyCVYo85Bm4hO0d6GlNd+jZeAqScRPO1MJhuED0C 3KO319/+WgMGAswPc1ini6/ysw== X-Google-Smtp-Source: ABdhPJyE+pAn7gWEZTYj9bqNkprgRbIA8ZjA9M8QTJUnb3pEdI+FzNwtwWMFArF/buYt6wDUM7t07Q== X-Received: by 2002:a05:6a00:1652:: with SMTP id m18mr17396585pfc.56.1643809822645; Wed, 02 Feb 2022 05:50:22 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:78b5:214c:c81:b9aa]) by smtp.gmail.com with ESMTPSA id w19sm27335684pfu.47.2022.02.02.05.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Feb 2022 05:50:22 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , Miles Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 22/31] clk: mediatek: gate: Implement error handling in register API Date: Wed, 2 Feb 2022 21:48:25 +0800 Message-Id: <20220202134834.690675-23-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc2.247.g8bbb082509-goog In-Reply-To: <20220202134834.690675-1-wenst@chromium.org> References: <20220202134834.690675-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220202_055023_278043_F0410144 X-CRM114-Status: GOOD ( 14.98 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The gate clk type registration function does not stop or return errors if any clk failed to be registered, nor does it implement an error handling path. This may result in a partially working device if any step failed. Make the register function return proper error codes, and bail out if errors occur. Proper cleanup, i.e. unregister any clks that were successfully registered, is done in the new error path. Signed-off-by: Chen-Yu Tsai Reviewed-by: Miles Chen Reviewed-by: AngeloGioacchino Del Regno --- drivers/clk/mediatek/clk-gate.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-gate.c b/drivers/clk/mediatek/clk-gate.c index e8881ae1489a..631ff170b7b9 100644 --- a/drivers/clk/mediatek/clk-gate.c +++ b/drivers/clk/mediatek/clk-gate.c @@ -237,13 +237,26 @@ int mtk_clk_register_gates_with_dev(struct device_node *node, if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", gate->name, clk); - continue; + goto err; } clk_data->clks[gate->id] = clk; } return 0; + +err: + while (--i >= 0) { + const struct mtk_gate *gate = &clks[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[gate->id])) + continue; + + mtk_clk_unregister_gate(clk_data->clks[gate->id]); + clk_data->clks[gate->id] = ERR_PTR(-ENOENT); + } + + return PTR_ERR(clk); } int mtk_clk_register_gates(struct device_node *node,