Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp4324248rwr; Sun, 30 Apr 2023 05:15:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4vOsQh9Ydt3B1JGenhksvejA0CSTJPTALMEUwY6ripx83XQoJMAVMxUBu5990ZJXRvfRvQ X-Received: by 2002:a17:90a:344:b0:240:cf04:c997 with SMTP id 4-20020a17090a034400b00240cf04c997mr9851326pjf.2.1682856901810; Sun, 30 Apr 2023 05:15:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682856901; cv=none; d=google.com; s=arc-20160816; b=a8Iw1PnQoNmstYbFoMlk7XLAvPW5p0X+5ZI8jPTfnDFnQwrFpDuRuyqmsKuHSTbBQi VBRTW265+Gj+zgYbFhuY/F7dai+7xdq6jvZpmpzCb62HD50jlueN8qJrRwLw+McUBs1I dSYnRfSPor7KktSXTmQwIMsn4JJrBHYJ6nRp3UCRhxQBRlVJtEHeAluqJsovri4jOHCx k1G96TaCed9LtTXPxJVK6qVnQ9sNffgiiBV34zd2RPv8oSS+zXGPDOsbgK93J1OC98NX QUCcHrz9uc7LaXWLGoHn68a7REmfSYNZcS33boclFnhkhNXoHiAyvvqxoCBypYg32dlX /24g== 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 :message-id:date:subject:cc:to:from; bh=vAr7p3Y81qS8REVxGrGYpdcJ8L4BIsiN7Z5hVTmJ3FQ=; b=nTVeSfeSKPZ21iONQ3hUf9Y/2oim/EFtohWXbrr6hM9oqoUUuc/nMLzKZTa7X1nPEq EDvAHUPsa2za2Bgv+LjOQXcpkXd4v3X4xYq6ar36n+NVzdjho7LrLrHlKeh7jrSrMQ8C JFZ+XdyWZG7l+vlwRIR1GhZw9eSsCD8KM4uupEYvBkEgygjKuB520DCbA+7Rvtljrx1x XHkrv2XJk6++i9lbBgGyedam76GhP379aXq43ID6ExZwsuo+wUXgCUWQxzs2FHcQl9rM xzTfMbjzC6ssYKb0jdFVfGOWLjANlYcFE0mGIVPWzkBYHLzV2XFb1ioWtdEDFb9lCabj 9ORw== 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 s35-20020a634523000000b0051b784e64casi25265647pga.171.2023.04.30.05.14.48; Sun, 30 Apr 2023 05:15:01 -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 S230013AbjD3L02 (ORCPT + 99 others); Sun, 30 Apr 2023 07:26:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjD3L01 (ORCPT ); Sun, 30 Apr 2023 07:26:27 -0400 Received: from hust.edu.cn (unknown [202.114.0.240]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A13626AD for ; Sun, 30 Apr 2023 04:26:24 -0700 (PDT) Received: from haru.localdomain ([10.12.176.125]) (user=m202071377@hust.edu.cn mech=LOGIN bits=0) by mx1.hust.edu.cn with ESMTP id 33UBNmPL023948-33UBNmPM023948 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sun, 30 Apr 2023 19:23:53 +0800 From: XuDong Liu To: Maxime Ripard , Chen-Yu Tsai , David Airlie , Daniel Vetter , Jernej Skrabec , Samuel Holland , Boris Brezillon , Paul Kocialkowski Cc: hust-os-kernel-patches@googlegroups.com, XuDong Liu , Dongliang Mu , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] drm: sun4i_tcon: use devm_clk_get_enabled in `sun4i_tcon_init_clocks` Date: Sun, 30 Apr 2023 19:23:46 +0800 Message-Id: <20230430112347.4689-1-m202071377@hust.edu.cn> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-FEAS-AUTH-USER: m202071377@hust.edu.cn X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 reports: drivers/gpu/drm/sun4i/sun4i_tcon.c:805 sun4i_tcon_init_clocks() warn: 'tcon->clk' from clk_prepare_enable() not released on lines: 792,801. In the function sun4i_tcon_init_clocks(), tcon->clk and tcon->sclk0 are not disabled in the error handling, which affects the release of these variable. Although sun4i_tcon_bind(), which calls sun4i_tcon_init_clocks(), use sun4i_tcon_free_clocks to disable the variables mentioned, but the error handling branch of sun4i_tcon_init_clocks() ignores the required disable process. To fix this issue, use the devm_clk_get_enabled to automatically balance enable and disabled calls. As original implementation use sun4i_tcon_free_clocks() to disable clk explicitly, we delete the related calls and error handling that are no longer needed. Fixes: 9026e0d122ac ("drm: Add Allwinner A10 Display Engine support") Fixes: b14e945bda8a ("drm/sun4i: tcon: Prepare and enable TCON channel 0 clock at init") Fixes: 8e9240472522 ("drm/sun4i: support TCONs without channel 1") Fixes: 34d698f6e349 ("drm/sun4i: Add has_channel_0 TCON quirk") Signed-off-by: XuDong Liu Reviewed-by: Dongliang Mu --- The issue is discovered by static analysis, and the patch is not tested yet. --- drivers/gpu/drm/sun4i/sun4i_tcon.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c index 523a6d787921..936796851ffd 100644 --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c @@ -778,21 +778,19 @@ static irqreturn_t sun4i_tcon_handler(int irq, void *private) static int sun4i_tcon_init_clocks(struct device *dev, struct sun4i_tcon *tcon) { - tcon->clk = devm_clk_get(dev, "ahb"); + tcon->clk = devm_clk_get_enabled(dev, "ahb"); if (IS_ERR(tcon->clk)) { dev_err(dev, "Couldn't get the TCON bus clock\n"); return PTR_ERR(tcon->clk); } - clk_prepare_enable(tcon->clk); if (tcon->quirks->has_channel_0) { - tcon->sclk0 = devm_clk_get(dev, "tcon-ch0"); + tcon->sclk0 = devm_clk_get_enabled(dev, "tcon-ch0"); if (IS_ERR(tcon->sclk0)) { dev_err(dev, "Couldn't get the TCON channel 0 clock\n"); return PTR_ERR(tcon->sclk0); } } - clk_prepare_enable(tcon->sclk0); if (tcon->quirks->has_channel_1) { tcon->sclk1 = devm_clk_get(dev, "tcon-ch1"); @@ -805,12 +803,6 @@ static int sun4i_tcon_init_clocks(struct device *dev, return 0; } -static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon) -{ - clk_disable_unprepare(tcon->sclk0); - clk_disable_unprepare(tcon->clk); -} - static int sun4i_tcon_init_irq(struct device *dev, struct sun4i_tcon *tcon) { @@ -1223,14 +1215,14 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, ret = sun4i_tcon_init_regmap(dev, tcon); if (ret) { dev_err(dev, "Couldn't init our TCON regmap\n"); - goto err_free_clocks; + goto err_assert_reset; } if (tcon->quirks->has_channel_0) { ret = sun4i_dclk_create(dev, tcon); if (ret) { dev_err(dev, "Couldn't create our TCON dot clock\n"); - goto err_free_clocks; + goto err_assert_reset; } } @@ -1293,8 +1285,6 @@ static int sun4i_tcon_bind(struct device *dev, struct device *master, err_free_dotclock: if (tcon->quirks->has_channel_0) sun4i_dclk_free(tcon); -err_free_clocks: - sun4i_tcon_free_clocks(tcon); err_assert_reset: reset_control_assert(tcon->lcd_rst); return ret; @@ -1308,7 +1298,6 @@ static void sun4i_tcon_unbind(struct device *dev, struct device *master, list_del(&tcon->list); if (tcon->quirks->has_channel_0) sun4i_dclk_free(tcon); - sun4i_tcon_free_clocks(tcon); } static const struct component_ops sun4i_tcon_ops = { -- 2.34.1