]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
usb: ether: Fix error handling in usb_ether_init
authorMichal Suchanek <msuchanek@suse.de>
Wed, 12 Oct 2022 19:57:54 +0000 (21:57 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 18 Oct 2022 03:17:12 +0000 (21:17 -0600)
The code checks the return value from uclass_first_device as well as
that the device exists but it passes on the return value which may be
zero if there are no gadget devices. Just check that a device was
returned and return -ENODEV otherwise.

Also remove the dev variable which is not really used for anything.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/usb/gadget/ether.c

index 6ce389de9f0cae4e7dc6ceb05b127ffbc55b5160..43aec7ffa7024b651fd82710cb12e70fa0e09ce6 100644 (file)
@@ -2636,18 +2636,17 @@ static const struct eth_ops usb_eth_ops = {
 
 int usb_ether_init(void)
 {
-       struct udevice *dev;
        struct udevice *usb_dev;
        int ret;
 
-       ret = uclass_first_device(UCLASS_USB_GADGET_GENERIC, &usb_dev);
-       if (!usb_dev || ret) {
+       uclass_first_device(UCLASS_USB_GADGET_GENERIC, &usb_dev);
+       if (!usb_dev) {
                pr_err("No USB device found\n");
-               return ret;
+               return -ENODEV;
        }
 
-       ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", &dev);
-       if (!dev || ret) {
+       ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", NULL);
+       if (ret) {
                pr_err("usb - not able to bind usb_ether device\n");
                return ret;
        }