From mboxrd@z Thu Jan 1 00:00:00 1970 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 3411DC433F5 for ; Sat, 22 Jan 2022 09:34:44 +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=9/XDyfTwYlwd37CkaThV+DIibYKfk1zuI83hpEoeW20=; b=zEGTBRPHAHn1qg xrZUiUBB1RRr4KvUmKAdc+yA6Y9biH6IH5buA3136XJmb1w2oy+Bm6wUBL3ZVblpis3IRMtMHVxPj mb06Tc4E9wTXR9jNkwR5q6s+GWTnw6+7FucaHDXOvMdYq7OImLqcu5Y/92VTURNzN1lpPei1XWRyw oQLKLMna75AcYlyzoW7QW1B+kd2kcW8QMEf9GpHaPUWrvswTslFlz5RNNYHu5XI2FuDPt8p+U7Zou 8UpRuT6N16iETidod1H8O5LE1a9CX8o78VH8wwwN4oYJSudBO7AoXs+kWdA93GSoWTu3ZFjYNdEUu IB0b44wmwMA6HBeSkM+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nBCli-00Gxvf-BS; Sat, 22 Jan 2022 09:33:10 +0000 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nBCXX-00GrlZ-Ob for linux-arm-kernel@lists.infradead.org; Sat, 22 Jan 2022 09:18:33 +0000 Received: by mail-pf1-x429.google.com with SMTP id 128so11044151pfe.12 for ; Sat, 22 Jan 2022 01:18:31 -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=WfZgCCKhWWL4g9b63+UJL7GvGCEBOJx3TOX6o+D52NI=; b=BsAVCGC9C4UCU9w4e0beBa1T1K3NEh7vcM+upT9wdmY25oE2j+R+CPgkeTRHf5YF0U 2HLwzn10mw+DqT20c0YkpYAow643YIWjQZXE/tqB9DuFeaRY5JLeEKvdwGTpttT9fxD1 xl8Jem+89eo2oglIvf1Hx3HfDHQHmamvRvEmc= 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=WfZgCCKhWWL4g9b63+UJL7GvGCEBOJx3TOX6o+D52NI=; b=nwCONA9QwU+VdA1EFuIsIo//9yV88YVV8ikaPhd9hRVqvFEIQ9v09M++64M9qAoGA4 cV4zNApTEszCajwYfgQpvlis6ynOjg5t7oVRXfQZDvgQ7P7mxMDBH+JLfYwAi5sKsr7v 66dvGU1HMvF3r5vRCc2dp+B8Vm2YI5gxb8MZnpq3faD1kofkh1X/W+Kk75hzww1qWBF/ u9u8WRQQAva6T0b6HlDrfiHCGHgVmt0JWabEH8ZyWQ/Jp1V8vs0sTcVGbgGrBUDfb98C KI567+Zq693AgVf0YutlXa15aNuTsj7pyozh38WkZHXAUW38oqCUNpCLz2ho8trcroP0 S1FA== X-Gm-Message-State: AOAM5310ckDc3WmQhjc3Y+6RYDIHHHmojx4cwv+n5Eob+PlOTcuCSzis hXRGMPoL2zpS6uYeokEIFNuGRpzAgeSr7w== X-Google-Smtp-Source: ABdhPJx2VhgGVxkpCD6c4pBfWLcAfhPTpc4I2h8LOcFbzz4iFjf2yJpC7rnNN2p2KTBfDDh2j2J+Lw== X-Received: by 2002:a63:2b84:: with SMTP id r126mr5552900pgr.624.1642843111330; Sat, 22 Jan 2022 01:18:31 -0800 (PST) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:349f:9373:45d9:eb26]) by smtp.gmail.com with ESMTPSA id s1sm1608100pjn.42.2022.01.22.01.18.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jan 2022 01:18:30 -0800 (PST) From: Chen-Yu Tsai To: Stephen Boyd , Michael Turquette , Matthias Brugger Cc: Chen-Yu Tsai , Chun-Jie Chen , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 21/31] clk: mediatek: cpumux: Implement error handling in register API Date: Sat, 22 Jan 2022 17:17:21 +0800 Message-Id: <20220122091731.283592-22-wenst@chromium.org> X-Mailer: git-send-email 2.35.0.rc0.227.g00780c9af4-goog In-Reply-To: <20220122091731.283592-1-wenst@chromium.org> References: <20220122091731.283592-1-wenst@chromium.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220122_011831_850593_3CE1AEC0 X-CRM114-Status: GOOD ( 13.69 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The cpumux 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 --- drivers/clk/mediatek/clk-cpumux.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-cpumux.c b/drivers/clk/mediatek/clk-cpumux.c index 658aee789f44..499c60432280 100644 --- a/drivers/clk/mediatek/clk-cpumux.c +++ b/drivers/clk/mediatek/clk-cpumux.c @@ -123,13 +123,26 @@ int mtk_clk_register_cpumuxes(struct device_node *node, clk = mtk_clk_register_cpumux(mux, regmap); if (IS_ERR(clk)) { pr_err("Failed to register clk %s: %pe\n", mux->name, clk); - continue; + goto err; } clk_data->clks[mux->id] = clk; } return 0; + +err: + while (--i >= 0) { + const struct mtk_composite *mux = &clks[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) + continue; + + mtk_clk_unregister_cpumux(clk_data->clks[mux->id]); + clk_data->clks[mux->id] = ERR_PTR(-ENOENT); + } + + return PTR_ERR(clk); } void mtk_clk_unregister_cpumuxes(const struct mtk_composite *clks, int num, -- 2.35.0.rc0.227.g00780c9af4-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel