RE: [PATCH -next] usb: dwc2: Fix the error handling of dwc2_pci_probe()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Vardan,

> 
> We have patch doing the same in our internal branch, please review it
> below. We will send it out after internal review/testing process.
> 
> usb: dwc2: pci: Fix error handling in dwc2_pci_probe
> 
> Move usb_phy_generic_register() function call to the top, to simplify
> error handling.
> 
> Replace kzalloc() with devm_kzalloc().
> 
> After platform_device_add(), if we error out, we must do
> platform_device_unregister(), which also does the put. So lets move
> devm_kzalloc() to simplify error handling and avoid
> calling of platform_device_unregister().
> 
> Change-Id: Ic183ee233f5dc622e9e6126c1bfd4890baee1f76
> Signed-off-by: Vardan Mikayelyan <mvardan@xxxxxxxxxxxx>


Your patch is ok to me.


> 
> diff --git a/drivers/usb/dwc2/pci.c b/drivers/usb/dwc2/pci.c
> index fdeb8c7..7696131 100644
> --- a/drivers/usb/dwc2/pci.c
> +++ b/drivers/usb/dwc2/pci.c
> @@ -104,10 +104,17 @@ static int dwc2_pci_probe(struct pci_dev *pci,
> 
>          pci_set_master(pci);
> 
> +       phy = usb_phy_generic_register();
> +       if (IS_ERR(phy)) {
> +               dev_err(dev, "error registering generic PHY (%ld)\n",
> +                       PTR_ERR(phy));
> +               return PTR_ERR(phy);
> +       }
> +
>          dwc2 = platform_device_alloc("dwc2", PLATFORM_DEVID_AUTO);
>          if (!dwc2) {
>                  dev_err(dev, "couldn't allocate dwc2 device\n");
> -               return -ENOMEM;
> +               goto err;
>          }
> 
>          memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
> @@ -124,32 +131,25 @@ static int dwc2_pci_probe(struct pci_dev *pci,
>          ret = platform_device_add_resources(dwc2, res, ARRAY_SIZE(res));
>          if (ret) {
>                  dev_err(dev, "couldn't add resources to dwc2 device\n");
> -               return ret;
> +               goto err;
>          }
> 
>          dwc2->dev.parent = dev;
> 
> -       phy = usb_phy_generic_register();
> -       if (IS_ERR(phy)) {
> -               dev_err(dev, "error registering generic PHY (%ld)\n",
> -                       PTR_ERR(phy));
> -               return PTR_ERR(phy);
> -       }
> -
>          ret = dwc2_pci_quirks(pci, dwc2);
>          if (ret)
>                  goto err;
> 
> +       glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
> +       if (!glue)
> +               goto err;
> +
>          ret = platform_device_add(dwc2);
>          if (ret) {
>                  dev_err(dev, "failed to register dwc2 device\n");
>                  goto err;
>          }
> 
> -       glue = kzalloc(sizeof(*glue), GFP_KERNEL);
> -       if (!glue)
> -               return -ENOMEM;
> -
>          glue->phy = phy;
> 
> 
> Thanks,
> Vardan.
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux