Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+40 -17
+40 -17
drivers/base/regmap/regmap-kunit.c
··· 9 9 10 10 #define BLOCK_TEST_SIZE 12 11 11 12 + static void get_changed_bytes(void *orig, void *new, size_t size) 13 + { 14 + char *o = orig; 15 + char *n = new; 16 + int i; 17 + 18 + get_random_bytes(new, size); 19 + 20 + /* 21 + * This could be nicer and more efficient but we shouldn't 22 + * super care. 23 + */ 24 + for (i = 0; i < size; i++) 25 + while (n[i] == o[i]) 26 + get_random_bytes(&n[i], 1); 27 + } 28 + 12 29 static const struct regmap_config test_regmap_config = { 13 30 .max_register = BLOCK_TEST_SIZE, 14 31 .reg_stride = 1, ··· 1219 1202 struct regmap *map; 1220 1203 struct regmap_config config; 1221 1204 struct regmap_ram_data *data; 1222 - unsigned int val, val_test, val_last; 1205 + unsigned int val; 1206 + u16 val_test, val_last; 1223 1207 u16 val_array[BLOCK_TEST_SIZE]; 1224 1208 1225 1209 config = raw_regmap_config; ··· 1269 1251 struct regmap *map; 1270 1252 struct regmap_config config; 1271 1253 struct regmap_ram_data *data; 1272 - u16 val[2]; 1254 + u16 val[3]; 1273 1255 u16 *hw_buf; 1274 1256 unsigned int rval; 1275 1257 int i; ··· 1283 1265 1284 1266 hw_buf = (u16 *)data->vals; 1285 1267 1286 - get_random_bytes(&val, sizeof(val)); 1268 + get_changed_bytes(&hw_buf[2], &val[0], sizeof(val)); 1287 1269 1288 1270 /* Do a regular write and a raw write in cache only mode */ 1289 1271 regcache_cache_only(map, true); 1290 - KUNIT_EXPECT_EQ(test, 0, regmap_raw_write(map, 2, val, sizeof(val))); 1291 - if (config.val_format_endian == REGMAP_ENDIAN_BIG) 1292 - KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 6, 1293 - be16_to_cpu(val[0]))); 1294 - else 1295 - KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 6, 1296 - le16_to_cpu(val[0]))); 1272 + KUNIT_EXPECT_EQ(test, 0, regmap_raw_write(map, 2, val, 1273 + sizeof(u16) * 2)); 1274 + KUNIT_EXPECT_EQ(test, 0, regmap_write(map, 4, val[2])); 1297 1275 1298 1276 /* We should read back the new values, and defaults for the rest */ 1299 1277 for (i = 0; i < config.max_register + 1; i++) { ··· 1298 1284 switch (i) { 1299 1285 case 2: 1300 1286 case 3: 1301 - case 6: 1302 1287 if (config.val_format_endian == REGMAP_ENDIAN_BIG) { 1303 1288 KUNIT_EXPECT_EQ(test, rval, 1304 - be16_to_cpu(val[i % 2])); 1289 + be16_to_cpu(val[i - 2])); 1305 1290 } else { 1306 1291 KUNIT_EXPECT_EQ(test, rval, 1307 - le16_to_cpu(val[i % 2])); 1292 + le16_to_cpu(val[i - 2])); 1308 1293 } 1294 + break; 1295 + case 4: 1296 + KUNIT_EXPECT_EQ(test, rval, val[i - 2]); 1309 1297 break; 1310 1298 default: 1311 1299 KUNIT_EXPECT_EQ(test, config.reg_defaults[i].def, rval); 1312 1300 break; 1313 1301 } 1314 1302 } 1303 + 1304 + /* 1305 + * The value written via _write() was translated by the core, 1306 + * translate the original copy for comparison purposes. 1307 + */ 1308 + if (config.val_format_endian == REGMAP_ENDIAN_BIG) 1309 + val[2] = cpu_to_be16(val[2]); 1310 + else 1311 + val[2] = cpu_to_le16(val[2]); 1315 1312 1316 1313 /* The values should not appear in the "hardware" */ 1317 - KUNIT_EXPECT_MEMNEQ(test, &hw_buf[2], val, sizeof(val)); 1318 - KUNIT_EXPECT_MEMNEQ(test, &hw_buf[6], val, sizeof(u16)); 1314 + KUNIT_EXPECT_MEMNEQ(test, &hw_buf[2], &val[0], sizeof(val)); 1319 1315 1320 1316 for (i = 0; i < config.max_register + 1; i++) 1321 1317 data->written[i] = false; ··· 1336 1312 KUNIT_EXPECT_EQ(test, 0, regcache_sync(map)); 1337 1313 1338 1314 /* The values should now appear in the "hardware" */ 1339 - KUNIT_EXPECT_MEMEQ(test, &hw_buf[2], val, sizeof(val)); 1340 - KUNIT_EXPECT_MEMEQ(test, &hw_buf[6], val, sizeof(u16)); 1315 + KUNIT_EXPECT_MEMEQ(test, &hw_buf[2], &val[0], sizeof(val)); 1341 1316 1342 1317 regmap_exit(map); 1343 1318 }