regmap: Allow reads from write only registers with the flat cache
authorMark Brown <broonie@kernel.org>
Sat, 17 Jun 2023 20:11:07 +0000 (21:11 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 19 Jun 2023 11:59:41 +0000 (12:59 +0100)
The flat cache is intended for devices that need the lowest overhead so
doesn't track any sparseness.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20230617-regmap-kunit-read-writeonly-flat-v1-1-efd3ed66dec6@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/regmap-kunit.c

index 6f444ac..24257aa 100644 (file)
@@ -252,9 +252,18 @@ static void read_writeonly(struct kunit *test)
        for (i = 0; i < BLOCK_TEST_SIZE; i++)
                data->read[i] = false;
 
-       /* Try to read all the registers, the writeonly one should fail */
-       for (i = 0; i < BLOCK_TEST_SIZE; i++)
-               KUNIT_EXPECT_EQ(test, i != 5, regmap_read(map, i, &val) == 0);
+       /*
+        * Try to read all the registers, the writeonly one should
+        * fail if we aren't using the flat cache.
+        */
+       for (i = 0; i < BLOCK_TEST_SIZE; i++) {
+               if (t->type != REGCACHE_FLAT) {
+                       KUNIT_EXPECT_EQ(test, i != 5,
+                                       regmap_read(map, i, &val) == 0);
+               } else {
+                       KUNIT_EXPECT_EQ(test, 0, regmap_read(map, i, &val));
+               }
+       }
 
        /* Did we trigger a hardware access? */
        KUNIT_EXPECT_FALSE(test, data->read[5]);