From patchwork Wed Apr 17 08:28:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?Q2h1bmZlbmcgWXVuICjkupHmmKXls7Ap?= X-Patchwork-Id: 10904925 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84EDC161F for ; Wed, 17 Apr 2019 08:29:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70D0828A57 for ; Wed, 17 Apr 2019 08:29:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6510828A77; Wed, 17 Apr 2019 08:29:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4376A28A57 for ; Wed, 17 Apr 2019 08:29:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731349AbfDQI2n (ORCPT ); Wed, 17 Apr 2019 04:28:43 -0400 Received: from mailgw02.mediatek.com ([1.203.163.81]:47506 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1731311AbfDQI2l (ORCPT ); Wed, 17 Apr 2019 04:28:41 -0400 X-UUID: dc898f7e83794882b3c0610678ae8681-20190417 X-UUID: dc898f7e83794882b3c0610678ae8681-20190417 Received: from mtkcas35.mediatek.inc [(172.27.4.253)] by mailgw02.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 500815480; Wed, 17 Apr 2019 16:28:29 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by MTKMBS31DR.mediatek.inc (172.27.6.102) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 17 Apr 2019 16:28:27 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 17 Apr 2019 16:28:26 +0800 From: Chunfeng Yun To: Greg Kroah-Hartman CC: Mathias Nyman , Matthias Brugger , Chunfeng Yun , Marek Szyprowski , , , , , Dongjin Kim Subject: [PATCH v3 3/6] usb: misc: usb3503: get optional clock by devm_clk_get_optional() Date: Wed, 17 Apr 2019 16:28:18 +0800 Message-ID: <7c1d28cb44102d96b224157f93f856ef84950a97.1555488276.git.chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-MTK: N Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the driver tries to get optional clock, it ignores all errors except -EPROBE_DEFER, but if only ignores -ENOENT, it will cover some real errors, such as -ENOMEM, so use devm_clk_get_optional() to get optional clock. And remove unnecessary stack variable clk. Cc: Dongjin Kim Signed-off-by: Chunfeng Yun --- v3: modify changelog comment v2: no changes --- drivers/usb/misc/usb3503.c | 48 ++++++++++++++------------------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/drivers/usb/misc/usb3503.c b/drivers/usb/misc/usb3503.c index d5141aa79dd4..72f39a9751b5 100644 --- a/drivers/usb/misc/usb3503.c +++ b/drivers/usb/misc/usb3503.c @@ -172,7 +172,6 @@ static int usb3503_probe(struct usb3503 *hub) hub->gpio_reset = pdata->gpio_reset; hub->mode = pdata->initial_mode; } else if (np) { - struct clk *clk; u32 rate = 0; hub->port_off_mask = 0; @@ -198,34 +197,29 @@ static int usb3503_probe(struct usb3503 *hub) } } - clk = devm_clk_get(dev, "refclk"); - if (IS_ERR(clk) && PTR_ERR(clk) != -ENOENT) { + hub->clk = devm_clk_get_optional(dev, "refclk"); + if (IS_ERR(hub->clk)) { dev_err(dev, "unable to request refclk (%ld)\n", - PTR_ERR(clk)); - return PTR_ERR(clk); + PTR_ERR(hub->clk)); + return PTR_ERR(hub->clk); } - if (!IS_ERR(clk)) { - hub->clk = clk; - - if (rate != 0) { - err = clk_set_rate(hub->clk, rate); - if (err) { - dev_err(dev, - "unable to set reference clock rate to %d\n", - (int) rate); - return err; - } - } - - err = clk_prepare_enable(hub->clk); + if (rate != 0) { + err = clk_set_rate(hub->clk, rate); if (err) { dev_err(dev, - "unable to enable reference clock\n"); + "unable to set reference clock rate to %d\n", + (int)rate); return err; } } + err = clk_prepare_enable(hub->clk); + if (err) { + dev_err(dev, "unable to enable reference clock\n"); + return err; + } + property = of_get_property(np, "disabled-ports", &len); if (property && (len / sizeof(u32)) > 0) { int i; @@ -324,8 +318,7 @@ static int usb3503_i2c_remove(struct i2c_client *i2c) struct usb3503 *hub; hub = i2c_get_clientdata(i2c); - if (hub->clk) - clk_disable_unprepare(hub->clk); + clk_disable_unprepare(hub->clk); return 0; } @@ -348,8 +341,7 @@ static int usb3503_platform_remove(struct platform_device *pdev) struct usb3503 *hub; hub = platform_get_drvdata(pdev); - if (hub->clk) - clk_disable_unprepare(hub->clk); + clk_disable_unprepare(hub->clk); return 0; } @@ -358,18 +350,14 @@ static int usb3503_platform_remove(struct platform_device *pdev) static int usb3503_suspend(struct usb3503 *hub) { usb3503_switch_mode(hub, USB3503_MODE_STANDBY); - - if (hub->clk) - clk_disable_unprepare(hub->clk); + clk_disable_unprepare(hub->clk); return 0; } static int usb3503_resume(struct usb3503 *hub) { - if (hub->clk) - clk_prepare_enable(hub->clk); - + clk_prepare_enable(hub->clk); usb3503_switch_mode(hub, hub->mode); return 0;