From patchwork Tue Sep 12 17:55:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 138347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp584216vqx; Tue, 12 Sep 2023 11:01:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGPCSKDcMAxuZI1OnvbBCq4TdvqI3VoGACDAYG475rEPC1COs+URUvi/hrQhr7AL1cFSVsy X-Received: by 2002:a05:6a00:1396:b0:68b:a137:373d with SMTP id t22-20020a056a00139600b0068ba137373dmr454432pfg.17.1694541682380; Tue, 12 Sep 2023 11:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694541682; cv=none; d=google.com; s=arc-20160816; b=0i9gZImj7XX6cMSBiltxwAzxMEuVymSPZhLN5n8x58BBlw0OIUSAzf5hHp5Tsd1nWP M8BxwLfwynThOFN8jAfVj10Yuqv/7+cHTs763u1uSvB+4EKPX0HUmFgFQV9tzxnpgXjX U3RfDuQ+OLNthrfGThwErow/3Ax69wofDDPUsu1ktIOj7+TkyBl45aBI6BY3jBODsJO8 I0QU7f2YmhF5VqtEAJQNYrF4wSXM5S+Aky1DbGtS54gYmXiskPAxRW0uF1kyNpgk+UdZ CprpSOMdPZxWQZvi1CdOKBLW0GUJoWHSDpypanoU1wrIIJSXuU+zyItqucQeX+nOhHg8 uGIQ== 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 :dkim-signature; bh=UUH7uy3wuiLGAxvHvBk+PUlD7fC9kNXddVQ22bPc/8Y=; fh=H5lpYlBvhnQo0X1S08ar1R+O5zzVwpspWk1VrTdrykU=; b=CvcCqmLjGkL7sjDl+u/O1JhS3nrlBjW9E3rsGBdZZ8mexurq/VS96l6Z7XQFxRciuo AIgH9lUk/8m6u8Ss4ihDQLIdAku9GygRUJC8nbWnX3xQlyw3aQpDfd0jaa4D2rV9lBMR TylTisV3ZegvAMuVGSmnIRFSUJbusrlCms463JMpJ6pCo4KQR8bGIOV4HSBuvgocE0IK ApUAd+zQEBY0hR3ujClsFNnve20CYpwyhSbiJGi0DsQx3xsWXwTaPDiwKtssQ/NUwoUn m3TXZOScp84AQW1Vv5UkUMVx23HcbDk9mN63yvncmMHrien7vlixSGKyaAEa9oOBKzUp wl8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MBjMeUOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id cn10-20020a056a00340a00b0068a14066ae2si300366pfb.51.2023.09.12.11.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 11:01:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MBjMeUOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D095680697FD; Tue, 12 Sep 2023 10:55:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236934AbjILRzk (ORCPT + 36 others); Tue, 12 Sep 2023 13:55:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236851AbjILRzj (ORCPT ); Tue, 12 Sep 2023 13:55:39 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BE0BC1; Tue, 12 Sep 2023 10:55:36 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B6EDC433CB; Tue, 12 Sep 2023 17:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694541335; bh=FfnLct/wM1EZ4QoILWTk6w0kU9+rPQdHk0gX8shw8H0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MBjMeUOip/jXsDm9/9iiwSwy8/XXD5zbPdWpXFRofw8xoxJjpkluJpk7Lidv7e5x9 B5tw4JyfzIY3J8sEr8rA259DNMkvGGt+aShf12exuXjE3lbDj4uh0UXHDx73ARPCcB qRBoHO4J0hMDZS7icph61GpnRpTZoK1AAUhtJU3F94LTu4nyjlsHy6o1jvG/s7ySJj WwBkjV/p0o8k/SMihdVqNsGz7uvXiR+lUOpcOtqLXihgJGwK+u/rYw9PonHf4B6NP0 tLrTc9Eo4dOudHXIm3o8EtHSbsItkoXCq1dAW3RW89N4KK90+998aRKmqYn8G6TPzv T8qDNS19XokZw== From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, patches@lists.linux.dev, Guenter Roeck , kernel test robot , Maxime Ripard Subject: [PATCH 1/2] clk: Drive clk_leaf_mux_set_rate_parent test from clk_ops Date: Tue, 12 Sep 2023 10:55:30 -0700 Message-ID: <20230912175534.2427862-2-sboyd@kernel.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230912175534.2427862-1-sboyd@kernel.org> References: <20230912175534.2427862-1-sboyd@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 12 Sep 2023 10:55:48 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776855739172495254 X-GMAIL-MSGID: 1776855739172495254 Running this kunit test with lockdep enabled leads to warning splats about calling clk provider APIs without the clk_prepare lock held. I proposed adding a wrapper around these APIs to grab the prepare lock so we can call them from anywhere, and Maxime implemented that approach[1], but it didn't look great. That's because we had to make more kunit testing APIs just to call code from a place that isn't a clk provider when the prepare lock isn't held. Instead of doing that, let's implement a determine_rate clk_op for a new leaf clk that is the child of the existing leaf clk. We can call __clk_determine_rate() on the existing leaf clk from there, and stash away the clk_rate_request struct to check once the clk_op returns. Drive that clk_op by calling clk_round_rate() to keep things similar to how it was before (i.e. nothing actually changes rate, just the new rate is determined). This silences the warning by driving the test from a clk_op where we know the prepare lock is held. While looking at this in more detail, it was determined that the code we intended to test in commit 262ca38f4b6e ("clk: Stop forwarding clk_rate_requests to the parent") wasn't actually tested. The call to __clk_determine_rate() wasn't actually getting to the newly introduced code under the CLK_SET_RATE_PARENT if condition in clk_core_round_rate_nolock() because the parent clk (the mux) could round rates. We introduce a new leaf and make sure the parent of that clk has no clk_ops so that we can be certain that the CLK_SET_RATE_PARENT condition in clk_core_round_rate_nolock() is evaluated. Reported-by: Guenter Roeck Closes: https://lore.kernel.org/linux-clk/2b594e50-2bbf-4a2d-88e6-49fc39f3957a@roeck-us.net/ Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202301310919.b9d56ee3-yujie.liu@intel.com Cc: Maxime Ripard Link: https://lore.kernel.org/r/20230721-clk-fix-kunit-lockdep-v1-0-32cdba4c8fc1@kernel.org [1] Fixes: 262ca38f4b6e ("clk: Stop forwarding clk_rate_requests to the parent") Signed-off-by: Stephen Boyd --- drivers/clk/clk_test.c | 65 +++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index a154ec9d0111..43e85fc0b025 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -10,6 +10,8 @@ #include +static const struct clk_ops empty_clk_ops = { }; + #define DUMMY_CLOCK_INIT_RATE (42 * 1000 * 1000) #define DUMMY_CLOCK_RATE_1 (142 * 1000 * 1000) #define DUMMY_CLOCK_RATE_2 (242 * 1000 * 1000) @@ -2155,6 +2157,30 @@ static struct kunit_suite clk_range_minimize_test_suite = { struct clk_leaf_mux_ctx { struct clk_multiple_parent_ctx mux_ctx; struct clk_hw hw; + struct clk_hw parent; + struct clk_rate_request *req; +}; + +static int clk_leaf_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) +{ + struct clk_leaf_mux_ctx *ctx = container_of(hw, struct clk_leaf_mux_ctx, hw); + int ret; + struct clk_rate_request *parent_req = ctx->req; + + clk_hw_forward_rate_request(hw, req, req->best_parent_hw, parent_req, req->rate); + ret = __clk_determine_rate(req->best_parent_hw, parent_req); + if (ret) + return ret; + + req->rate = parent_req->rate; + + return 0; +} + +static const struct clk_ops clk_leaf_mux_set_rate_parent_ops = { + .determine_rate = clk_leaf_mux_determine_rate, + .set_parent = clk_dummy_single_set_parent, + .get_parent = clk_dummy_single_get_parent, }; static int @@ -2193,8 +2219,14 @@ clk_leaf_mux_set_rate_parent_test_init(struct kunit *test) if (ret) return ret; - ctx->hw.init = CLK_HW_INIT_HW("test-clock", &ctx->mux_ctx.hw, - &clk_dummy_single_parent_ops, + ctx->parent.init = CLK_HW_INIT_HW("test-parent", &ctx->mux_ctx.hw, + &empty_clk_ops, CLK_SET_RATE_PARENT); + ret = clk_hw_register(NULL, &ctx->parent); + if (ret) + return ret; + + ctx->hw.init = CLK_HW_INIT_HW("test-clock", &ctx->parent, + &clk_leaf_mux_set_rate_parent_ops, CLK_SET_RATE_PARENT); ret = clk_hw_register(NULL, &ctx->hw); if (ret) @@ -2208,32 +2240,31 @@ static void clk_leaf_mux_set_rate_parent_test_exit(struct kunit *test) struct clk_leaf_mux_ctx *ctx = test->priv; clk_hw_unregister(&ctx->hw); + clk_hw_unregister(&ctx->parent); clk_hw_unregister(&ctx->mux_ctx.hw); clk_hw_unregister(&ctx->mux_ctx.parents_ctx[0].hw); clk_hw_unregister(&ctx->mux_ctx.parents_ctx[1].hw); } /* - * Test that, for a clock that will forward any rate request to its - * parent, the rate request structure returned by __clk_determine_rate - * is sane and will be what we expect. + * Test that, for a clock that will forward any rate request to its parent, the + * rate request structure returned by __clk_determine_rate() is sane and + * doesn't have the clk_rate_request's best_parent_hw pointer point to the + * clk_hw passed into __clk_determine_rate(). See commit 262ca38f4b6e ("clk: + * Stop forwarding clk_rate_requests to the parent") for more background. */ -static void clk_leaf_mux_set_rate_parent_determine_rate(struct kunit *test) +static void clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent(struct kunit *test) { struct clk_leaf_mux_ctx *ctx = test->priv; struct clk_hw *hw = &ctx->hw; struct clk *clk = clk_hw_get_clk(hw, NULL); struct clk_rate_request req; unsigned long rate; - int ret; + ctx->req = &req; 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); - - ret = __clk_determine_rate(hw, &req); - KUNIT_ASSERT_EQ(test, ret, 0); + KUNIT_ASSERT_EQ(test, DUMMY_CLOCK_RATE_2, clk_round_rate(clk, DUMMY_CLOCK_RATE_2)); KUNIT_EXPECT_EQ(test, req.rate, DUMMY_CLOCK_RATE_2); KUNIT_EXPECT_EQ(test, req.best_parent_rate, DUMMY_CLOCK_RATE_2); @@ -2243,15 +2274,15 @@ static void clk_leaf_mux_set_rate_parent_determine_rate(struct kunit *test) } static struct kunit_case clk_leaf_mux_set_rate_parent_test_cases[] = { - KUNIT_CASE(clk_leaf_mux_set_rate_parent_determine_rate), + KUNIT_CASE(clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent), {} }; /* - * Test suite for a clock whose parent is a mux with multiple parents. - * The leaf clock has CLK_SET_RATE_PARENT, and will forward rate - * requests to the mux, which will then select which parent is the best - * fit for a given rate. + * Test suite for a clock whose parent is a pass-through clk whose parent is a + * mux with multiple parents. The leaf and pass-through clocks have the + * CLK_SET_RATE_PARENT flag, and will forward rate requests to the mux, which + * will then select which parent is the best fit for a given rate. * * These tests exercise the behaviour of muxes, and the proper selection * of parents. From patchwork Tue Sep 12 17:55:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 138344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp582896vqx; Tue, 12 Sep 2023 10:59:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHC3AJLpfIHqEsDCXMOAXDFRF9ApR959Q1DKju6ULlrIJVc6RbsGnU0CdY5+XX+JkS6XW/e X-Received: by 2002:a17:903:188:b0:1c3:21ae:7a4a with SMTP id z8-20020a170903018800b001c321ae7a4amr599816plg.38.1694541582981; Tue, 12 Sep 2023 10:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694541582; cv=none; d=google.com; s=arc-20160816; b=HqiAmkh+DRo+g9pWeRFUcc8wPstLTSbtuo3lCIJjylY+0drAESqaqpeONLPQtpVqGu sXfevdNG0gokavnxdDMmANxac7fFXKwimws4l3Hgww1hS0o4XLDFO4uS2nmh3Y1sYEzC bybu8rM+YhoftkhoUFoeS9W4JpGReBJTZ24wRPHCP6E3n7NrTiKCQDjrr7Ic1Klj0iPW 7ue/UZg+Zf8ZiinO+HJxAeS4T0xoTQu5rVNukWXDNLU5FAo/meD8YXT1DrW3A/48jr5S Hu3gm/DRDpJBgS6NUnWI7b8O3tN20J5Tmk1o3GTVcuAMGWBXE4e4Qvd0yI4nfYgUPbzZ eEnQ== 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 :dkim-signature; bh=wICgjCnrV6U4LumHZx8L8HTrMNcCINMp6EY9quaNYZM=; fh=ncZ9FZxYDSVz/grCh/WR+Eul+N2DK5wZHP60jyIas4A=; b=jEiPD/i5wxizoxNECP+0wcc0mq004Y8bW4EkmOTVmhZ3oDnoUy7NQ9jtuZbhiGmjmu H5SeVEC0qRQ057cMX/hgeN0hAxeUllG4vPhNh0SB7pMTppRAjXND88zFmmtfg3TjzFAT 7chcYJ8gEk5Hb3MlscePB4ZqiRtyn6lYxMqDXWlmf/enknUl5hdx7nPpvhP/WBIIyKyF ZC2AqqEQXPlZrWUfTsn5i52LR2XZTsM085tpBgY3aDypFSuG8OeoImbYPJZJwAi4Ghf+ I69zJgNYyTGod4jrVKhrmKum4PeBMXhqeY21WoXpJirjmskRJA2v224bjYgilenYpbI1 BqPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Er1pbDCr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id u8-20020a17090341c800b001bbfbe6bf3esi8450664ple.504.2023.09.12.10.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 10:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Er1pbDCr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D084B801B8B9; Tue, 12 Sep 2023 10:55:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237050AbjILRzm (ORCPT + 36 others); Tue, 12 Sep 2023 13:55:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236893AbjILRzk (ORCPT ); Tue, 12 Sep 2023 13:55:40 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85EEFC1; Tue, 12 Sep 2023 10:55:36 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC82FC433C9; Tue, 12 Sep 2023 17:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1694541336; bh=Ko4/UwcgT3eF+DcCLkqCyN0KFTjfLGv5nyGKHZQ9hcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Er1pbDCrPsgoljrMA7EZu4PaPiK4QM/q0W5JqbtXFV8FolVzjwN/rrjYK+mg/2dnZ LIo+HwBY3cQ8yBBeBDM57UPLKJ+nZBzmWGz1+NFeojsx9LKFJfxjoubXUPwHGG7jDs O0IAOqRu6N12saJD9lDjBrgUDFulU69nztdX2n2yr+dej312vxW9Dfe3GfcLlxgaz1 2MCg6w7STeRELdeErgKDnrD2bb7y32OHCi6EgAM1uc2YbOl4Qc9ZZCgT4nbnLB5WSa 6W7hnodZ3RrtE+GWm8+nLjFfmfmMVe4f4j/jc1idaoaI7WWqPj/dIPyIC2UM8YqsBo gQYDj7fPGq53Q== From: Stephen Boyd To: Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, patches@lists.linux.dev, Guenter Roeck , Maxime Ripard Subject: [PATCH 2/2] clk: Parameterize clk_leaf_mux_set_rate_parent Date: Tue, 12 Sep 2023 10:55:31 -0700 Message-ID: <20230912175534.2427862-3-sboyd@kernel.org> X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog In-Reply-To: <20230912175534.2427862-1-sboyd@kernel.org> References: <20230912175534.2427862-1-sboyd@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 10:55:56 -0700 (PDT) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776855635135632288 X-GMAIL-MSGID: 1776855635135632288 Transform the existing clk_leaf_mux_set_rate_parent test into a parameterized test that calls the various determine rate APIs that exist for clk providers. This ensures that whatever determine rate API is used by a clk provider will return the correct parent in the best_parent_hw pointer of the clk_rate_request because clk_rate_requests are forwarded properly. Cc: Guenter Roeck Cc: Maxime Ripard Signed-off-by: Stephen Boyd --- drivers/clk/clk_test.c | 81 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index 43e85fc0b025..39e2b5ff4f51 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -2159,6 +2159,7 @@ struct clk_leaf_mux_ctx { struct clk_hw hw; struct clk_hw parent; struct clk_rate_request *req; + int (*determine_rate_func)(struct clk_hw *hw, struct clk_rate_request *req); }; static int clk_leaf_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) @@ -2168,7 +2169,7 @@ static int clk_leaf_mux_determine_rate(struct clk_hw *hw, struct clk_rate_reques struct clk_rate_request *parent_req = ctx->req; clk_hw_forward_rate_request(hw, req, req->best_parent_hw, parent_req, req->rate); - ret = __clk_determine_rate(req->best_parent_hw, parent_req); + ret = ctx->determine_rate_func(req->best_parent_hw, parent_req); if (ret) return ret; @@ -2246,20 +2247,83 @@ static void clk_leaf_mux_set_rate_parent_test_exit(struct kunit *test) clk_hw_unregister(&ctx->mux_ctx.parents_ctx[1].hw); } +struct clk_leaf_mux_set_rate_parent_determine_rate_test_case { + const char *desc; + int (*determine_rate_func)(struct clk_hw *hw, struct clk_rate_request *req); +}; + +static void +clk_leaf_mux_set_rate_parent_determine_rate_test_case_to_desc( + const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case *t, char *desc) +{ + strcpy(desc, t->desc); +} + +static const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case +clk_leaf_mux_set_rate_parent_determine_rate_test_cases[] = { + { + /* + * Test that __clk_determine_rate() on the parent that can't + * change rate doesn't return a clk_rate_request structure with + * the best_parent_hw pointer pointing to the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent", + .determine_rate_func = __clk_determine_rate, + }, + { + /* + * Test that __clk_mux_determine_rate() on the parent that + * can't change rate doesn't return a clk_rate_request + * structure with the best_parent_hw pointer pointing to + * the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent__clk_mux_determine_rate_proper_parent", + .determine_rate_func = __clk_mux_determine_rate, + }, + { + /* + * Test that __clk_mux_determine_rate_closest() on the parent + * that can't change rate doesn't return a clk_rate_request + * structure with the best_parent_hw pointer pointing to + * the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent__clk_mux_determine_rate_closest_proper_parent", + .determine_rate_func = __clk_mux_determine_rate_closest, + }, + { + /* + * Test that clk_hw_determine_rate_no_reparent() on the parent + * that can't change rate doesn't return a clk_rate_request + * structure with the best_parent_hw pointer pointing to + * the parent. + */ + .desc = "clk_leaf_mux_set_rate_parent_clk_hw_determine_rate_no_reparent_proper_parent", + .determine_rate_func = clk_hw_determine_rate_no_reparent, + }, +}; + +KUNIT_ARRAY_PARAM(clk_leaf_mux_set_rate_parent_determine_rate_test, + clk_leaf_mux_set_rate_parent_determine_rate_test_cases, + clk_leaf_mux_set_rate_parent_determine_rate_test_case_to_desc) + /* - * Test that, for a clock that will forward any rate request to its parent, the - * rate request structure returned by __clk_determine_rate() is sane and - * doesn't have the clk_rate_request's best_parent_hw pointer point to the - * clk_hw passed into __clk_determine_rate(). See commit 262ca38f4b6e ("clk: - * Stop forwarding clk_rate_requests to the parent") for more background. + * Test that when a clk that can't change rate itself calls a function like + * __clk_determine_rate() on its parent it doesn't get back a clk_rate_request + * structure that has the best_parent_hw pointer point to the clk_hw passed + * into the determine rate function. See commit 262ca38f4b6e ("clk: Stop + * forwarding clk_rate_requests to the parent") for more background. */ -static void clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent(struct kunit *test) +static void clk_leaf_mux_set_rate_parent_determine_rate_test(struct kunit *test) { struct clk_leaf_mux_ctx *ctx = test->priv; struct clk_hw *hw = &ctx->hw; struct clk *clk = clk_hw_get_clk(hw, NULL); struct clk_rate_request req; unsigned long rate; + const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case *test_param; + + test_param = test->param_value; + ctx->determine_rate_func = test_param->determine_rate_func; ctx->req = &req; rate = clk_get_rate(clk); @@ -2274,7 +2338,8 @@ static void clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent(struc } static struct kunit_case clk_leaf_mux_set_rate_parent_test_cases[] = { - KUNIT_CASE(clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent), + KUNIT_CASE_PARAM(clk_leaf_mux_set_rate_parent_determine_rate_test, + clk_leaf_mux_set_rate_parent_determine_rate_test_gen_params), {} };