Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2042581rwd; Fri, 26 May 2023 00:22:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7n004trW8fbykhiIs2w/ZeFKiHouFmXczb96bE7+umOozWqcGzvstgtXCBdqWMKzmPEQ64 X-Received: by 2002:a05:6a00:9a2:b0:64b:e8:24ff with SMTP id u34-20020a056a0009a200b0064b00e824ffmr874978pfg.17.1685085766538; Fri, 26 May 2023 00:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685085766; cv=none; d=google.com; s=arc-20160816; b=0Fj+ZmOhnMs/EJTRzKkiRwUiPX7mSy8JbToVR2LmoOz9aXayCnk3od1yQ1R4NU38/c UBQ0vANKXoTUcSDdf/F9tjTeeo590if+kyUXNzlfTUTgGINSf37gKG1w73U0pM8SFs3R 0bDuoPyx/VNKXTnAKIH0XpzbZluboklbqLCNkGXW59VnHMDYwjXv/bi5sNNNgmaGpnNt a0fIWFdAO/raFg4RHeJgk1J/D7HlT4VHZWRnNsBvq44M/jZCJIj+Fc19gn9gKLFROege JJghU7iTvz+juOAEb4IOEgfjzomH7OGJockS41Tty66EzyorGTEp2xsbfV3S18gH8MKN pUfw== 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; bh=qpgIlMR1giFDJI0QRCY10iByiSKCXRjZJ3e/PIrtWxg=; b=LQAAVPEDgpoX5beVjQ2GHWtlvW9AAzSJjMQ0YHME9h6lrbfUZkGC5xkg7qPP0bpt3q p7w6HyvZs13j1iIv/kxVQUwWjnCXoxE7fTZl4r76+/2TyWl0t4cdYY7055BEBI0f1qBe 3545BrwFyHYsK5lTYzIQTvgd50n6qeZ/Xom6vZrDHyh+MGcE7kmFlYw8j8pUp86Tslpq ywktE0Z/oludvMBgpS7UtIDbblJIv3V/Yx+4lD46LUrs7Gv3EhPw+5JhCiX/PEum9Id2 1nTPtk/Uk4J4/Bkv5JCtjB2ymGDTnkA0KJ4RES6kgFQ96A5zcZtUp4q9FdlMCRCIK7q8 faeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z135-20020a63338d000000b0052866b25be5si2895293pgz.746.2023.05.26.00.22.31; Fri, 26 May 2023 00:22:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236886AbjEZHHW (ORCPT + 99 others); Fri, 26 May 2023 03:07:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbjEZHHV (ORCPT ); Fri, 26 May 2023 03:07:21 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 372E8F7; Fri, 26 May 2023 00:07:19 -0700 (PDT) Received: from van1shing-pc.localdomain ([10.12.182.0]) (user=silver_code@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 34Q75tik000939-34Q75til000939 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 26 May 2023 15:05:57 +0800 From: Wang Zhang To: Peter Korsgaard , Andrew Lunn , Wolfram Sang , Andreas Larsson Cc: hust-os-kernel-patches@googlegroups.com, Wang Zhang , Peter Korsgaard , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] i2c: ocores: use devm_ managed clks Date: Fri, 26 May 2023 15:05:33 +0800 Message-Id: <20230526070534.76112-1-silver_code@hust.edu.cn> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: silver_code@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Smatch complains that: drivers/i2c/busses/i2c-ocores.c:704 ocores_i2c_probe() warn: missing unwind goto? If any wrong occurs in ocores_i2c_of_probe, the i2c->clk needs to be released. But the function returns directly without freeing the clock. Fix this by updating the code to use devm_clk_get_optional_enabled() instead. Use dev_err_probe() where appropriate as well since we are changing those statements. Fixes: f5f35a92e44a ("i2c: ocores: Add irq support for sparc") Signed-off-by: Wang Zhang --- v3->v4: use `dev_err_probe` to compact the code and add a fixes tag v2->v3: use `devm_clk_get_optional_enabled()` to manage clks v1->v2: change `ocores_i2c_of_probe` to use `devm_clk_get_enabled()` --- drivers/i2c/busses/i2c-ocores.c | 64 +++++++++++---------------------- 1 file changed, 21 insertions(+), 43 deletions(-) diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c index 2e575856c5cd..e30df2b78fdf 100644 --- a/drivers/i2c/busses/i2c-ocores.c +++ b/drivers/i2c/busses/i2c-ocores.c @@ -552,28 +552,20 @@ static int ocores_i2c_of_probe(struct platform_device *pdev, &clock_frequency); i2c->bus_clock_khz = 100; - i2c->clk = devm_clk_get(&pdev->dev, NULL); - - if (!IS_ERR(i2c->clk)) { - int ret = clk_prepare_enable(i2c->clk); - - if (ret) { - dev_err(&pdev->dev, - "clk_prepare_enable failed: %d\n", ret); - return ret; - } - i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000; - if (clock_frequency_present) - i2c->bus_clock_khz = clock_frequency / 1000; - } - + i2c->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL); + if (IS_ERR(i2c->clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(i2c->clk), + "devm_clk_get_optional_enabled failed\n"); + + i2c->ip_clock_khz = clk_get_rate(i2c->clk) / 1000; + if (clock_frequency_present) + i2c->bus_clock_khz = clock_frequency / 1000; if (i2c->ip_clock_khz == 0) { if (of_property_read_u32(np, "opencores,ip-clock-frequency", &val)) { if (!clock_frequency_present) { dev_err(&pdev->dev, "Missing required parameter 'opencores,ip-clock-frequency'\n"); - clk_disable_unprepare(i2c->clk); return -ENODEV; } i2c->ip_clock_khz = clock_frequency / 1000; @@ -678,8 +670,7 @@ static int ocores_i2c_probe(struct platform_device *pdev) default: dev_err(&pdev->dev, "Unsupported I/O width (%d)\n", i2c->reg_io_width); - ret = -EINVAL; - goto err_clk; + return -EINVAL; } } @@ -710,13 +701,13 @@ static int ocores_i2c_probe(struct platform_device *pdev) pdev->name, i2c); if (ret) { dev_err(&pdev->dev, "Cannot claim IRQ\n"); - goto err_clk; + return ret; } } ret = ocores_init(&pdev->dev, i2c); if (ret) - goto err_clk; + return ret; /* hook up driver to tree */ platform_set_drvdata(pdev, i2c); @@ -728,7 +719,7 @@ static int ocores_i2c_probe(struct platform_device *pdev) /* add i2c adapter to i2c tree */ ret = i2c_add_adapter(&i2c->adap); if (ret) - goto err_clk; + return ret; /* add in known devices to the bus */ if (pdata) { @@ -737,10 +728,6 @@ static int ocores_i2c_probe(struct platform_device *pdev) } return 0; - -err_clk: - clk_disable_unprepare(i2c->clk); - return ret; } static int ocores_i2c_remove(struct platform_device *pdev) @@ -755,9 +742,6 @@ static int ocores_i2c_remove(struct platform_device *pdev) /* remove adapter & data */ i2c_del_adapter(&i2c->adap); - if (!IS_ERR(i2c->clk)) - clk_disable_unprepare(i2c->clk); - return 0; } @@ -771,28 +755,22 @@ static int ocores_i2c_suspend(struct device *dev) ctrl &= ~(OCI2C_CTRL_EN | OCI2C_CTRL_IEN); oc_setreg(i2c, OCI2C_CONTROL, ctrl); - if (!IS_ERR(i2c->clk)) - clk_disable_unprepare(i2c->clk); + clk_disable_unprepare(i2c->clk); return 0; } static int ocores_i2c_resume(struct device *dev) { struct ocores_i2c *i2c = dev_get_drvdata(dev); + unsigned long rate; + int ret; - if (!IS_ERR(i2c->clk)) { - unsigned long rate; - int ret = clk_prepare_enable(i2c->clk); - - if (ret) { - dev_err(dev, - "clk_prepare_enable failed: %d\n", ret); - return ret; - } - rate = clk_get_rate(i2c->clk) / 1000; - if (rate) - i2c->ip_clock_khz = rate; - } + ret = clk_prepare_enable(i2c->clk); + if (ret) + return dev_err_probe(dev, ret, "clk_prepare_enable failed\n"); + rate = clk_get_rate(i2c->clk) / 1000; + if (rate) + i2c->ip_clock_khz = rate; return ocores_init(dev, i2c); } -- 2.34.1