From patchwork Fri Jul 21 07:09:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 123619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp29193vqg; Fri, 21 Jul 2023 00:28:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHh3+LQVuQfONDMcvhOf5IdF7CTn2WCZGQzbP2+95qZyilDOYKdiupjfol77+PpAJlKm+z X-Received: by 2002:aca:1214:0:b0:39e:8678:4035 with SMTP id 20-20020aca1214000000b0039e86784035mr1389137ois.13.1689924496245; Fri, 21 Jul 2023 00:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689924496; cv=none; d=google.com; s=arc-20160816; b=1LHGWdPflC6t6JV8T0Mx2+QpnmfKr8U3HGCdb0Gg5jZNAQrta1Lgnn1JiCSDb4z8ny m2tmJoaFOxUngtjK/ZLPY39Lqz4vKsFtjmqpawf//s+vSLO0SwufrGys9CcmO1AtxxPv 0nMbo8C8x8m7KlgcB6cBM/62a6iRLpOrYN8+m5+O9W0APOMwFV3FoYw+K/3Urv8QsymV fNYlkLe9Q3aJfAbmLR99Sx2J0KVoiy6suR8J69j3k1WV26Q790muNCuy9VPQc/P1iqhM vtKSLS6xvNOzqbrCcOgP9WcjaW1WhQQDyc+pSdn2ZzWzZit9Nhe/V/Nejkr4qzc3go4Z KuvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=mOTDJQK8p6s7YRE9WgLoXQ58HKvg3E0qR1hFXYa698Y=; fh=360HmAXND8A05iRBc7UoIp+5mY0SlJN6aKBr9AaO02M=; b=ktZWW9Mv+osuUMjvrduJrCdG9xo9ciVqPdS30yUu8VF64s82V+8Nce0X++tI9Uu0eB qFXzS5YL7MCqZjoWko22xt+zkL9msx0WLXhvO+h6YSEgp6yA/+Wil6Szc/mpsC5S8gqR 5WlIi8rkSwS0O3ifqDipcQeiTpXkUgiP6wF8vTW6cP2h02Zu+YqxQfeUyaXrwotgassJ doUqgS4XPOC7k/g5E6w8qHjf8jb5EEJd+vjwbDG/FlJ7W6HIiQSSB6lll84FLvDI5ENr e3ot8D+mUGjc5v0pUzvD/CBJuKag2SWs4v4/B9WrG2hri2TgKrt4OW9vP/gYyEf7Jjw1 xcsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QCz4J47z; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt8-20020a632908000000b0055387ef9633si2354798pgb.804.2023.07.21.00.28.03; Fri, 21 Jul 2023 00:28:16 -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=@kernel.org header.s=k20201202 header.b=QCz4J47z; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230104AbjGUHJv (ORCPT + 99 others); Fri, 21 Jul 2023 03:09:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbjGUHJk (ORCPT ); Fri, 21 Jul 2023 03:09:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6257D273E; Fri, 21 Jul 2023 00:09:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E5BB261416; Fri, 21 Jul 2023 07:09:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA145C433CA; Fri, 21 Jul 2023 07:09:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689923378; bh=MY8zoSsf9fgRkDcy3MJpnTeax5YDOFKq4s0E/rUA/rE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=QCz4J47ztfPLM+FQOIBqYlXwzBrf8lVvgOXQs8+oRZor1xHKr/BZXOze6pUVPQS4E Udm99VWZyU8iIYwg9ip5koylLFCXWKi7dTusE58hOuOXsccSAyYdPFng9GDdYcLqXK 6dpRD1zvipmV9paBFQS0kEsnYUaDVbOXrqezqa407/3PzGY1sPIIKg/vBLDSzL8OMU IKr+hG0PvIR24pX30uh+iPIr1B2lT45H1Mg8v7NjHYNX4L0A7tJ+2F2MTwQR2e9Tzv Dt0kK1G8VxM19aeJafN5k7RiDOiuj9XEovkOEXWOLdF+vUmQpblZMbRMz3gcxtBA85 8bg/PNwOVDyVA== From: Maxime Ripard Date: Fri, 21 Jul 2023 09:09:32 +0200 Subject: [PATCH 1/2] clk: Introduce kunit wrapper around clk_hw_init_rate_request MIME-Version: 1.0 Message-Id: <20230721-clk-fix-kunit-lockdep-v1-1-32cdba4c8fc1@kernel.org> References: <20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org> In-Reply-To: <20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org> To: Michael Turquette , Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Maxime Ripard , Guenter Roeck , kernel test robot X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3879; i=mripard@kernel.org; h=from:subject:message-id; bh=MY8zoSsf9fgRkDcy3MJpnTeax5YDOFKq4s0E/rUA/rE=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCm79HW2OW2yclFfd3DdyTpX94aposc1xc5XpVi8lBBd2 3vc89uUjlIWBjEuBlkxRZYYYfMlcadmve5k45sHM4eVCWQIAxenAEzkXQcjw4tV517GiWVOnvC7 6XCb8NHrta7rbx35M7F5LU9hdVFR7xKG/x6yuttlIhkalnwKjyux35p69rlqY2u0+eFJHG9Xyk+ NZQEA X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772014268661291477 X-GMAIL-MSGID: 1772014268661291477 Some kunit tests are meant to test the behaviour of providers (and most notably __clk_determine_rate()), but don't run those functions with the clk prepare_lock held which results in lockdep warning. clk_hw_init_rate_request is one of the functions being executed from a test which should have the lock held. Let's introduce a wrapper around it meant to be used only by kunit tests. Reported-by: Guenter Roeck Link: https://lore.kernel.org/linux-clk/2b594e50-2bbf-4a2d-88e6-49fc39f3957a@roeck-us.net/ Reported-by: kernel test robot Link: https://lore.kernel.org/oe-lkp/202301310919.b9d56ee3-yujie.liu@intel.com Fixes: 262ca38f4b6e ("clk: Stop forwarding clk_rate_requests to the parent") Signed-off-by: Maxime Ripard Tested-by: Guenter Roeck --- drivers/clk/clk.c | 26 ++++++++++++++++++++++++++ drivers/clk/clk_test.c | 2 +- include/linux/clk-provider.h | 11 +++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c249f9791ae8..8ee9bd02af76 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -6,6 +6,7 @@ * Standard functionality for the common clock API. See Documentation/driver-api/clk.rst */ +#include #include #include #include @@ -1556,6 +1557,31 @@ void clk_hw_init_rate_request(const struct clk_hw *hw, } EXPORT_SYMBOL_GPL(clk_hw_init_rate_request); +#if IS_ENABLED(CONFIG_KUNIT) +/** + * clk_kunit_init_rate_request - Initializes a clk_rate_request + * @hw: the clk for which we want to submit a rate request + * @req: the clk_rate_request structure we want to initialise + * @rate: the rate which is to be requested + * + * Initializes a clk_rate_request structure to submit to + * __clk_determine_rate() or similar functions. Only usable in kunit + * test contexts, use clk_hw_init_rate_request() otherwise. + */ +void clk_kunit_init_rate_request(const struct clk_hw *hw, + struct clk_rate_request *req, + unsigned long rate) +{ + if (!kunit_get_current_test()) + return; + + clk_prepare_lock(); + clk_hw_init_rate_request(hw, req, rate); + clk_prepare_unlock(); +} +EXPORT_SYMBOL_GPL(clk_kunit_init_rate_request); +#endif + /** * clk_hw_forward_rate_request - Forwards a clk_rate_request to a clock's parent * @hw: the original clock that got the rate request diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index a154ec9d0111..a64f7036baa3 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -2230,7 +2230,7 @@ static void clk_leaf_mux_set_rate_parent_determine_rate(struct kunit *test) rate = clk_get_rate(clk); KUNIT_ASSERT_EQ(test, rate, DUMMY_CLOCK_RATE_1); - clk_hw_init_rate_request(hw, &req, DUMMY_CLOCK_RATE_2); + clk_kunit_init_rate_request(hw, &req, DUMMY_CLOCK_RATE_2); ret = __clk_determine_rate(hw, &req); KUNIT_ASSERT_EQ(test, ret, 0); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 0f0cd01906b4..efdebfa3fce9 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -67,6 +67,17 @@ struct clk_rate_request { void clk_hw_init_rate_request(const struct clk_hw *hw, struct clk_rate_request *req, unsigned long rate); +#if IS_ENABLED(CONFIG_KUNIT) +void clk_kunit_init_rate_request(const struct clk_hw *hw, + struct clk_rate_request *req, + unsigned long rate); +#else +static inline void clk_kunit_init_rate_request(const struct clk_hw *hw, + struct clk_rate_request *req, + unsigned long rate) +{ +} +#endif void clk_hw_forward_rate_request(const struct clk_hw *core, const struct clk_rate_request *old_req, const struct clk_hw *parent, From patchwork Fri Jul 21 07:09:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 123639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp39480vqg; Fri, 21 Jul 2023 00:56:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlFWUBdpAS68/2mlD47uKb5wGGKNp39OP6KYg+TWbZ8oscRTweji3oAKhfuL/V7jQncvq1Xi X-Received: by 2002:a17:906:d7:b0:99b:64d0:f6c8 with SMTP id 23-20020a17090600d700b0099b64d0f6c8mr1201707eji.50.1689926196290; Fri, 21 Jul 2023 00:56:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689926196; cv=none; d=google.com; s=arc-20160816; b=s41czjT02+ctsue0hFlyAma2L0jQRDqerEY7ECs0f2XCb0KaKrQN6Ni/NFFqwQ+PRp LdyxsFMQ0Cm74Kl1RRPHV6n7i74lzbKbR3q5g4SdWAHZe0FlkutIGCrL+Me84mVCmSU4 COsJQVFq13FhY9Gsd3Qk7d/7OUk1rDnDj4HP0MQWeOWbdHl3B4iE0o4QQbaBHEl8D5mI usERKxeSIOiuWV6MIrwhP6VzDkfpUj1Nhj6XSNmqeEu1Q7IIHlhzVrhPKexH0qRK6rYg RYs7Q7Nu2uIKEPSLtAPSklbOGYxPU5ma0d9cC3OypcI67yAxPJGpqMXyUIuk8IPhP9kZ OUmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=/lmqo70Jgi2tPEVZR5CbsdtTkMKfzGKXPAjeTNQsDoM=; fh=360HmAXND8A05iRBc7UoIp+5mY0SlJN6aKBr9AaO02M=; b=cTSYwBka7K6WNRe6WK+V44Byhi8v1nbynYbjH2o8Z2SdBGQVf76YbdHKtiL9BU/f7k t+8x6RgdZzL04xvV1qa4UBsEMhWDt2v+xSF6PxsehbjS6MyHdr8PPVEMuG0ZiCDRL1zX likVXFrBdEXQbfOk+MJyMAods9LEZB1hyA7arhDPv6xxbZx+psiyJASUO0CeitNVR8xt ww/pIfUbm1qEZzHccL00QYt+DTAs0uOaFkBnl4UfP8cjAuEO57Cw7IrLoSsAew8KztWL OGGuvc0PwV56a+uMcc5pNBC9ub1aOEDAxie4yFAZSz7Q7Nki/afHnMKIlkiGlKoibolh eXyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OrSgLaC5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o20-20020a170906359400b0098e19ebc8fcsi1861690ejb.679.2023.07.21.00.56.11; Fri, 21 Jul 2023 00:56:36 -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=@kernel.org header.s=k20201202 header.b=OrSgLaC5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230040AbjGUHKA (ORCPT + 99 others); Fri, 21 Jul 2023 03:10:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230052AbjGUHJp (ORCPT ); Fri, 21 Jul 2023 03:09:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACD0A2D7E; Fri, 21 Jul 2023 00:09:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 30935613F9; Fri, 21 Jul 2023 07:09:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1870EC433C7; Fri, 21 Jul 2023 07:09:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689923381; bh=fsrYWcK7YUDwW5EUZ1gn9ZIMVIGkgbU1ULCwl39qicc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OrSgLaC56p8xHXAPqjWtxZzr/trelbbtbqUT9ykpv4alDW9ARvPFEChwjaUBbGT1S QTQFZ3a0/7Qlp5QyMT8vLcGaTGp11DdSxGufXkfIGN5jTyMWqNwZ9BpmrIcrnwmvfJ f0OBKLA6UKRdC4M+3/H8JRSPDAdOArE3Ny9K8c+TGaL5/MWAbh6/Fa6YhKw14BiE6x 7tFj4EEdCYIxpM+e44S5Dlxgb8bM6wRT2ZHt9bI/AM0cQANFKc4+dJ47LWF1rv3vu4 eZwnrPh8bwxfvbMeEviue0bCXxeWwvyfJiMBcr5h5DVmdJBNBR9+H/KDJLXv3HKmdv 9BPuOsHiq5rpA== From: Maxime Ripard Date: Fri, 21 Jul 2023 09:09:33 +0200 Subject: [PATCH 2/2] clk: Introduce kunit wrapper around __clk_determine_rate MIME-Version: 1.0 Message-Id: <20230721-clk-fix-kunit-lockdep-v1-2-32cdba4c8fc1@kernel.org> References: <20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org> In-Reply-To: <20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org> To: Michael Turquette , Stephen Boyd Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Maxime Ripard , Guenter Roeck , kernel test robot X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3338; i=mripard@kernel.org; h=from:subject:message-id; bh=fsrYWcK7YUDwW5EUZ1gn9ZIMVIGkgbU1ULCwl39qicc=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDCm79HWcZA2ZMsra5v4ouPWh9X3YAi5Wli77KqPXkVNP6 Ct+LPjUUcrCIMbFICumyBIjbL4k7tSs151sfPNg5rAygQxh4OIUgIlMjmL471Vt6ry6ePPS/4pK utyRuy89XSl9ZUHLP3+pa0tZI2x0uBgZNufOdvkkFcw02+96FI/Qn0ipI/pxcf+5cmuqlrDxNrR wAAA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772016051282661102 X-GMAIL-MSGID: 1772016051282661102 Some kunit tests are meant to test the behaviour of providers but don't run those functions with the clk prepare_lock held which results in lockdep warning. __clk_determine_rate is one of the functions being executed from a test which should have the lock held. Let's introduce a wrapper around it meant to be used only by kunit tests. Reported-by: Guenter Roeck Link: https://lore.kernel.org/linux-clk/2b594e50-2bbf-4a2d-88e6-49fc39f3957a@roeck-us.net/ Reported-by: kernel test robot Link: https://lore.kernel.org/oe-lkp/202301310919.b9d56ee3-yujie.liu@intel.com Fixes: 262ca38f4b6e ("clk: Stop forwarding clk_rate_requests to the parent") Signed-off-by: Maxime Ripard Tested-by: Guenter Roeck --- drivers/clk/clk.c | 25 +++++++++++++++++++++++++ drivers/clk/clk_test.c | 2 +- include/linux/clk-provider.h | 10 ++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 8ee9bd02af76..8fdbfec6bd85 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1669,6 +1669,31 @@ int __clk_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) } EXPORT_SYMBOL_GPL(__clk_determine_rate); +#if IS_ENABLED(CONFIG_KUNIT) +/** + * __clk_kunit_determine_rate - get the closest rate actually supported by a clock + * @hw: determine the rate of this clock + * @req: target rate request + * + * Useful for clk_ops such as .set_rate and .determine_rate. Only usable + * in a kunit test context. Use __clk_determine_rate() otherwise. + */ +int __clk_kunit_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) +{ + int ret; + + if (!kunit_get_current_test()) + return -EINVAL; + + clk_prepare_lock(); + ret = __clk_determine_rate(hw, req); + clk_prepare_unlock(); + + return ret; +} +EXPORT_SYMBOL_GPL(__clk_kunit_determine_rate); +#endif + /** * clk_hw_round_rate() - round the given rate for a hw clk * @hw: the hw clk for which we are rounding a rate diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index a64f7036baa3..b835e08892b4 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -2232,7 +2232,7 @@ static void clk_leaf_mux_set_rate_parent_determine_rate(struct kunit *test) clk_kunit_init_rate_request(hw, &req, DUMMY_CLOCK_RATE_2); - ret = __clk_determine_rate(hw, &req); + ret = __clk_kunit_determine_rate(hw, &req); KUNIT_ASSERT_EQ(test, ret, 0); KUNIT_EXPECT_EQ(test, req.rate, DUMMY_CLOCK_RATE_2); diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index efdebfa3fce9..43049f2c1dd2 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -1352,6 +1352,16 @@ void clk_hw_get_rate_range(struct clk_hw *hw, unsigned long *min_rate, void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate, unsigned long max_rate); +#if IS_ENABLED(CONFIG_KUNIT) +int __clk_kunit_determine_rate(struct clk_hw *hw, struct clk_rate_request *req); +#else +static inline int __clk_kunit_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + return -ENOENT; +} +#endif + static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src) { dst->clk = src->clk;