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 06E56C433F5 for ; Sat, 22 Jan 2022 09:37:09 +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=nZMuVPMuqWBpoZ13Bbyv4wLEEdI0SIfPCKyip+8f7PA=; b=Ow+jUfY50jKJNy yDcieBDC3G+Y+BWP3NOrxrMyx+6Or9G8wtUK/PbqsGqsDjWbOUzpRUPvgOdnU34AJfyqbkRjrRW8T JSk0Ea5x6myGcTri1at1OdUatePuL5blg+LL41+dDAElbEiMYrMh6LJ0H0XwwpRr7z7QiWx6S9kCn U7qzSS/PFofvbPjwIYsZ6vNu1RlGJtW3Gdvi3Q2P1kOGmKHkwAbVsVvNqREu4TJ3vv9YevDjeZpAq ileCqwctq32WEeXNJ/txgBTYakncKVZtUhDIf6mX9KIoIMnyyV+hxptFFA44tOAOve3CBd1x/sdPg tfQT5PebqXXEHrI6c4Lw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nBCo2-00GyxX-LM; Sat, 22 Jan 2022 09:35:36 +0000 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nBCXn-00GrqD-0b for linux-arm-kernel@lists.infradead.org; Sat, 22 Jan 2022 09:18:48 +0000 Received: by mail-pj1-x1034.google.com with SMTP id l16so11324573pjl.4 for ; Sat, 22 Jan 2022 01:18:38 -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=8YPN+1zbb0FLmeCLY1r05U9fmN1fkUgWhlHUKwR4SnA=; b=X/ZtK2SpDBNbC3Na1TLbE7R39jEjlYu+bOu8u+DNEurHjH1tbv0qDNcyqaLBDYGA1Q 8VwLaJ/PNA2WR9RbNJ4eDR3BMD8BIyBuTAJ/WNHxn6wrfM3rexdndBFYfjpCNFiKNiqo E7c4AfXewebnkxmvND/e8oxCRJ21aYZY5EKFk= 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=8YPN+1zbb0FLmeCLY1r05U9fmN1fkUgWhlHUKwR4SnA=; b=LW7i5rrKmtxOqa7vHODbmiZUvQmHiMZQrIZyTyuA/sTqlV0rYDopcTyVdIURJIlmKy G2GNwwdTLAGhpWzIbiYg4als+83bkYNoC6wPu6EFN7d6PYRoIKlq9YeHFeG+OHf598Aq /GAfiNyBWk5iF4guOf8ALxOgSLfeAeplNuwjh6WFlfW7TgTt0EyJyHsewovd0fZ3Jwz9 e306fck2z34S4iqYfyKFusTDn5IZwcjRekwXE/BF3IKiVxLpjrKd41VoN8+Ra35beNEA Okyv2qyBCASBnjZmSJtvIb5dabFkHV0gH63XQvPin33MjFEQ0kq5Dhi5cGHS1nlPfhed gxOw== X-Gm-Message-State: AOAM5312DgJR0SFB2O2oOLoK0nS7xH1eC5iAHrJu075UW9FuKU5ANgYH r7gFUpNe5drRvna0R7XwuX/AoiMWgsruhA== X-Google-Smtp-Source: ABdhPJxXOmZFL9go3UdVwQDSJBJ6fg68hKE0lBH0fAd3eIgttYowB4HFeZeVzoGLMe1c7TNtJJKpJw== X-Received: by 2002:a17:902:6b02:b0:149:7c20:c15b with SMTP id o2-20020a1709026b0200b001497c20c15bmr7026790plk.173.1642843117953; Sat, 22 Jan 2022 01:18:37 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jan 2022 01:18:37 -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 24/31] clk: mediatek: mux: Implement error handling in register API Date: Sat, 22 Jan 2022 17:17:24 +0800 Message-Id: <20220122091731.283592-25-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_011847_091163_C9727A8A X-CRM114-Status: GOOD ( 13.79 ) 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 mux 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-mux.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/clk/mediatek/clk-mux.c b/drivers/clk/mediatek/clk-mux.c index 70aa42144632..f51e67650f03 100644 --- a/drivers/clk/mediatek/clk-mux.c +++ b/drivers/clk/mediatek/clk-mux.c @@ -215,13 +215,26 @@ int mtk_clk_register_muxes(const struct mtk_mux *muxes, 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_mux *mux = &muxes[i]; + + if (IS_ERR_OR_NULL(clk_data->clks[mux->id])) + continue; + + mtk_clk_unregister_mux(clk_data->clks[mux->id]); + clk_data->clks[mux->id] = ERR_PTR(-ENOENT); + } + + return PTR_ERR(clk); } EXPORT_SYMBOL_GPL(mtk_clk_register_muxes); -- 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