From: Maxime Ripard <mripard@kernel.org>
To: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
Maxime Ripard <mripard@kernel.org>,
Guenter Roeck <linux@roeck-us.net>,
kernel test robot <yujie.liu@intel.com>
Subject: [PATCH 2/2] clk: Introduce kunit wrapper around __clk_determine_rate
Date: Fri, 21 Jul 2023 09:09:33 +0200 [thread overview]
Message-ID: <20230721-clk-fix-kunit-lockdep-v1-2-32cdba4c8fc1@kernel.org> (raw)
In-Reply-To: <20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org>
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 <linux@roeck-us.net>
Link: https://lore.kernel.org/linux-clk/2b594e50-2bbf-4a2d-88e6-49fc39f3957a@roeck-us.net/
Reported-by: kernel test robot <yujie.liu@intel.com>
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 <mripard@kernel.org>
---
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;
--
2.41.0
next prev parent reply other threads:[~2023-07-21 7:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-21 7:09 [PATCH 0/2] clk: kunit: Fix the lockdep warnings Maxime Ripard
2023-07-21 7:09 ` [PATCH 1/2] clk: Introduce kunit wrapper around clk_hw_init_rate_request Maxime Ripard
2023-07-21 16:14 ` Guenter Roeck
2023-07-21 7:09 ` Maxime Ripard [this message]
2023-07-21 16:15 ` [PATCH 2/2] clk: Introduce kunit wrapper around __clk_determine_rate Guenter Roeck
2023-07-21 16:16 ` [PATCH 0/2] clk: kunit: Fix the lockdep warnings Guenter Roeck
2023-08-09 23:21 ` Stephen Boyd
2023-08-10 0:02 ` Guenter Roeck
2023-08-10 1:37 ` Stephen Boyd
2023-08-21 11:16 ` Maxime Ripard
2023-08-23 19:50 ` Stephen Boyd
2023-08-24 9:56 ` Maxime Ripard
2023-09-12 0:53 ` Stephen Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230721-clk-fix-kunit-lockdep-v1-2-32cdba4c8fc1@kernel.org \
--to=mripard@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mturquette@baylibre.com \
--cc=sboyd@kernel.org \
--cc=yujie.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®