Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp903881rwd; Sun, 14 May 2023 08:33:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7VoboUhviN3vgKxeep4Rqn06Tgl+riS47VWjXcSMILEVxATV6CbZQvwlJ0nM/MrZ3eyMvj X-Received: by 2002:a17:90a:bc8d:b0:250:bc78:9828 with SMTP id x13-20020a17090abc8d00b00250bc789828mr18276885pjr.4.1684078417191; Sun, 14 May 2023 08:33:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684078417; cv=none; d=google.com; s=arc-20160816; b=GopjWUXtIvbrI+jpagzpy1OECF8x6/ZHAR9O+mASan1D1pBNWA41TvMDYDAxBC80iD H9QkZo1R9+dtKBHGh5T+A5x5Y8+7Q+fhTg1xhIwdAyiKK1KWFb220mYVeuNngXTL5bKZ wJkjN2LCEUBtDl3QD3ZyNYFiopy9/2QvYKiOfcMemx6+6WzSruNxTq2iOco0A+CoJRAe mDRhKQIEBYeeEk6i74bxTIf0Ar0taZTOpx7vo5+qXjh54rcnN+H0xaA3L1PdKvMXqy2V Jblhm15Len6Ln2388ut7PXPnZVPkdxqxQP0S1hh9dQDBjS6qX5Kivuy3nB2ZvFMiixsr svrA== 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:dkim-signature; bh=3UV8m4qvroWJvD9DLw5XhRNq9v27vjHdJQsxv5YLPos=; b=j8B+3rdYXf6hWgBw/3KCcYuEzyEyRLSz3uc4qQQH/9wx1Wuc9ej8m9oXauDT6kAarj u1wgf5NIybFVwQlr5RHC4CUy6csohxoGhV6Fl6yrXsghYEvYAbEuyuP1q1+b6dtyZE7c AfXnnSqb86D7HequxVFv86xpuDKZ6F+3qDxJFKqBy+UtjuOzvcd4cGszZvNbvkmWKnOI YG0Dv2kwIgb8j0FXx0nTuUXaGWv3++NrzqnAijbSOd+1KXAceJLIM/nEIcDRJGPALzGO kWfJldkfR/urDAsawBFSXQGBXuydDm7r3x2DkKSB0AFcXCSMeQ9E7dxjI3DgSRWitLxk hueQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Vogqn6Ai; 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 na3-20020a17090b4c0300b0024e1911ab42si34010634pjb.18.2023.05.14.08.33.22; Sun, 14 May 2023 08:33:37 -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; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b=Vogqn6Ai; 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 S229808AbjENPVt (ORCPT + 99 others); Sun, 14 May 2023 11:21:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjENPVr (ORCPT ); Sun, 14 May 2023 11:21:47 -0400 Received: from smtp.smtpout.orange.fr (smtp-14.smtpout.orange.fr [80.12.242.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A32931BF9 for ; Sun, 14 May 2023 08:21:46 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id yDXVp1l1EQj3myDXVpoD0z; Sun, 14 May 2023 17:21:43 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1684077703; bh=3UV8m4qvroWJvD9DLw5XhRNq9v27vjHdJQsxv5YLPos=; h=From:To:Cc:Subject:Date; b=Vogqn6AiRBujoyfjW9ehH9+U4nGrvVaXYQ5nteyOzkSvON3usz08mGUD3gBWsyUXn ZdqTgwBJiM63afau72MQnx5MN6O/kodUKFf2Q3yvWkkWlKzkRcFHfVZtuD7rTv7kQM c/jtVYQ0G5xq0u2yV/D+Yr4Yky5BbrNTzBSgoczCtFZ2u5DmjBzaSKE0cYVkiTb1J7 xhMWjFGfCG1jlFfrS6+4JZELJULIRfqMeNZTc1ZOYsPSqxW/3ryVMmCOmx9291FLqQ Q5GJjSKq2eEFKEddIJAMFjoC9x2lgxyuGJqrEq19Kr/ZmeJEZ4EUyvU1360GjTI8Nq dYBLL4BPCg9BQ== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 14 May 2023 17:21:43 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Vasily Khoruzhick , Yangtao Li , "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Philipp Zabel , Maxime Ripard , Ondrej Jirman Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Subject: [PATCH] thermal/drivers/sun8i: Fix some error handling paths in sun8i_ths_probe() Date: Sun, 14 May 2023 17:21:35 +0200 Message-Id: <26f9e3bb3fcd0c12ea24a44c75b7960da993b68b.1684077651.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 Should an error occur after calling sun8i_ths_resource_init() in the probe function, some resources need to be released, as already done in the .remove() function. Switch to the devm_clk_get_enabled() helper and add a new devm_action to turn sun8i_ths_resource_init() into a fully managed function. This fixes the issue and removes some LoC at the same time. Fixes: dccc5c3b6f30 ("thermal/drivers/sun8i: Add thermal driver for H6/H5/H3/A64/A83T/R40") Signed-off-by: Christophe JAILLET --- This changes the order of the release functions, but should be fine. --- drivers/thermal/sun8i_thermal.c | 43 +++++++++------------------------ 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index 793ddce72132..8f4c29bc85aa 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -319,6 +319,11 @@ static int sun8i_ths_calibrate(struct ths_device *tmdev) return ret; } +static void sun8i_ths_reset_control_assert(void *data) +{ + reset_control_assert(data); +} + static int sun8i_ths_resource_init(struct ths_device *tmdev) { struct device *dev = tmdev->dev; @@ -339,13 +344,13 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev) if (IS_ERR(tmdev->reset)) return PTR_ERR(tmdev->reset); - tmdev->bus_clk = devm_clk_get(&pdev->dev, "bus"); + tmdev->bus_clk = devm_clk_get_enabled(&pdev->dev, "bus"); if (IS_ERR(tmdev->bus_clk)) return PTR_ERR(tmdev->bus_clk); } if (tmdev->chip->has_mod_clk) { - tmdev->mod_clk = devm_clk_get(&pdev->dev, "mod"); + tmdev->mod_clk = devm_clk_get_enabled(&pdev->dev, "mod"); if (IS_ERR(tmdev->mod_clk)) return PTR_ERR(tmdev->mod_clk); } @@ -354,32 +359,20 @@ static int sun8i_ths_resource_init(struct ths_device *tmdev) if (ret) return ret; - ret = clk_prepare_enable(tmdev->bus_clk); + ret = devm_add_action_or_reset(dev, sun8i_ths_reset_control_assert, + tmdev->reset); if (ret) - goto assert_reset; + return ret; ret = clk_set_rate(tmdev->mod_clk, 24000000); if (ret) - goto bus_disable; - - ret = clk_prepare_enable(tmdev->mod_clk); - if (ret) - goto bus_disable; + return ret; ret = sun8i_ths_calibrate(tmdev); if (ret) - goto mod_disable; + return ret; return 0; - -mod_disable: - clk_disable_unprepare(tmdev->mod_clk); -bus_disable: - clk_disable_unprepare(tmdev->bus_clk); -assert_reset: - reset_control_assert(tmdev->reset); - - return ret; } static int sun8i_h3_thermal_init(struct ths_device *tmdev) @@ -530,17 +523,6 @@ static int sun8i_ths_probe(struct platform_device *pdev) return 0; } -static int sun8i_ths_remove(struct platform_device *pdev) -{ - struct ths_device *tmdev = platform_get_drvdata(pdev); - - clk_disable_unprepare(tmdev->mod_clk); - clk_disable_unprepare(tmdev->bus_clk); - reset_control_assert(tmdev->reset); - - return 0; -} - static const struct ths_thermal_chip sun8i_a83t_ths = { .sensor_num = 3, .scale = 705, @@ -642,7 +624,6 @@ MODULE_DEVICE_TABLE(of, of_ths_match); static struct platform_driver ths_driver = { .probe = sun8i_ths_probe, - .remove = sun8i_ths_remove, .driver = { .name = "sun8i-thermal", .of_match_table = of_ths_match, -- 2.34.1