Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5456816pxb; Wed, 26 Jan 2022 12:24:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJytzOJ79YDKkftGAjdKHOjmDmMkWOq15yflTg1lIqRe5fjc6pwFICGNrWwPLJ3AmtLzrXWM X-Received: by 2002:a63:34b:: with SMTP id 72mr408142pgd.50.1643228676824; Wed, 26 Jan 2022 12:24:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643228676; cv=none; d=google.com; s=arc-20160816; b=uAaO/9qpUwcXiHkHDk11IRSZ+Q48I3YgYrJ4z0nt8mgIisWWCxPdhTIUb3gyiwW/2e EaP4py4hDms1TMV96ICfrUOxwSzX5ocdejcdew0mN8QbykOq3SuWA45WJVAXEUeZeLiw vYW3LMXrwL2c4XYX+l2s9mcdWKy8oBXTceaHb0dmxz9ZNzWoZ0SBFTSoEyDdiaWko2Er M4ni2R8COP4m5oCsVBy6pH1L/klLbypkGsE45CxcS7MpOF/lFmnW1OE50jZdP8pm9Fw0 q7VXfSos5Wm4IzAwH9Vl8TTNaD/fjC3NyA2XU/vxFXvNfFF9mOGAPPisZaAXbrSh+0o1 c5Ug== 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; bh=ITf+GylFwCOIUExl9+x32aMdNg8hbM29sn45SrfkYzI=; b=NOnL0/8oGepg6qv6p62ch1vt6OLkHxb5b6q7uytLTsvFHSMvA/CbjkYO6RfsfU1nF2 vyQa8zpDHWeEhtBZ8TEbSbDGTQ+hCcHqNqb/mmW6DmWgGBWuPtIo849h+ji6kPc2UWYp GzYEoTy20cKWZdrCd42u58HkOrMO1GdoTGRJewjsk0WGsxEjuYMGGrUxqgmhX5MEyZ2g R7i/e9nlgOT2lDIDesSiOI57kxXW5dkq9uoe6OfrrDy/6/MHsTTr3YqJSp2yfVdvIW9n kO+a0kgPbMBAkZFRF7k4QMRjySPigSryjcaJqojXm/IimcSBDxAJzpUuPbHnqs4nS5wd V87g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a133si225050pfa.60.2022.01.26.12.24.24; Wed, 26 Jan 2022 12:24:36 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238005AbiAZHms (ORCPT + 99 others); Wed, 26 Jan 2022 02:42:48 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:52184 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S238104AbiAZHmq (ORCPT ); Wed, 26 Jan 2022 02:42:46 -0500 X-UUID: 03a15b6a7ae742919c2bd10d56a0946d-20220126 X-UUID: 03a15b6a7ae742919c2bd10d56a0946d-20220126 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 586552892; Wed, 26 Jan 2022 15:42:43 +0800 Received: from mtkexhb01.mediatek.inc (172.21.101.102) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 26 Jan 2022 15:42:42 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb01.mediatek.inc (172.21.101.102) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 26 Jan 2022 15:42:42 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 26 Jan 2022 15:42:42 +0800 From: Miles Chen To: CC: , , , , , , , Subject: Re: [PATCH 22/31] clk: mediatek: gate: Implement error handling in register API Date: Wed, 26 Jan 2022 15:42:42 +0800 Message-ID: <20220126074242.18291-1-miles.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20220122091731.283592-23-wenst@chromium.org> References: <20220122091731.283592-23-wenst@chromium.org> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 > --- > 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, > -- > 2.35.0.rc0.227.g00780c9af4-goog