Skip to content

Commit 7535782

Browse files
committed
clk: Fix clk gate kunit test on big-endian CPUs
The clk gate kunit test checks that the implementation of the basic clk gate reads and writes the proper bits in an MMIO register. The implementation of the basic clk gate type uses writel() and readl() which operate on little-endian registers. This test fails on big-endian CPUs because the clk gate implementation writes to 'fake_reg' with writel(), which converts the value to be written to little-endian before storing the value in the fake register. When the test checks the bits in the fake register on a big-endian machine it falsely assumes the format of the register is also big-endian, when it is really always little-endian. Suffice to say things don't work very well. Mark 'fake_reg' as __le32 and push through endian accessor fixes wherever the value is inspected to make this test endian agnostic. There's a CLK_GATE_BIG_ENDIAN flag for big-endian MMIO devices, which this test isn't using. A follow-up patch will test with and without that flag. Reported-by: Boqun Feng <[email protected]> Closes: https://lore.kernel.org/r/ZTLH5o0GlFBYsAHq@boqun-archlinux Tested-by: Boqun Feng <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 831187c commit 7535782

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

drivers/clk/clk-gate_test.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ struct clk_gate_test_context {
131131
void __iomem *fake_mem;
132132
struct clk_hw *hw;
133133
struct clk_hw *parent;
134-
u32 fake_reg; /* Keep at end, KASAN can detect out of bounds */
134+
__le32 fake_reg; /* Keep at end, KASAN can detect out of bounds */
135135
};
136136

137137
static struct clk_gate_test_context *clk_gate_test_alloc_ctx(struct kunit *test)
@@ -166,7 +166,7 @@ static void clk_gate_test_enable(struct kunit *test)
166166

167167
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
168168

169-
KUNIT_EXPECT_EQ(test, enable_val, ctx->fake_reg);
169+
KUNIT_EXPECT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
170170
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(hw));
171171
KUNIT_EXPECT_TRUE(test, clk_hw_is_prepared(hw));
172172
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(parent));
@@ -183,10 +183,10 @@ static void clk_gate_test_disable(struct kunit *test)
183183
u32 disable_val = 0;
184184

185185
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
186-
KUNIT_ASSERT_EQ(test, enable_val, ctx->fake_reg);
186+
KUNIT_ASSERT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
187187

188188
clk_disable_unprepare(clk);
189-
KUNIT_EXPECT_EQ(test, disable_val, ctx->fake_reg);
189+
KUNIT_EXPECT_EQ(test, disable_val, le32_to_cpu(ctx->fake_reg));
190190
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(hw));
191191
KUNIT_EXPECT_FALSE(test, clk_hw_is_prepared(hw));
192192
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(parent));
@@ -246,7 +246,7 @@ static void clk_gate_test_invert_enable(struct kunit *test)
246246

247247
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
248248

249-
KUNIT_EXPECT_EQ(test, enable_val, ctx->fake_reg);
249+
KUNIT_EXPECT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
250250
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(hw));
251251
KUNIT_EXPECT_TRUE(test, clk_hw_is_prepared(hw));
252252
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(parent));
@@ -263,10 +263,10 @@ static void clk_gate_test_invert_disable(struct kunit *test)
263263
u32 disable_val = BIT(15);
264264

265265
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
266-
KUNIT_ASSERT_EQ(test, enable_val, ctx->fake_reg);
266+
KUNIT_ASSERT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
267267

268268
clk_disable_unprepare(clk);
269-
KUNIT_EXPECT_EQ(test, disable_val, ctx->fake_reg);
269+
KUNIT_EXPECT_EQ(test, disable_val, le32_to_cpu(ctx->fake_reg));
270270
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(hw));
271271
KUNIT_EXPECT_FALSE(test, clk_hw_is_prepared(hw));
272272
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(parent));
@@ -290,7 +290,7 @@ static int clk_gate_test_invert_init(struct kunit *test)
290290
2000000);
291291
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent);
292292

293-
ctx->fake_reg = BIT(15); /* Default to off */
293+
ctx->fake_reg = cpu_to_le32(BIT(15)); /* Default to off */
294294
hw = clk_hw_register_gate_parent_hw(NULL, "test_gate", parent, 0,
295295
ctx->fake_mem, 15,
296296
CLK_GATE_SET_TO_DISABLE, NULL);
@@ -319,7 +319,7 @@ static void clk_gate_test_hiword_enable(struct kunit *test)
319319

320320
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
321321

322-
KUNIT_EXPECT_EQ(test, enable_val, ctx->fake_reg);
322+
KUNIT_EXPECT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
323323
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(hw));
324324
KUNIT_EXPECT_TRUE(test, clk_hw_is_prepared(hw));
325325
KUNIT_EXPECT_TRUE(test, clk_hw_is_enabled(parent));
@@ -336,10 +336,10 @@ static void clk_gate_test_hiword_disable(struct kunit *test)
336336
u32 disable_val = BIT(9 + 16);
337337

338338
KUNIT_ASSERT_EQ(test, clk_prepare_enable(clk), 0);
339-
KUNIT_ASSERT_EQ(test, enable_val, ctx->fake_reg);
339+
KUNIT_ASSERT_EQ(test, enable_val, le32_to_cpu(ctx->fake_reg));
340340

341341
clk_disable_unprepare(clk);
342-
KUNIT_EXPECT_EQ(test, disable_val, ctx->fake_reg);
342+
KUNIT_EXPECT_EQ(test, disable_val, le32_to_cpu(ctx->fake_reg));
343343
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(hw));
344344
KUNIT_EXPECT_FALSE(test, clk_hw_is_prepared(hw));
345345
KUNIT_EXPECT_FALSE(test, clk_hw_is_enabled(parent));
@@ -387,7 +387,7 @@ static void clk_gate_test_is_enabled(struct kunit *test)
387387
struct clk_gate_test_context *ctx;
388388

389389
ctx = clk_gate_test_alloc_ctx(test);
390-
ctx->fake_reg = BIT(7);
390+
ctx->fake_reg = cpu_to_le32(BIT(7));
391391
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 7,
392392
0, NULL);
393393
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
@@ -402,7 +402,7 @@ static void clk_gate_test_is_disabled(struct kunit *test)
402402
struct clk_gate_test_context *ctx;
403403

404404
ctx = clk_gate_test_alloc_ctx(test);
405-
ctx->fake_reg = BIT(4);
405+
ctx->fake_reg = cpu_to_le32(BIT(4));
406406
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 7,
407407
0, NULL);
408408
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
@@ -417,7 +417,7 @@ static void clk_gate_test_is_enabled_inverted(struct kunit *test)
417417
struct clk_gate_test_context *ctx;
418418

419419
ctx = clk_gate_test_alloc_ctx(test);
420-
ctx->fake_reg = BIT(31);
420+
ctx->fake_reg = cpu_to_le32(BIT(31));
421421
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 2,
422422
CLK_GATE_SET_TO_DISABLE, NULL);
423423
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
@@ -432,7 +432,7 @@ static void clk_gate_test_is_disabled_inverted(struct kunit *test)
432432
struct clk_gate_test_context *ctx;
433433

434434
ctx = clk_gate_test_alloc_ctx(test);
435-
ctx->fake_reg = BIT(29);
435+
ctx->fake_reg = cpu_to_le32(BIT(29));
436436
hw = clk_hw_register_gate(NULL, "test_gate", NULL, 0, ctx->fake_mem, 29,
437437
CLK_GATE_SET_TO_DISABLE, NULL);
438438
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);

0 commit comments

Comments
 (0)