[U-Boot] [PATCH v2 2/9] dm: usb: Make usb_get_bus easier to use for callers
Simon Glass
sjg at chromium.org
Sun May 3 18:59:47 CEST 2015
On 1 May 2015 at 04:04, Hans de Goede <hdegoede at redhat.com> wrote:
> Make usb_get_bus easier to use for callers, by directly returning the bus
> rather then returning it via a pass-by-ref argument.
>
> This also removes the error checking from the single current caller, as
> we alreayd have an assert() for bus not being NULL in usb_get_bus().
>
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
> drivers/usb/host/usb-uclass.c | 11 +++--------
> include/usb.h | 7 +++----
> 2 files changed, 6 insertions(+), 12 deletions(-)
>
Acked-by: Simon Glass <sjg at chromium.org>
> diff --git a/drivers/usb/host/usb-uclass.c b/drivers/usb/host/usb-uclass.c
> index 95e371d..9f690dc 100644
> --- a/drivers/usb/host/usb-uclass.c
> +++ b/drivers/usb/host/usb-uclass.c
> @@ -477,9 +477,7 @@ int usb_scan_device(struct udevice *parent, int port,
>
> *devp = NULL;
> memset(udev, '\0', sizeof(*udev));
> - ret = usb_get_bus(parent, &udev->controller_dev);
> - if (ret)
> - return ret;
> + udev->controller_dev = usb_get_bus(parent);
> priv = dev_get_uclass_priv(udev->controller_dev);
>
> /*
> @@ -574,22 +572,19 @@ int usb_child_post_bind(struct udevice *dev)
> return 0;
> }
>
> -int usb_get_bus(struct udevice *dev, struct udevice **busp)
> +struct udevice *usb_get_bus(struct udevice *dev)
> {
> struct udevice *bus;
>
> - *busp = NULL;
> for (bus = dev; bus && device_get_uclass_id(bus) != UCLASS_USB; )
> bus = bus->parent;
> if (!bus) {
> /* By design this cannot happen */
> assert(bus);
> debug("USB HUB '%s' does not have a controller\n", dev->name);
> - return -EXDEV;
> }
> - *busp = bus;
>
> - return 0;
> + return bus;
> }
>
> int usb_child_pre_probe(struct udevice *dev)
> diff --git a/include/usb.h b/include/usb.h
> index 1b667ff..d8bde1d 100644
> --- a/include/usb.h
> +++ b/include/usb.h
> @@ -739,11 +739,10 @@ int usb_scan_device(struct udevice *parent, int port,
> * will be a device with uclass UCLASS_USB.
> *
> * @dev: Device to check
> - * @busp: Returns bus, or NULL if not found
> - * @return 0 if OK, -EXDEV is somehow this bus does not have a controller (this
> - * indicates a critical error in the USB stack
> + * @return The bus, or NULL if not found (this indicates a critical error in
> + * the USB stack
) here
> */
> -int usb_get_bus(struct udevice *dev, struct udevice **busp);
> +struct udevice *usb_get_bus(struct udevice *dev);
>
> /**
> * usb_select_config() - Set up a device ready for use
> --
> 2.3.6
>
More information about the U-Boot
mailing list