[U-Boot] [PATCH 2/2] dm: Use uclass_first_device_err() where it is useful
Simon Glass
sjg at chromium.org
Thu Feb 11 21:23:26 CET 2016
Use this new function in places where it simplifies the code.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
arch/arm/mach-rockchip/rk3288/sdram_rk3288.c | 2 +-
arch/nios2/cpu/cpu.c | 4 +---
arch/x86/cpu/interrupts.c | 2 +-
arch/x86/cpu/ivybridge/cpu.c | 14 +++++---------
arch/x86/cpu/ivybridge/gma.c | 6 +++---
arch/x86/cpu/ivybridge/sata.c | 4 +---
arch/x86/cpu/ivybridge/sdram.c | 4 +---
arch/x86/lib/mpspec.c | 2 +-
cmd/bmp.c | 12 ++++--------
cmd/tpm.c | 4 ++--
drivers/gpio/rk_gpio.c | 4 +---
drivers/misc/altera_sysid.c | 4 +---
drivers/pci/pci-uclass.c | 4 +---
drivers/power/regulator/regulator-uclass.c | 2 +-
drivers/timer/timer-uclass.c | 4 +---
drivers/video/vidconsole-uclass.c | 6 ++----
lib/tpm.c | 6 +++---
17 files changed, 30 insertions(+), 54 deletions(-)
diff --git a/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c b/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c
index e9e2211..2e21282 100644
--- a/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c
+++ b/arch/arm/mach-rockchip/rk3288/sdram_rk3288.c
@@ -756,7 +756,7 @@ static int veyron_init(struct dram_info *priv)
struct udevice *pmic;
int ret;
- ret = uclass_first_device(UCLASS_PMIC, &pmic);
+ ret = uclass_first_device_err(UCLASS_PMIC, &pmic);
if (ret)
return ret;
diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c
index be7f99c..4f0f8fc 100644
--- a/arch/nios2/cpu/cpu.c
+++ b/arch/nios2/cpu/cpu.c
@@ -63,11 +63,9 @@ int arch_cpu_init_dm(void)
struct udevice *dev;
int ret;
- ret = uclass_first_device(UCLASS_CPU, &dev);
+ ret = uclass_first_device_err(UCLASS_CPU, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
#ifndef CONFIG_ROM_STUBS
diff --git a/arch/x86/cpu/interrupts.c b/arch/x86/cpu/interrupts.c
index c40200b..10dc4d4 100644
--- a/arch/x86/cpu/interrupts.c
+++ b/arch/x86/cpu/interrupts.c
@@ -249,7 +249,7 @@ int interrupt_init(void)
int ret;
/* Try to set up the interrupt router, but don't require one */
- ret = uclass_first_device(UCLASS_IRQ, &dev);
+ ret = uclass_first_device_err(UCLASS_IRQ, &dev);
if (ret && ret != -ENODEV)
return ret;
diff --git a/arch/x86/cpu/ivybridge/cpu.c b/arch/x86/cpu/ivybridge/cpu.c
index 948833c..5d839a7 100644
--- a/arch/x86/cpu/ivybridge/cpu.c
+++ b/arch/x86/cpu/ivybridge/cpu.c
@@ -104,9 +104,9 @@ int arch_cpu_init_dm(void)
/* TODO(sjg at chromium.org): Get rid of gd->hose */
gd->hose = hose;
- ret = uclass_first_device(UCLASS_LPC, &dev);
- if (!dev)
- return -ENODEV;
+ ret = uclass_first_device_err(UCLASS_LPC, &dev);
+ if (ret)
+ return ret;
/*
* We should do as little as possible before the serial console is
@@ -210,11 +210,9 @@ int print_cpuinfo(void)
/* 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 (ret)
return ret;
- if (!dev)
- return -ENODEV;
/* Cause the SATA device to do its early init */
uclass_first_device(UCLASS_DISK, &dev);
@@ -236,11 +234,9 @@ int print_cpuinfo(void)
post_code(POST_EARLY_INIT);
/* Enable SPD ROMs and DDR-III DRAM */
- ret = uclass_first_device(UCLASS_I2C, &dev);
+ ret = uclass_first_device_err(UCLASS_I2C, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
/* Prepare USB controller early in S3 resume */
if (boot_mode == PEI_BOOT_RESUME)
diff --git a/arch/x86/cpu/ivybridge/gma.c b/arch/x86/cpu/ivybridge/gma.c
index 3b6291e..91a57f9 100644
--- a/arch/x86/cpu/ivybridge/gma.c
+++ b/arch/x86/cpu/ivybridge/gma.c
@@ -812,9 +812,9 @@ int gma_func0_init(struct udevice *dev)
writew(0x0010, RCB_REG(DISPBDF));
setbits_le32(RCB_REG(FD2), PCH_ENABLE_DBDF);
- ret = uclass_first_device(UCLASS_NORTHBRIDGE, &nbridge);
- if (!nbridge)
- return -ENODEV;
+ ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &nbridge);
+ if (ret)
+ return ret;
rev = bridge_silicon_revision(nbridge);
sandybridge_setup_graphics(nbridge, dev);
diff --git a/arch/x86/cpu/ivybridge/sata.c b/arch/x86/cpu/ivybridge/sata.c
index a59d9ed..da6455b 100644
--- a/arch/x86/cpu/ivybridge/sata.c
+++ b/arch/x86/cpu/ivybridge/sata.c
@@ -229,11 +229,9 @@ static int bd82x6x_sata_probe(struct udevice *dev)
struct udevice *pch;
int ret;
- ret = uclass_first_device(UCLASS_PCH, &pch);
+ ret = uclass_first_device_err(UCLASS_PCH, &pch);
if (ret)
return ret;
- if (!pch)
- return -ENODEV;
if (!(gd->flags & GD_FLG_RELOC))
bd82x6x_sata_enable(dev);
diff --git a/arch/x86/cpu/ivybridge/sdram.c b/arch/x86/cpu/ivybridge/sdram.c
index e23c422..0ebcc2c 100644
--- a/arch/x86/cpu/ivybridge/sdram.c
+++ b/arch/x86/cpu/ivybridge/sdram.c
@@ -736,11 +736,9 @@ int dram_init(void)
struct udevice *dev, *me_dev;
int ret;
- ret = uclass_first_device(UCLASS_NORTHBRIDGE, &dev);
+ ret = uclass_first_device_err(UCLASS_NORTHBRIDGE, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
ret = syscon_get_by_driver_data(X86_SYSCON_ME, &me_dev);
if (ret)
return ret;
diff --git a/arch/x86/lib/mpspec.c b/arch/x86/lib/mpspec.c
index 0faa582..6ab43f1 100644
--- a/arch/x86/lib/mpspec.c
+++ b/arch/x86/lib/mpspec.c
@@ -297,7 +297,7 @@ static int mptable_add_intsrc(struct mp_config_table *mc,
const u32 *cell;
int i, ret;
- ret = uclass_first_device(UCLASS_IRQ, &dev);
+ ret = uclass_first_device_err(UCLASS_IRQ, &dev);
if (ret && ret != -ENODEV) {
debug("%s: Cannot find irq router node\n", __func__);
return ret;
diff --git a/cmd/bmp.c b/cmd/bmp.c
index fd5b7db..edad918 100644
--- a/cmd/bmp.c
+++ b/cmd/bmp.c
@@ -246,18 +246,14 @@ int bmp_display(ulong addr, int x, int y)
addr = map_to_sysmem(bmp);
#ifdef CONFIG_DM_VIDEO
- ret = uclass_first_device(UCLASS_VIDEO, &dev);
+ ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
if (!ret) {
- if (!dev)
- ret = -ENODEV;
- if (!ret) {
- bool align = false;
+ bool align = false;
# ifdef CONFIG_SPLASH_SCREEN_ALIGN
- align = true;
+ align = true;
# endif /* CONFIG_SPLASH_SCREEN_ALIGN */
- ret = video_bmp_display(dev, addr, x, y, align);
- }
+ ret = video_bmp_display(dev, addr, x, y, align);
}
return ret ? CMD_RET_FAILURE : 0;
#elif defined(CONFIG_LCD)
diff --git a/cmd/tpm.c b/cmd/tpm.c
index 6edf3e9..312503f 100644
--- a/cmd/tpm.c
+++ b/cmd/tpm.c
@@ -447,8 +447,8 @@ static int get_tpm(struct udevice **devp)
{
int rc;
- rc = uclass_first_device(UCLASS_TPM, devp);
- if (rc || !*devp) {
+ rc = uclass_first_device_err(UCLASS_TPM, devp);
+ if (rc) {
printf("Could not find TPM (ret=%d)\n", rc);
return CMD_RET_FAILURE;
}
diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
index c62f025..40e87bd 100644
--- a/drivers/gpio/rk_gpio.c
+++ b/drivers/gpio/rk_gpio.c
@@ -116,11 +116,9 @@ static int rockchip_gpio_probe(struct udevice *dev)
/* This only supports RK3288 at present */
priv->regs = (struct rockchip_gpio_regs *)dev_get_addr(dev);
- ret = uclass_first_device(UCLASS_PINCTRL, &priv->pinctrl);
+ ret = uclass_first_device_err(UCLASS_PINCTRL, &priv->pinctrl);
if (ret)
return ret;
- if (!priv->pinctrl)
- return -ENODEV;
uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
end = strrchr(dev->name, '@');
diff --git a/drivers/misc/altera_sysid.c b/drivers/misc/altera_sysid.c
index 2d0fa2a..ed6d462 100644
--- a/drivers/misc/altera_sysid.c
+++ b/drivers/misc/altera_sysid.c
@@ -32,11 +32,9 @@ void display_sysid(void)
int ret;
/* the first misc device will be used */
- ret = uclass_first_device(UCLASS_MISC, &dev);
+ ret = uclass_first_device_err(UCLASS_MISC, &dev);
if (ret)
return;
- if (!dev)
- return;
ret = misc_read(dev, 0, &sysid, sizeof(sysid));
if (ret)
return;
diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
index d01bfc1..519052e 100644
--- a/drivers/pci/pci-uclass.c
+++ b/drivers/pci/pci-uclass.c
@@ -30,11 +30,9 @@ int pci_get_bus(int busnum, struct udevice **busp)
/* Since buses may not be numbered yet try a little harder with bus 0 */
if (ret == -ENODEV) {
- ret = uclass_first_device(UCLASS_PCI, busp);
+ ret = uclass_first_device_err(UCLASS_PCI, busp);
if (ret)
return ret;
- else if (!*busp)
- return -ENODEV;
ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, busp);
}
diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 9fe07f2..4434e36 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -325,7 +325,7 @@ int regulators_enable_boot_on(bool verbose)
if (ret)
return ret;
for (uclass_first_device(UCLASS_REGULATOR, &dev);
- dev && !ret;
+ dev;
uclass_next_device(&dev)) {
ret = regulator_autoset(dev);
if (ret == -EMEDIUMTYPE) {
diff --git a/drivers/timer/timer-uclass.c b/drivers/timer/timer-uclass.c
index 83d1a35..918da1a 100644
--- a/drivers/timer/timer-uclass.c
+++ b/drivers/timer/timer-uclass.c
@@ -82,11 +82,9 @@ int notrace dm_timer_init(void)
node = fdtdec_get_chosen_node(blob, "tick-timer");
if (node < 0) {
/* No chosen timer, trying first available timer */
- ret = uclass_first_device(UCLASS_TIMER, &dev);
+ ret = uclass_first_device_err(UCLASS_TIMER, &dev);
if (ret)
return ret;
- if (!dev)
- return -ENODEV;
} else {
if (uclass_get_device_by_of_offset(UCLASS_TIMER, node, &dev)) {
/*
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index f6326b6..9295af2 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -239,8 +239,7 @@ static int do_video_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc != 3)
return CMD_RET_USAGE;
- uclass_first_device(UCLASS_VIDEO_CONSOLE, &dev);
- if (!dev)
+ if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
return CMD_RET_FAILURE;
col = simple_strtoul(argv[1], NULL, 10);
row = simple_strtoul(argv[2], NULL, 10);
@@ -258,8 +257,7 @@ static int do_video_puts(cmd_tbl_t *cmdtp, int flag, int argc,
if (argc != 2)
return CMD_RET_USAGE;
- uclass_first_device(UCLASS_VIDEO_CONSOLE, &dev);
- if (!dev)
+ if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
return CMD_RET_FAILURE;
for (s = argv[1]; *s; s++)
vidconsole_put_char(dev, *s);
diff --git a/lib/tpm.c b/lib/tpm.c
index f428d45..88f2406 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -242,7 +242,7 @@ static uint32_t tpm_sendrecv_command(const void *command,
response_length = sizeof(response_buffer);
}
- ret = uclass_first_device(UCLASS_TPM, &dev);
+ ret = uclass_first_device_err(UCLASS_TPM, &dev);
if (ret)
return ret;
err = tpm_xfer(dev, command, tpm_command_size(command),
@@ -261,8 +261,8 @@ int tpm_init(void)
int err;
struct udevice *dev;
- err = uclass_first_device(UCLASS_TPM, &dev);
- if (err || !dev)
+ err = uclass_first_device_err(UCLASS_TPM, &dev);
+ if (err)
return err;
return tpm_open(dev);
}
--
2.7.0.rc3.207.g0ac5344
More information about the U-Boot
mailing list