[PATCH 2/2] drm: Don't swallow error codes in drm_dev_alloc()

Tom Gundersen teg at jklm.no
Thu Sep 22 10:17:12 UTC 2016


On Thu, Sep 22, 2016 at 11:47 AM, Eric Engestrom
<eric.engestrom at imgtec.com> wrote:
> On Wed, Sep 21, 2016 at 04:59:19PM +0200, Tom Gundersen wrote:
>> There are many reasons other than ENOMEM that drm_dev_init() can
>> fail. Return ERR_PTR rather than NULL to be able to distinguish
>> these in the caller.
>>
>> Signed-off-by: Tom Gundersen <teg at jklm.no>
>
> Looks good to me :)
> Assuming you fixed all the drm_dev_alloc() calls, which a quick grep
> seems to confirm, this series is:
> Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>

Thanks.

> BTW, this looks like a task for coccinelle; is that what you used?
> If so, you could include your .cocci patch in the commit msg?

Probably could have used coccinelle, though I just did git grep and
fixed it up manually.

Cheers,

Tom

> Cheers,
>   Eric
>
>> ---
>>  drivers/gpu/drm/arc/arcpgu_drv.c                | 4 ++--
>>  drivers/gpu/drm/arm/hdlcd_drv.c                 | 4 ++--
>>  drivers/gpu/drm/arm/malidp_drv.c                | 4 ++--
>>  drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c    | 4 ++--
>>  drivers/gpu/drm/drm_drv.c                       | 6 +++---
>>  drivers/gpu/drm/drm_pci.c                       | 4 ++--
>>  drivers/gpu/drm/drm_platform.c                  | 4 ++--
>>  drivers/gpu/drm/etnaviv/etnaviv_drv.c           | 4 ++--
>>  drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c       | 4 ++--
>>  drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c | 4 ++--
>>  drivers/gpu/drm/mediatek/mtk_drm_drv.c          | 4 ++--
>>  drivers/gpu/drm/msm/msm_drv.c                   | 4 ++--
>>  drivers/gpu/drm/nouveau/nouveau_drm.c           | 4 ++--
>>  drivers/gpu/drm/rcar-du/rcar_du_drv.c           | 4 ++--
>>  drivers/gpu/drm/rockchip/rockchip_drm_drv.c     | 4 ++--
>>  drivers/gpu/drm/sti/sti_drv.c                   | 4 ++--
>>  drivers/gpu/drm/sun4i/sun4i_drv.c               | 4 ++--
>>  drivers/gpu/drm/tegra/drm.c                     | 4 ++--
>>  drivers/gpu/drm/udl/udl_drv.c                   | 4 ++--
>>  drivers/gpu/drm/vc4/vc4_drv.c                   | 4 ++--
>>  drivers/gpu/drm/vgem/vgem_drv.c                 | 4 ++--
>>  drivers/gpu/drm/virtio/virtgpu_drm_bus.c        | 4 ++--
>>  22 files changed, 45 insertions(+), 45 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/arc/arcpgu_drv.c b/drivers/gpu/drm/arc/arcpgu_drv.c
>> index 6d4ff34..28e6471 100644
>> --- a/drivers/gpu/drm/arc/arcpgu_drv.c
>> +++ b/drivers/gpu/drm/arc/arcpgu_drv.c
>> @@ -198,8 +198,8 @@ static int arcpgu_probe(struct platform_device *pdev)
>>       int ret;
>>
>>       drm = drm_dev_alloc(&arcpgu_drm_driver, &pdev->dev);
>> -     if (!drm)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm))
>> +             return PTR_ERR(drm);
>>
>>       ret = arcpgu_load(drm);
>>       if (ret)
>> diff --git a/drivers/gpu/drm/arm/hdlcd_drv.c b/drivers/gpu/drm/arm/hdlcd_drv.c
>> index d83b46a..fb6a418 100644
>> --- a/drivers/gpu/drm/arm/hdlcd_drv.c
>> +++ b/drivers/gpu/drm/arm/hdlcd_drv.c
>> @@ -326,8 +326,8 @@ static int hdlcd_drm_bind(struct device *dev)
>>               return -ENOMEM;
>>
>>       drm = drm_dev_alloc(&hdlcd_driver, dev);
>> -     if (!drm)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm))
>> +             return PTR_ERR(drm);
>>
>>       drm->dev_private = hdlcd;
>>       dev_set_drvdata(dev, drm);
>> diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
>> index c383d72..9280358 100644
>> --- a/drivers/gpu/drm/arm/malidp_drv.c
>> +++ b/drivers/gpu/drm/arm/malidp_drv.c
>> @@ -311,8 +311,8 @@ static int malidp_bind(struct device *dev)
>>               return ret;
>>
>>       drm = drm_dev_alloc(&malidp_driver, dev);
>> -     if (!drm) {
>> -             ret = -ENOMEM;
>> +     if (IS_ERR(drm)) {
>> +             ret = PTR_ERR(drm);
>>               goto alloc_fail;
>>       }
>>
>> diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
>> index 8e7483d..5f48431 100644
>> --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
>> +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_dc.c
>> @@ -797,8 +797,8 @@ static int atmel_hlcdc_dc_drm_probe(struct platform_device *pdev)
>>       int ret;
>>
>>       ddev = drm_dev_alloc(&atmel_hlcdc_dc_driver, &pdev->dev);
>> -     if (!ddev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(ddev))
>> +             return PTR_ERR(ddev);
>>
>>       ret = atmel_hlcdc_dc_load(ddev);
>>       if (ret)
>> diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
>> index 99e6751..80c7f25 100644
>> --- a/drivers/gpu/drm/drm_drv.c
>> +++ b/drivers/gpu/drm/drm_drv.c
>> @@ -591,7 +591,7 @@ EXPORT_SYMBOL(drm_dev_init);
>>   * own struct should look at using drm_dev_init() instead.
>>   *
>>   * RETURNS:
>> - * Pointer to new DRM device, or NULL if out of memory.
>> + * Pointer to new DRM device, or ERR_PTR on failure.
>>   */
>>  struct drm_device *drm_dev_alloc(struct drm_driver *driver,
>>                                struct device *parent)
>> @@ -601,12 +601,12 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
>>
>>       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
>>       if (!dev)
>> -             return NULL;
>> +             return ERR_PTR(-ENOMEM);
>>
>>       ret = drm_dev_init(dev, driver, parent);
>>       if (ret) {
>>               kfree(dev);
>> -             return NULL;
>> +             return ERR_PTR(ret);
>>       }
>>
>>       return dev;
>> diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
>> index d86362f..3ceea9c 100644
>> --- a/drivers/gpu/drm/drm_pci.c
>> +++ b/drivers/gpu/drm/drm_pci.c
>> @@ -236,8 +236,8 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
>>       DRM_DEBUG("\n");
>>
>>       dev = drm_dev_alloc(driver, &pdev->dev);
>> -     if (!dev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(dev))
>> +             return PTR_ERR(dev);
>>
>>       ret = pci_enable_device(pdev);
>>       if (ret)
>> diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
>> index 2c819ef..0262698 100644
>> --- a/drivers/gpu/drm/drm_platform.c
>> +++ b/drivers/gpu/drm/drm_platform.c
>> @@ -48,8 +48,8 @@ static int drm_get_platform_dev(struct platform_device *platdev,
>>       DRM_DEBUG("\n");
>>
>>       dev = drm_dev_alloc(driver, &platdev->dev);
>> -     if (!dev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(dev))
>> +             return PTR_ERR(dev);
>>
>>       dev->platformdev = platdev;
>>
>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_drv.c b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
>> index e3164d9..aa68766 100644
>> --- a/drivers/gpu/drm/etnaviv/etnaviv_drv.c
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_drv.c
>> @@ -529,8 +529,8 @@ static int etnaviv_bind(struct device *dev)
>>       int ret;
>>
>>       drm = drm_dev_alloc(&etnaviv_drm_driver, dev);
>> -     if (!drm)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm))
>> +             return PTR_ERR(drm);
>>
>>       priv = kzalloc(sizeof(*priv), GFP_KERNEL);
>>       if (!priv) {
>> diff --git a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
>> index 7882387..0d2ae94 100644
>> --- a/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
>> +++ b/drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_drv.c
>> @@ -402,8 +402,8 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev)
>>       fsl_dev->tcon = fsl_tcon_init(dev);
>>
>>       drm = drm_dev_alloc(driver, dev);
>> -     if (!drm) {
>> -             ret = -ENOMEM;
>> +     if (IS_ERR(drm)) {
>> +             ret = PTR_ERR(drm);
>>               goto disable_pix_clk;
>>       }
>>
>> diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
>> index 1fc2f50..90377a6 100644
>> --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
>> +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_drv.c
>> @@ -207,8 +207,8 @@ static int kirin_drm_bind(struct device *dev)
>>       int ret;
>>
>>       drm_dev = drm_dev_alloc(driver, dev);
>> -     if (!drm_dev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm_dev))
>> +             return PTR_ERR(drm_dev);
>>
>>       drm_dev->platformdev = to_platform_device(dev);
>>
>> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
>> index 72c1ae4..cf83f65 100644
>> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
>> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
>> @@ -294,8 +294,8 @@ static int mtk_drm_bind(struct device *dev)
>>       int ret;
>>
>>       drm = drm_dev_alloc(&mtk_drm_driver, dev);
>> -     if (!drm)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm))
>> +             return PTR_ERR(drm);
>>
>>       drm->dev_private = private;
>>       private->drm = drm;
>> diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c
>> index 8a02370..042bde4 100644
>> --- a/drivers/gpu/drm/msm/msm_drv.c
>> +++ b/drivers/gpu/drm/msm/msm_drv.c
>> @@ -347,9 +347,9 @@ static int msm_drm_init(struct device *dev, struct drm_driver *drv)
>>       int ret;
>>
>>       ddev = drm_dev_alloc(drv, dev);
>> -     if (!ddev) {
>> +     if (IS_ERR(ddev)) {
>>               dev_err(dev, "failed to allocate drm_device\n");
>> -             return -ENOMEM;
>> +             return PTR_ERR(ddev);
>>       }
>>
>>       platform_set_drvdata(pdev, ddev);
>> diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
>> index 652ab11..3100fd88 100644
>> --- a/drivers/gpu/drm/nouveau/nouveau_drm.c
>> +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
>> @@ -1067,8 +1067,8 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
>>               goto err_free;
>>
>>       drm = drm_dev_alloc(&driver_platform, &pdev->dev);
>> -     if (!drm) {
>> -             err = -ENOMEM;
>> +     if (IS_ERR(drm)) {
>> +             err = PTR_ERR(drm);
>>               goto err_free;
>>       }
>>
>> diff --git a/drivers/gpu/drm/rcar-du/rcar_du_drv.c b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> index 899ef7a..73c971e 100644
>> --- a/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> +++ b/drivers/gpu/drm/rcar-du/rcar_du_drv.c
>> @@ -316,8 +316,8 @@ static int rcar_du_probe(struct platform_device *pdev)
>>       rcdu->info = of_match_device(rcar_du_of_table, rcdu->dev)->data;
>>
>>       ddev = drm_dev_alloc(&rcar_du_driver, &pdev->dev);
>> -     if (!ddev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(ddev))
>> +             return PTR_ERR(ddev);
>>
>>       rcdu->ddev = ddev;
>>       ddev->dev_private = rcdu;
>> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
>> index 76eaf1d..446b5d7 100644
>> --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
>> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
>> @@ -143,8 +143,8 @@ static int rockchip_drm_bind(struct device *dev)
>>       int ret;
>>
>>       drm_dev = drm_dev_alloc(&rockchip_drm_driver, dev);
>> -     if (!drm_dev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm_dev))
>> +             return PTR_ERR(drm_dev);
>>
>>       dev_set_drvdata(dev, drm_dev);
>>
>> diff --git a/drivers/gpu/drm/sti/sti_drv.c b/drivers/gpu/drm/sti/sti_drv.c
>> index 7cd3804..49ed3c4 100644
>> --- a/drivers/gpu/drm/sti/sti_drv.c
>> +++ b/drivers/gpu/drm/sti/sti_drv.c
>> @@ -365,8 +365,8 @@ static int sti_bind(struct device *dev)
>>       int ret;
>>
>>       ddev = drm_dev_alloc(&sti_driver, dev);
>> -     if (!ddev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(ddev))
>> +             return PTR_ERR(ddev);
>>
>>       ddev->platformdev = to_platform_device(dev);
>>
>> diff --git a/drivers/gpu/drm/sun4i/sun4i_drv.c b/drivers/gpu/drm/sun4i/sun4i_drv.c
>> index 9059e3e..0da9862 100644
>> --- a/drivers/gpu/drm/sun4i/sun4i_drv.c
>> +++ b/drivers/gpu/drm/sun4i/sun4i_drv.c
>> @@ -121,8 +121,8 @@ static int sun4i_drv_bind(struct device *dev)
>>       int ret;
>>
>>       drm = drm_dev_alloc(&sun4i_drv_driver, dev);
>> -     if (!drm)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm))
>> +             return PTR_ERR(drm);
>>
>>       drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL);
>>       if (!drv) {
>> diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c
>> index 4b9f1c7..8ab47b5 100644
>> --- a/drivers/gpu/drm/tegra/drm.c
>> +++ b/drivers/gpu/drm/tegra/drm.c
>> @@ -983,8 +983,8 @@ static int host1x_drm_probe(struct host1x_device *dev)
>>       int err;
>>
>>       drm = drm_dev_alloc(driver, &dev->dev);
>> -     if (!drm)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm))
>> +             return PTR_ERR(drm);
>>
>>       dev_set_drvdata(&dev->dev, drm);
>>
>> diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c
>> index f0851db..cc45d98 100644
>> --- a/drivers/gpu/drm/udl/udl_drv.c
>> +++ b/drivers/gpu/drm/udl/udl_drv.c
>> @@ -86,8 +86,8 @@ static int udl_usb_probe(struct usb_interface *interface,
>>       int r;
>>
>>       dev = drm_dev_alloc(&driver, &interface->dev);
>> -     if (!dev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(dev))
>> +             return PTR_ERR(dev);
>>
>>       r = drm_dev_register(dev, (unsigned long)udev);
>>       if (r)
>> diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
>> index deec535..3c9e7f6 100644
>> --- a/drivers/gpu/drm/vc4/vc4_drv.c
>> +++ b/drivers/gpu/drm/vc4/vc4_drv.c
>> @@ -233,8 +233,8 @@ static int vc4_drm_bind(struct device *dev)
>>               return -ENOMEM;
>>
>>       drm = drm_dev_alloc(&vc4_drm_driver, dev);
>> -     if (!drm)
>> -             return -ENOMEM;
>> +     if (IS_ERR(drm))
>> +             return PTR_ERR(drm);
>>       platform_set_drvdata(pdev, drm);
>>       vc4->dev = drm;
>>       drm->dev_private = vc4;
>> diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
>> index c15bafb..f36c147 100644
>> --- a/drivers/gpu/drm/vgem/vgem_drv.c
>> +++ b/drivers/gpu/drm/vgem/vgem_drv.c
>> @@ -334,8 +334,8 @@ static int __init vgem_init(void)
>>       int ret;
>>
>>       vgem_device = drm_dev_alloc(&vgem_driver, NULL);
>> -     if (!vgem_device) {
>> -             ret = -ENOMEM;
>> +     if (IS_ERR(vgem_device)) {
>> +             ret = PTR_ERR(vgem_device);
>>               goto out;
>>       }
>>
>> diff --git a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
>> index a59d0e3..26197dd 100644
>> --- a/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
>> +++ b/drivers/gpu/drm/virtio/virtgpu_drm_bus.c
>> @@ -54,8 +54,8 @@ int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
>>       int ret;
>>
>>       dev = drm_dev_alloc(driver, &vdev->dev);
>> -     if (!dev)
>> -             return -ENOMEM;
>> +     if (IS_ERR(dev))
>> +             return PTR_ERR(dev);
>>       dev->virtdev = vdev;
>>       vdev->priv = dev;
>>
>> --
>> 2.9.3


More information about the dri-devel mailing list