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>
25 files changed:
struct udevice *dev;
int ret;
struct udevice *dev;
int ret;
- ret = uclass_first_device(UCLASS_MISC, &dev);
- if (ret || !dev)
+ ret = uclass_first_device_err(UCLASS_MISC, &dev);
+ if (ret)
return ret;
#if defined(CONFIG_DM_ETH) && defined(CONFIG_USB_ETHER)
return ret;
#if defined(CONFIG_DM_ETH) && defined(CONFIG_USB_ETHER)
int ret;
/* Start up the LPC so we have serial */
int ret;
/* Start up the LPC so we have serial */
- ret = uclass_first_device(UCLASS_LPC, &dev);
+ ret = uclass_first_device_err(UCLASS_LPC, &dev);
- if (!dev)
- return -ENODEV;
ret = cpu_set_flex_ratio_to_tdp_nominal();
if (ret)
return ret;
ret = cpu_set_flex_ratio_to_tdp_nominal();
if (ret)
return ret;
/* Early chipset init required before RAM init can work */
uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
/* Early chipset init required before RAM init can work */
uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
- ret = uclass_first_device(UCLASS_LPC, &lpc);
+ ret = uclass_first_device_err(UCLASS_LPC, &lpc);
- if (!lpc)
- return -ENODEV;
/* Cause the SATA device to do its early init */
uclass_first_device(UCLASS_AHCI, &dev);
/* Cause the SATA device to do its early init */
uclass_first_device(UCLASS_AHCI, &dev);
u32 iobase = -1;
debug("%s: start\n", __func__);
u32 iobase = -1;
debug("%s: start\n", __func__);
- ret = uclass_first_device(UCLASS_PCH, &pch);
+ ret = uclass_first_device_err(UCLASS_PCH, &pch);
- if (!pch)
- return -ENODEV;
/*
* Get the memory/io base address to configure every pins.
/*
* Get the memory/io base address to configure every pins.
struct udevice *pch;
int ret;
struct udevice *pch;
int ret;
- ret = uclass_first_device(UCLASS_PCH, &pch);
+ ret = uclass_first_device_err(UCLASS_PCH, &pch);
- if (!pch)
- return -ENODEV;
/* Initialize LPC interface to turn on superio chipset decode range */
dm_pci_write_config16(pch, LPC_IO_DEC, COMA_DEC_RANGE | COMB_DEC_RANGE);
/* Initialize LPC interface to turn on superio chipset decode range */
dm_pci_write_config16(pch, LPC_IO_DEC, COMA_DEC_RANGE | COMB_DEC_RANGE);
((mmc->selected_mode == UHS_SDR50) && (val & CAPA2_TSDR50))))
return 0;
((mmc->selected_mode == UHS_SDR50) && (val & CAPA2_TSDR50))))
return 0;
- ret = uclass_first_device(UCLASS_THERMAL, &thermal_dev);
+ ret = uclass_first_device_err(UCLASS_THERMAL, &thermal_dev);
if (ret) {
printf("Couldn't get thermal device for tuning\n");
return ret;
if (ret) {
printf("Couldn't get thermal device for tuning\n");
return ret;
#else
if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) ||
!uclass_get_device(UCLASS_SERIAL, INDEX, &dev) ||
#else
if (!uclass_get_device_by_seq(UCLASS_SERIAL, INDEX, &dev) ||
!uclass_get_device(UCLASS_SERIAL, INDEX, &dev) ||
- (!uclass_first_device(UCLASS_SERIAL, &dev) && dev)) {
+ !uclass_first_device_err(UCLASS_SERIAL, &dev)) {
gd->cur_serial_dev = dev;
return;
}
gd->cur_serial_dev = dev;
return;
}
int serial_gpio = 15;
struct udevice *dev;
int serial_gpio = 15;
struct udevice *dev;
- if (uclass_first_device(UCLASS_PINCTRL, &dev) || !dev)
+ if (uclass_first_device_err(UCLASS_PINCTRL, &dev))
return false;
if (pinctrl_get_gpio_mux(dev, 0, serial_gpio) != BCM2835_GPIO_ALT5)
return false;
if (pinctrl_get_gpio_mux(dev, 0, serial_gpio) != BCM2835_GPIO_ALT5)
int serial_gpio = 15;
struct udevice *dev;
int serial_gpio = 15;
struct udevice *dev;
- if (uclass_first_device(UCLASS_PINCTRL, &dev) || !dev)
+ if (uclass_first_device_err(UCLASS_PINCTRL, &dev))
return false;
if (pinctrl_get_gpio_mux(dev, 0, serial_gpio) != BCM2835_GPIO_ALT0)
return false;
if (pinctrl_get_gpio_mux(dev, 0, serial_gpio) != BCM2835_GPIO_ALT0)
{
struct udevice *wdt;
u32 reset_mode;
{
struct udevice *wdt;
u32 reset_mode;
- int ret = uclass_first_device(UCLASS_WDT, &wdt);
+ int ret = uclass_first_device_err(UCLASS_WDT, &wdt);
#endif
exynos_fimd_lcd_init(dev);
#endif
exynos_fimd_lcd_init(dev);
- ret = uclass_first_device(UCLASS_PANEL, &panel);
+ ret = uclass_first_device_err(UCLASS_PANEL, &panel);
- printf("LCD panel failed to probe\n");
+ printf("%s: LCD panel failed to probe %d\n", __func__, ret);
- if (!panel) {
- printf("LCD panel not found\n");
- return -ENODEV;
- }
- ret = uclass_first_device(UCLASS_DISPLAY, &dp);
+ ret = uclass_first_device_err(UCLASS_DISPLAY, &dp);
if (ret) {
debug("%s: Display device error %d\n", __func__, ret);
return ret;
}
if (ret) {
debug("%s: Display device error %d\n", __func__, ret);
return ret;
}
- if (!dev) {
- debug("%s: Display device missing\n", __func__);
- return -ENODEV;
- }
ret = display_enable(dp, 18, NULL);
if (ret) {
debug("%s: Display enable error %d\n", __func__, ret);
ret = display_enable(dp, 18, NULL);
if (ret) {
debug("%s: Display enable error %d\n", __func__, ret);
struct udevice *disp_dev;
int err;
struct udevice *disp_dev;
int err;
- err = uclass_first_device(UCLASS_DISPLAY, &disp_dev);
+ err = uclass_first_device_err(UCLASS_DISPLAY, &disp_dev);
struct display_timing timings;
int ret;
struct display_timing timings;
int ret;
- ret = uclass_first_device(UCLASS_PANEL, &priv->panel);
+ ret = uclass_first_device_err(UCLASS_PANEL, &priv->panel);
if (ret) {
dev_err(dev, "panel device error %d\n", ret);
return ret;
if (ret) {
dev_err(dev, "panel device error %d\n", ret);
return ret;
- ret = uclass_first_device(UCLASS_VIDEO_BRIDGE, &sor);
- if (ret || !sor) {
+ ret = uclass_first_device_err(UCLASS_VIDEO_BRIDGE, &sor);
+ if (ret) {
debug("dp: failed to find SOR device: ret=%d\n", ret);
return ret;
}
debug("dp: failed to find SOR device: ret=%d\n", ret);
return ret;
}
struct udevice *cpu;
int ret;
struct udevice *cpu;
int ret;
- ret = uclass_first_device(UCLASS_CPU, &cpu);
+ ret = uclass_first_device_err(UCLASS_CPU, &cpu);
if (ret)
return log_msg_ret("cpu", ret);
ret = cpu_get_info(cpu, &info);
if (ret)
return log_msg_ret("cpu", ret);
ret = cpu_get_info(cpu, &info);
struct video_priv *priv;
/* We only support a single video output device for now */
struct video_priv *priv;
/* We only support a single video output device for now */
- if (uclass_first_device(UCLASS_VIDEO, &vdev) || !vdev) {
+ if (uclass_first_device_err(UCLASS_VIDEO, &vdev)) {
debug("WARNING: No video device\n");
return EFI_SUCCESS;
}
debug("WARNING: No video device\n");
return EFI_SUCCESS;
}
eth_errno = uclass_get_device_by_seq(UCLASS_ETH, 0,
&uc_priv->current);
if (eth_errno)
eth_errno = uclass_get_device_by_seq(UCLASS_ETH, 0,
&uc_priv->current);
if (eth_errno)
- eth_errno = uclass_first_device(UCLASS_ETH,
- &uc_priv->current);
+ eth_errno = uclass_first_device_err(UCLASS_ETH,
+ &uc_priv->current);
}
return uc_priv->current;
}
}
return uc_priv->current;
}
struct udevice *dev;
char buf[50];
struct udevice *dev;
char buf[50];
- ut_assertok(uclass_first_device(UCLASS_BOOTMETH, &dev));
+ ut_assertok(uclass_first_device_err(UCLASS_BOOTMETH, &dev));
ut_assertnonnull(dev);
ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf)));
ut_assertnonnull(dev);
ut_assertok(bootmeth_get_state_desc(dev, buf, sizeof(buf)));
ut_asserteq_str("GHIJ", name);
/* Test getting the name from acpi_device_get_name() */
ut_asserteq_str("GHIJ", name);
/* Test getting the name from acpi_device_get_name() */
- ut_assertok(uclass_first_device(UCLASS_I2C, &i2c));
+ ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c));
ut_assertok(acpi_get_name(i2c, name));
ut_asserteq_str("I2C0", name);
ut_assertok(acpi_get_name(i2c, name));
ut_asserteq_str("I2C0", name);
- ut_assertok(uclass_first_device(UCLASS_SPI, &spi));
+ ut_assertok(uclass_first_device_err(UCLASS_SPI, &spi));
ut_assertok(acpi_get_name(spi, name));
ut_asserteq_str("SPI0", name);
/* ACPI doesn't know about the timer */
ut_assertok(acpi_get_name(spi, name));
ut_asserteq_str("SPI0", name);
/* ACPI doesn't know about the timer */
- ut_assertok(uclass_first_device(UCLASS_TIMER, &timer));
+ ut_assertok(uclass_first_device_err(UCLASS_TIMER, &timer));
ut_asserteq(-ENOENT, acpi_get_name(timer, name));
/* May as well test the rest of the cases */
ut_asserteq(-ENOENT, acpi_get_name(timer, name));
/* May as well test the rest of the cases */
- ut_assertok(uclass_first_device(UCLASS_SOUND, &sound));
+ ut_assertok(uclass_first_device_err(UCLASS_SOUND, &sound));
ut_assertok(acpi_get_name(sound, name));
ut_asserteq_str("HDAS", name);
ut_assertok(acpi_get_name(sound, name));
ut_asserteq_str("HDAS", name);
- ut_assertok(uclass_first_device(UCLASS_PCI, &pci));
+ ut_assertok(uclass_first_device_err(UCLASS_PCI, &pci));
ut_assertok(acpi_get_name(pci, name));
ut_asserteq_str("PCI0", name);
ut_assertok(acpi_get_name(pci, name));
ut_asserteq_str("PCI0", name);
- ut_assertok(uclass_first_device(UCLASS_ROOT, &root));
+ ut_assertok(uclass_first_device_err(UCLASS_ROOT, &root));
ut_assertok(acpi_get_name(root, name));
ut_asserteq_str("\\_SB", name);
ut_assertok(acpi_get_name(root, name));
ut_asserteq_str("\\_SB", name);
struct acpi_dmar dmar;
struct udevice *cpu;
struct acpi_dmar dmar;
struct udevice *cpu;
- ut_assertok(uclass_first_device(UCLASS_CPU, &cpu));
+ ut_assertok(uclass_first_device_err(UCLASS_CPU, &cpu));
ut_assertnonnull(cpu);
ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
ut_assertnonnull(cpu);
ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE3, stats.total_size);
/* Probing the device should add one allocation */
ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE3, stats.total_size);
/* Probing the device should add one allocation */
- ut_assertok(uclass_first_device(UCLASS_TEST_DEVRES, &dev));
- ut_assert(dev != NULL);
+ ut_assertok(uclass_first_device_err(UCLASS_TEST_DEVRES, &dev));
+ ut_assertnonnull(dev);
devres_get_stats(dev, &stats);
ut_asserteq(3, stats.allocs);
ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2 + TEST_DEVRES_SIZE3,
devres_get_stats(dev, &stats);
ut_asserteq(3, stats.allocs);
ut_asserteq(TEST_DEVRES_SIZE + TEST_DEVRES_SIZE2 + TEST_DEVRES_SIZE3,
ut_asserteq_mem(buf, "\0\0\0\0\0", sizeof(buf));
/* Tell the EEPROM to only read/write one register at a time */
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);
ut_assertnonnull(eeprom);
sandbox_i2c_eeprom_set_test_mode(eeprom, SIE_TEST_MODE_SINGLE_BYTE);
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
/* 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);
/* Offset length 0 */
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
/* 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);
/* Offset length 0 */
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
/* Do a transfer so we can find the emulator */
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
/* 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));
/* Dummy data for the test */
ut_assertok(dm_i2c_write(dev, 0, "\xff\x00\xff\x00\x10", 5));
u8 status;
/* check probe success */
u8 status;
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
struct virtqueue *vqs[2];
/* check probe success */
struct virtqueue *vqs[2];
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
struct udevice *bus, *dev;
/* check probe success */
struct udevice *bus, *dev;
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
u8 buffer[2][32];
/* check probe success */
u8 buffer[2][32];
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-blk device is bound */
ut_assertnonnull(bus);
/* check the child virtio-blk device is bound */
u8 buffer[16];
/* check probe success */
u8 buffer[16];
/* check probe success */
- ut_assertok(uclass_first_device(UCLASS_VIRTIO, &bus));
+ ut_assertok(uclass_first_device_err(UCLASS_VIRTIO, &bus));
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
ut_assertnonnull(bus);
/* check the child virtio-rng device is bound */
- if (uclass_first_device(UCLASS_FUZZING_ENGINE, &dev))
+ if (uclass_first_device_err(UCLASS_FUZZING_ENGINE, &dev))
return 0;
/* check probe success */
return 0;
/* check probe success */
- if (uclass_first_device(UCLASS_VIRTIO, &bus) || !bus)
+ if (uclass_first_device_err(UCLASS_VIRTIO, &bus))
panic("Could not find virtio bus\n");
/* check the child virtio-rng device is bound */
panic("Could not find virtio bus\n");
/* check the child virtio-rng device is bound */