aboutsummaryrefslogtreecommitdiff
path: root/test/dm/i2c.c
diff options
context:
space:
mode:
authorMichal Suchanek <msuchanek@suse.de>2022-10-12 21:57:59 +0200
committerSimon Glass <sjg@chromium.org>2022-10-17 21:17:12 -0600
commitc726fc01cf669e3e2979da8665ef660e7d3ba464 (patch)
tree5d11dc2d0e58fac8a08cb1e2425ff0ae10ad0a8a /test/dm/i2c.c
parent8676ae36ae4617b20b5cc49972c54c63c7b27bb3 (diff)
downloadu-boot-c726fc01cf669e3e2979da8665ef660e7d3ba464.zip
u-boot-c726fc01cf669e3e2979da8665ef660e7d3ba464.tar.gz
u-boot-c726fc01cf669e3e2979da8665ef660e7d3ba464.tar.bz2
dm: treewide: Use uclass_first_device_err when accessing one device
There is a number of users that use uclass_first_device to access the first and (assumed) only device in uclass. Some check the return value of uclass_first_device and also that a device was returned which is exactly what uclass_first_device_err does. Some are not checking that a device was returned and can potentially crash if no device exists in the uclass. Finally there is one that returns NULL on error either way. Convert all of these to use uclass_first_device_err instead, the return value will be removed from uclass_first_device in a later patch. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/dm/i2c.c')
-rw-r--r--test/dm/i2c.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/test/dm/i2c.c b/test/dm/i2c.c
index 74b2097..b46a22e 100644
--- a/test/dm/i2c.c
+++ b/test/dm/i2c.c
@@ -124,7 +124,7 @@ static int dm_test_i2c_bytewise(struct unit_test_state *uts)
ut_asserteq_mem(buf, "\0\0\0\0\0", sizeof(buf));
/* Tell the EEPROM to only read/write one register at a time */
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
ut_assertnonnull(eeprom);
sandbox_i2c_eeprom_set_test_mode(eeprom, SIE_TEST_MODE_SINGLE_BYTE);
@@ -177,7 +177,7 @@ static int dm_test_i2c_offset(struct unit_test_state *uts)
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
/* Offset length 0 */
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
@@ -250,7 +250,7 @@ static int dm_test_i2c_addr_offset(struct unit_test_state *uts)
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
/* Offset length 0 */
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
@@ -315,7 +315,7 @@ static int dm_test_i2c_reg_clrset(struct unit_test_state *uts)
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
- ut_assertok(uclass_first_device(UCLASS_I2C_EMUL, &eeprom));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
/* Dummy data for the test */
ut_assertok(dm_i2c_write(dev, 0, "\xff\x00\xff\x00\x10", 5));