Commit 2c460834 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'regmap-fix-v6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap test fixes from Mark Brown:
 "Guenter runs a lot of KUnit tests so noticed that there were a couple
  of the regmap tests, including the newly added noinc test, which could
  show spurious failures due to the use of randomly generated test
  values. These changes handle the randomly generated data properly"

* tag 'regmap-fix-v6.8-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: kunit: Ensure that changed bytes are actually different
  regmap: kunit: fix raw noinc write test wrapping
parents 9207fe75 2f0dbb24
...@@ -9,6 +9,23 @@ ...@@ -9,6 +9,23 @@
#define BLOCK_TEST_SIZE 12 #define BLOCK_TEST_SIZE 12
static void get_changed_bytes(void *orig, void *new, size_t size)
{
char *o = orig;
char *n = new;
int i;
get_random_bytes(new, size);
/*
* This could be nicer and more efficient but we shouldn't
* super care.
*/
for (i = 0; i < size; i++)
while (n[i] == o[i])
get_random_bytes(&n[i], 1);
}
static const struct regmap_config test_regmap_config = { static const struct regmap_config test_regmap_config = {
.max_register = BLOCK_TEST_SIZE, .max_register = BLOCK_TEST_SIZE,
.reg_stride = 1, .reg_stride = 1,
...@@ -1202,7 +1219,8 @@ static void raw_noinc_write(struct kunit *test) ...@@ -1202,7 +1219,8 @@ static void raw_noinc_write(struct kunit *test)
struct regmap *map; struct regmap *map;
struct regmap_config config; struct regmap_config config;
struct regmap_ram_data *data; struct regmap_ram_data *data;
unsigned int val, val_test, val_last; unsigned int val;
u16 val_test, val_last;
u16 val_array[BLOCK_TEST_SIZE]; u16 val_array[BLOCK_TEST_SIZE];
config = raw_regmap_config; config = raw_regmap_config;
...@@ -1251,7 +1269,7 @@ static void raw_sync(struct kunit *test) ...@@ -1251,7 +1269,7 @@ static void raw_sync(struct kunit *test)
struct regmap *map; struct regmap *map;
struct regmap_config config; struct regmap_config config;
struct regmap_ram_data *data; struct regmap_ram_data *data;
u16 val[2]; u16 val[3];
u16 *hw_buf; u16 *hw_buf;
unsigned int rval; unsigned int rval;
int i; int i;
...@@ -1265,17 +1283,13 @@ static void raw_sync(struct kunit *test) ...@@ -1265,17 +1283,13 @@ static void raw_sync(struct kunit *test)
hw_buf = (u16 *)data->vals; hw_buf = (u16 *)data->vals;
get_random_bytes(&val, sizeof(val)); get_changed_bytes(&hw_buf[2], &val[0], sizeof(val));
/* Do a regular write and a raw write in cache only mode */ /* Do a regular write and a raw write in cache only mode */
regcache_cache_only(map, true); regcache_cache_only(map, true);
KUNIT_EXPECT_EQ(test, 0, regmap_raw_write(map, 2, val, sizeof(val))); KUNIT_EXPECT_EQ(test, 0, regmap_raw_write(map, 2, val,
if (config.val_format_endian == REGMAP_ENDIAN_BIG) sizeof(u16) * 2));
KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 6, KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 4, val[2]));
be16_to_cpu(val[0])));
else
KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 6,
le16_to_cpu(val[0])));
/* We should read back the new values, and defaults for the rest */ /* We should read back the new values, and defaults for the rest */
for (i = 0; i < config.max_register + 1; i++) { for (i = 0; i < config.max_register + 1; i++) {
...@@ -1284,24 +1298,34 @@ static void raw_sync(struct kunit *test) ...@@ -1284,24 +1298,34 @@ static void raw_sync(struct kunit *test)
switch (i) { switch (i) {
case 2: case 2:
case 3: case 3:
case 6:
if (config.val_format_endian == REGMAP_ENDIAN_BIG) { if (config.val_format_endian == REGMAP_ENDIAN_BIG) {
KUNIT_EXPECT_EQ(test, rval, KUNIT_EXPECT_EQ(test, rval,
be16_to_cpu(val[i % 2])); be16_to_cpu(val[i - 2]));
} else { } else {
KUNIT_EXPECT_EQ(test, rval, KUNIT_EXPECT_EQ(test, rval,
le16_to_cpu(val[i % 2])); le16_to_cpu(val[i - 2]));
} }
break; break;
case 4:
KUNIT_EXPECT_EQ(test, rval, val[i - 2]);
break;
default: default:
KUNIT_EXPECT_EQ(test, config.reg_defaults[i].def, rval); KUNIT_EXPECT_EQ(test, config.reg_defaults[i].def, rval);
break; break;
} }
} }
/*
* The value written via _write() was translated by the core,
* translate the original copy for comparison purposes.
*/
if (config.val_format_endian == REGMAP_ENDIAN_BIG)
val[2] = cpu_to_be16(val[2]);
else
val[2] = cpu_to_le16(val[2]);
/* The values should not appear in the "hardware" */ /* The values should not appear in the "hardware" */
KUNIT_EXPECT_MEMNEQ(test, &hw_buf[2], val, sizeof(val)); KUNIT_EXPECT_MEMNEQ(test, &hw_buf[2], &val[0], sizeof(val));
KUNIT_EXPECT_MEMNEQ(test, &hw_buf[6], val, sizeof(u16));
for (i = 0; i < config.max_register + 1; i++) for (i = 0; i < config.max_register + 1; i++)
data->written[i] = false; data->written[i] = false;
...@@ -1312,8 +1336,7 @@ static void raw_sync(struct kunit *test) ...@@ -1312,8 +1336,7 @@ static void raw_sync(struct kunit *test)
KUNIT_EXPECT_EQ(test, 0, regcache_sync(map)); KUNIT_EXPECT_EQ(test, 0, regcache_sync(map));
/* The values should now appear in the "hardware" */ /* The values should now appear in the "hardware" */
KUNIT_EXPECT_MEMEQ(test, &hw_buf[2], val, sizeof(val)); KUNIT_EXPECT_MEMEQ(test, &hw_buf[2], &val[0], sizeof(val));
KUNIT_EXPECT_MEMEQ(test, &hw_buf[6], val, sizeof(u16));
regmap_exit(map); regmap_exit(map);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment