Re: [PATCH v6 10/20] dm: treewide: Use uclass_first_device_err when accessing one device

2022-10-17 Thread Simon Glass
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 
Reviewed-by: Simon Glass 
---
v6: drop errno_str
---
 arch/arm/mach-omap2/am33xx/board.c|  4 ++--
 arch/x86/cpu/broadwell/cpu.c  |  4 +---
 arch/x86/cpu/intel_common/cpu.c   |  4 +---
 arch/x86/lib/pinctrl_ich6.c   |  4 +---
 board/intel/cougarcanyon2/cougarcanyon2.c |  4 +---
 drivers/mmc/omap_hsmmc.c  |  2 +-
 drivers/serial/serial-uclass.c|  2 +-
 drivers/serial/serial_bcm283x_mu.c|  2 +-
 drivers/serial/serial_bcm283x_pl011.c |  2 +-
 drivers/sysreset/sysreset_ast.c   |  2 +-
 drivers/video/exynos/exynos_fb.c  | 14 +++---
 drivers/video/mali_dp.c   |  2 +-
 drivers/video/stm32/stm32_dsi.c   |  2 +-
 drivers/video/tegra124/dp.c   |  4 ++--
 lib/acpi/acpi_table.c |  2 +-
 lib/efi_loader/efi_gop.c  |  2 +-
 net/eth-uclass.c  |  4 ++--
 test/boot/bootmeth.c  |  2 +-
 test/dm/acpi.c| 14 +++---
 test/dm/devres.c  |  4 ++--
 test/dm/i2c.c |  8 
 test/dm/virtio_device.c   |  8 
 test/dm/virtio_rng.c  |  2 +-
 test/fuzz/cmd_fuzz.c  |  2 +-
 test/fuzz/virtio.c|  2 +-
 25 files changed, 43 insertions(+), 59 deletions(-)

Applied to u-boot-dm, thanks!


[PATCH v6 10/20] dm: treewide: Use uclass_first_device_err when accessing one device

2022-10-12 Thread Michal Suchanek
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 
Reviewed-by: Simon Glass 
---
v6: drop errno_str
---
 arch/arm/mach-omap2/am33xx/board.c|  4 ++--
 arch/x86/cpu/broadwell/cpu.c  |  4 +---
 arch/x86/cpu/intel_common/cpu.c   |  4 +---
 arch/x86/lib/pinctrl_ich6.c   |  4 +---
 board/intel/cougarcanyon2/cougarcanyon2.c |  4 +---
 drivers/mmc/omap_hsmmc.c  |  2 +-
 drivers/serial/serial-uclass.c|  2 +-
 drivers/serial/serial_bcm283x_mu.c|  2 +-
 drivers/serial/serial_bcm283x_pl011.c |  2 +-
 drivers/sysreset/sysreset_ast.c   |  2 +-
 drivers/video/exynos/exynos_fb.c  | 14 +++---
 drivers/video/mali_dp.c   |  2 +-
 drivers/video/stm32/stm32_dsi.c   |  2 +-
 drivers/video/tegra124/dp.c   |  4 ++--
 lib/acpi/acpi_table.c |  2 +-
 lib/efi_loader/efi_gop.c  |  2 +-
 net/eth-uclass.c  |  4 ++--
 test/boot/bootmeth.c  |  2 +-
 test/dm/acpi.c| 14 +++---
 test/dm/devres.c  |  4 ++--
 test/dm/i2c.c |  8 
 test/dm/virtio_device.c   |  8 
 test/dm/virtio_rng.c  |  2 +-
 test/fuzz/cmd_fuzz.c  |  2 +-
 test/fuzz/virtio.c|  2 +-
 25 files changed, 43 insertions(+), 59 deletions(-)

diff --git a/arch/arm/mach-omap2/am33xx/board.c 
b/arch/arm/mach-omap2/am33xx/board.c
index 7f1b84e466..f393ff9144 100644
--- a/arch/arm/mach-omap2/am33xx/board.c
+++ b/arch/arm/mach-omap2/am33xx/board.c
@@ -265,8 +265,8 @@ int arch_misc_init(void)
struct udevice *dev;
int ret;
 
-   ret = uclass_first_device(UCLASS_MISC, );
-   if (ret || !dev)
+   ret = uclass_first_device_err(UCLASS_MISC, );
+   if (ret)
return ret;
 
 #if defined(CONFIG_DM_ETH) && defined(CONFIG_USB_ETHER)
diff --git a/arch/x86/cpu/broadwell/cpu.c b/arch/x86/cpu/broadwell/cpu.c
index 2adcf4b242..7877961451 100644
--- a/arch/x86/cpu/broadwell/cpu.c
+++ b/arch/x86/cpu/broadwell/cpu.c
@@ -31,11 +31,9 @@ static int broadwell_init_cpu(void *ctx, struct event *event)
int ret;
 
/* Start up the LPC so we have serial */
-   ret = uclass_first_device(UCLASS_LPC, );
+   ret = uclass_first_device_err(UCLASS_LPC, );
if (ret)
return ret;
-   if (!dev)
-   return -ENODEV;
ret = cpu_set_flex_ratio_to_tdp_nominal();
if (ret)
return ret;
diff --git a/arch/x86/cpu/intel_common/cpu.c b/arch/x86/cpu/intel_common/cpu.c
index 96d05e2eb3..8f489e6c65 100644
--- a/arch/x86/cpu/intel_common/cpu.c
+++ b/arch/x86/cpu/intel_common/cpu.c
@@ -61,11 +61,9 @@ int cpu_common_init(void)
/* Early chipset init required before RAM init can work */
uclass_first_device(UCLASS_NORTHBRIDGE, );
 
-   ret = uclass_first_device(UCLASS_LPC, );
+   ret = uclass_first_device_err(UCLASS_LPC, );
if (ret)
return ret;
-   if (!lpc)
-   return -ENODEV;
 
/* Cause the SATA device to do its early init */
uclass_first_device(UCLASS_AHCI, );
diff --git a/arch/x86/lib/pinctrl_ich6.c b/arch/x86/lib/pinctrl_ich6.c
index fd5e311b29..c93f245845 100644
--- a/arch/x86/lib/pinctrl_ich6.c
+++ b/arch/x86/lib/pinctrl_ich6.c
@@ -160,11 +160,9 @@ static int ich6_pinctrl_probe(struct udevice *dev)
u32 iobase = -1;
 
debug("%s: start\n", __func__);
-   ret = uclass_first_device(UCLASS_PCH, );
+   ret = uclass_first_device_err(UCLASS_PCH, );
if (ret)
return ret;
-   if (!pch)
-   return -ENODEV;
 
/*
 * Get the memory/io base address to configure every pins.
diff --git a/board/intel/cougarcanyon2/cougarcanyon2.c 
b/board/intel/cougarcanyon2/cougarcanyon2.c
index ce11eae59d..7f61ef8b36 100644
--- a/board/intel/cougarcanyon2/cougarcanyon2.c
+++ b/board/intel/cougarcanyon2/cougarcanyon2.c
@@ -21,11 +21,9 @@ int board_early_init_f(void)
struct udevice *pch;
int ret;
 
-   ret = uclass_first_device(UCLASS_PCH, );
+   ret = uclass_first_device_err(UCLASS_PCH, );
if (ret)
return ret;
-   if (!pch)
-   return -ENODEV;
 
/* Initialize LPC interface to turn