Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2507696pxb; Sun, 23 Jan 2022 06:57:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJwm5RnbouAh/JmjG57QUdnRskdnHMkjL+o076FfUdgtrmA1qCNGqokYgDu1fCG1DJxF9seB X-Received: by 2002:a17:90a:f982:: with SMTP id cq2mr9186756pjb.36.1642949875424; Sun, 23 Jan 2022 06:57:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642949875; cv=none; d=google.com; s=arc-20160816; b=qnIwfPu+fUwpR1BoWIytjJWyhNFlV5vnFpzX45IcPvNxZdciMbtFA2NbuEHmsrPUD1 7WSFItZzxG3mPowfwVc2no+Oj8SDwfg0+urXGe7hlXsLkjpvywwL93+pKF2E+Q8Fv4Hk o14naaUXiKcop3Bz7uZv3K3g9vxuXcG1yvcN9LnJHOlodwDT0Z7sS61pOCnY+Z32dE36 HRN4Q4VszYImWLDX9yVSoVFBs9+iKqFDfrMgRpBp9ZW7UlJ7ySoMcktAPl9iNCG59T+J T3qc1ZEBKh2lFBpVhpyuIP9wfp7d7pvkPSmVO/UaN+Dub/cVtyedCWhUwHg6EZ7Wplky 3tyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WfZgCCKhWWL4g9b63+UJL7GvGCEBOJx3TOX6o+D52NI=; b=EKbO1mI6MFx80IQQ1Qfj311CjtZlaVHXBfnIgFy539PUG8N3UixYOFgvIru+r1wt9l eqcnM1pBV/X2kdJRt4sZs+2eInvoq9eLBiqfu3GeV8gcsNkXyl3gZOznLn9HpEyifwt6 bdS+p7VoR+Ax61n8qNU9abRkM/ctBL+s75Bd1CqxMH0HfFBuWZD165YMM/cgsbEOnkZr QNs0Nsr4CQkKBhfd8bgtczO4RZtI/acq7as2pAVAZg/60ZazGWgTo/gcIKIniolCmpRo alxRduDNxQKqi++CPR6JIvG5W65ZCQ+or65pCAzQhCiHXypzG+kB5doZXCRQM4cRYhnb ziAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BsAVCGC9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h5si11245847pgp.850.2022.01.23.06.57.44; Sun, 23 Jan 2022 06:57:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=BsAVCGC9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234180AbiAVJT4 (ORCPT + 99 others); Sat, 22 Jan 2022 04:19:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233358AbiAVJTL (ORCPT ); Sat, 22 Jan 2022 04:19:11 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5E09C06176D for ; Sat, 22 Jan 2022 01:18:31 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id h5so2664997pfv.13 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=gpePOa1PdoiEoiyLnRdlC2yzv9RqGoXrikjfOXgPitXu+W8G0WShxv21k5AoUHATpZ TmcbCQtiHpSGLb8GSzGHLKNsRCX04VnqydiHOKn+E54in3gC7o44ql3urNmlrf/f/yTp IJkIkNFFqeeB/4BoXvUJfBN8J1Y7yAsYAIwNAiXk7CgyFmojxokDv0/p9NZhPQu3zmOP Pn/I6Hqc9NFE2qI5zCDDt+C6q3yKNbxX4TbTQPrHtykH7A73wpuKHYwjXbchjXjgK1OO c/Ri55A+af1536Ryc9kBxsxe48koKPxzZQVA3d7xYDltjnBY4SBPd+cU6LFZLv+N3wYy xT9Q== X-Gm-Message-State: AOAM530Ldo7DLCPpFGq3TJgpOikMj1Va4+ozvg2dY+hrmZ7VQqzy6jVJ qYiGjno/70FjyzT1sWei+NuC0w== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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