Commit 0f288605 authored by Tom Gundersen's avatar Tom Gundersen Committed by Sean Paul

drm: Don't swallow error codes in drm_dev_alloc()

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: default avatarTom Gundersen <teg@jklm.no>
Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20160921145919.13754-2-teg@jklm.no
parent c6bf811a
...@@ -198,8 +198,8 @@ static int arcpgu_probe(struct platform_device *pdev) ...@@ -198,8 +198,8 @@ static int arcpgu_probe(struct platform_device *pdev)
int ret; int ret;
drm = drm_dev_alloc(&arcpgu_drm_driver, &pdev->dev); drm = drm_dev_alloc(&arcpgu_drm_driver, &pdev->dev);
if (!drm) if (IS_ERR(drm))
return -ENOMEM; return PTR_ERR(drm);
ret = arcpgu_load(drm); ret = arcpgu_load(drm);
if (ret) if (ret)
......
...@@ -326,8 +326,8 @@ static int hdlcd_drm_bind(struct device *dev) ...@@ -326,8 +326,8 @@ static int hdlcd_drm_bind(struct device *dev)
return -ENOMEM; return -ENOMEM;
drm = drm_dev_alloc(&hdlcd_driver, dev); drm = drm_dev_alloc(&hdlcd_driver, dev);
if (!drm) if (IS_ERR(drm))
return -ENOMEM; return PTR_ERR(drm);
drm->dev_private = hdlcd; drm->dev_private = hdlcd;
dev_set_drvdata(dev, drm); dev_set_drvdata(dev, drm);
......
...@@ -311,8 +311,8 @@ static int malidp_bind(struct device *dev) ...@@ -311,8 +311,8 @@ static int malidp_bind(struct device *dev)
return ret; return ret;
drm = drm_dev_alloc(&malidp_driver, dev); drm = drm_dev_alloc(&malidp_driver, dev);
if (!drm) { if (IS_ERR(drm)) {
ret = -ENOMEM; ret = PTR_ERR(drm);
goto alloc_fail; goto alloc_fail;
} }
......
...@@ -797,8 +797,8 @@ static int atmel_hlcdc_dc_drm_probe(struct platform_device *pdev) ...@@ -797,8 +797,8 @@ static int atmel_hlcdc_dc_drm_probe(struct platform_device *pdev)
int ret; int ret;
ddev = drm_dev_alloc(&atmel_hlcdc_dc_driver, &pdev->dev); ddev = drm_dev_alloc(&atmel_hlcdc_dc_driver, &pdev->dev);
if (!ddev) if (IS_ERR(ddev))
return -ENOMEM; return PTR_ERR(ddev);
ret = atmel_hlcdc_dc_load(ddev); ret = atmel_hlcdc_dc_load(ddev);
if (ret) if (ret)
......
...@@ -591,7 +591,7 @@ EXPORT_SYMBOL(drm_dev_init); ...@@ -591,7 +591,7 @@ EXPORT_SYMBOL(drm_dev_init);
* own struct should look at using drm_dev_init() instead. * own struct should look at using drm_dev_init() instead.
* *
* RETURNS: * 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 drm_device *drm_dev_alloc(struct drm_driver *driver,
struct device *parent) struct device *parent)
...@@ -601,12 +601,12 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver, ...@@ -601,12 +601,12 @@ struct drm_device *drm_dev_alloc(struct drm_driver *driver,
dev = kzalloc(sizeof(*dev), GFP_KERNEL); dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) if (!dev)
return NULL; return ERR_PTR(-ENOMEM);
ret = drm_dev_init(dev, driver, parent); ret = drm_dev_init(dev, driver, parent);
if (ret) { if (ret) {
kfree(dev); kfree(dev);
return NULL; return ERR_PTR(ret);
} }
return dev; return dev;
......
...@@ -236,8 +236,8 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent, ...@@ -236,8 +236,8 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
DRM_DEBUG("\n"); DRM_DEBUG("\n");
dev = drm_dev_alloc(driver, &pdev->dev); dev = drm_dev_alloc(driver, &pdev->dev);
if (!dev) if (IS_ERR(dev))
return -ENOMEM; return PTR_ERR(dev);
ret = pci_enable_device(pdev); ret = pci_enable_device(pdev);
if (ret) if (ret)
......
...@@ -48,8 +48,8 @@ static int drm_get_platform_dev(struct platform_device *platdev, ...@@ -48,8 +48,8 @@ static int drm_get_platform_dev(struct platform_device *platdev,
DRM_DEBUG("\n"); DRM_DEBUG("\n");
dev = drm_dev_alloc(driver, &platdev->dev); dev = drm_dev_alloc(driver, &platdev->dev);
if (!dev) if (IS_ERR(dev))
return -ENOMEM; return PTR_ERR(dev);
dev->platformdev = platdev; dev->platformdev = platdev;
......
...@@ -529,8 +529,8 @@ static int etnaviv_bind(struct device *dev) ...@@ -529,8 +529,8 @@ static int etnaviv_bind(struct device *dev)
int ret; int ret;
drm = drm_dev_alloc(&etnaviv_drm_driver, dev); drm = drm_dev_alloc(&etnaviv_drm_driver, dev);
if (!drm) if (IS_ERR(drm))
return -ENOMEM; return PTR_ERR(drm);
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
......
...@@ -402,8 +402,8 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev) ...@@ -402,8 +402,8 @@ static int fsl_dcu_drm_probe(struct platform_device *pdev)
fsl_dev->tcon = fsl_tcon_init(dev); fsl_dev->tcon = fsl_tcon_init(dev);
drm = drm_dev_alloc(driver, dev); drm = drm_dev_alloc(driver, dev);
if (!drm) { if (IS_ERR(drm)) {
ret = -ENOMEM; ret = PTR_ERR(drm);
goto disable_pix_clk; goto disable_pix_clk;
} }
......
...@@ -207,8 +207,8 @@ static int kirin_drm_bind(struct device *dev) ...@@ -207,8 +207,8 @@ static int kirin_drm_bind(struct device *dev)
int ret; int ret;
drm_dev = drm_dev_alloc(driver, dev); drm_dev = drm_dev_alloc(driver, dev);
if (!drm_dev) if (IS_ERR(drm_dev))
return -ENOMEM; return PTR_ERR(drm_dev);
drm_dev->platformdev = to_platform_device(dev); drm_dev->platformdev = to_platform_device(dev);
......
...@@ -294,8 +294,8 @@ static int mtk_drm_bind(struct device *dev) ...@@ -294,8 +294,8 @@ static int mtk_drm_bind(struct device *dev)
int ret; int ret;
drm = drm_dev_alloc(&mtk_drm_driver, dev); drm = drm_dev_alloc(&mtk_drm_driver, dev);
if (!drm) if (IS_ERR(drm))
return -ENOMEM; return PTR_ERR(drm);
drm->dev_private = private; drm->dev_private = private;
private->drm = drm; private->drm = drm;
......
...@@ -347,9 +347,9 @@ static int msm_drm_init(struct device *dev, struct drm_driver *drv) ...@@ -347,9 +347,9 @@ static int msm_drm_init(struct device *dev, struct drm_driver *drv)
int ret; int ret;
ddev = drm_dev_alloc(drv, dev); ddev = drm_dev_alloc(drv, dev);
if (!ddev) { if (IS_ERR(ddev)) {
dev_err(dev, "failed to allocate drm_device\n"); dev_err(dev, "failed to allocate drm_device\n");
return -ENOMEM; return PTR_ERR(ddev);
} }
platform_set_drvdata(pdev, ddev); platform_set_drvdata(pdev, ddev);
......
...@@ -1067,8 +1067,8 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func, ...@@ -1067,8 +1067,8 @@ nouveau_platform_device_create(const struct nvkm_device_tegra_func *func,
goto err_free; goto err_free;
drm = drm_dev_alloc(&driver_platform, &pdev->dev); drm = drm_dev_alloc(&driver_platform, &pdev->dev);
if (!drm) { if (IS_ERR(drm)) {
err = -ENOMEM; err = PTR_ERR(drm);
goto err_free; goto err_free;
} }
......
...@@ -316,8 +316,8 @@ static int rcar_du_probe(struct platform_device *pdev) ...@@ -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; rcdu->info = of_match_device(rcar_du_of_table, rcdu->dev)->data;
ddev = drm_dev_alloc(&rcar_du_driver, &pdev->dev); ddev = drm_dev_alloc(&rcar_du_driver, &pdev->dev);
if (!ddev) if (IS_ERR(ddev))
return -ENOMEM; return PTR_ERR(ddev);
rcdu->ddev = ddev; rcdu->ddev = ddev;
ddev->dev_private = rcdu; ddev->dev_private = rcdu;
......
...@@ -143,8 +143,8 @@ static int rockchip_drm_bind(struct device *dev) ...@@ -143,8 +143,8 @@ static int rockchip_drm_bind(struct device *dev)
int ret; int ret;
drm_dev = drm_dev_alloc(&rockchip_drm_driver, dev); drm_dev = drm_dev_alloc(&rockchip_drm_driver, dev);
if (!drm_dev) if (IS_ERR(drm_dev))
return -ENOMEM; return PTR_ERR(drm_dev);
dev_set_drvdata(dev, drm_dev); dev_set_drvdata(dev, drm_dev);
......
...@@ -365,8 +365,8 @@ static int sti_bind(struct device *dev) ...@@ -365,8 +365,8 @@ static int sti_bind(struct device *dev)
int ret; int ret;
ddev = drm_dev_alloc(&sti_driver, dev); ddev = drm_dev_alloc(&sti_driver, dev);
if (!ddev) if (IS_ERR(ddev))
return -ENOMEM; return PTR_ERR(ddev);
ddev->platformdev = to_platform_device(dev); ddev->platformdev = to_platform_device(dev);
......
...@@ -121,8 +121,8 @@ static int sun4i_drv_bind(struct device *dev) ...@@ -121,8 +121,8 @@ static int sun4i_drv_bind(struct device *dev)
int ret; int ret;
drm = drm_dev_alloc(&sun4i_drv_driver, dev); drm = drm_dev_alloc(&sun4i_drv_driver, dev);
if (!drm) if (IS_ERR(drm))
return -ENOMEM; return PTR_ERR(drm);
drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL);
if (!drv) { if (!drv) {
......
...@@ -983,8 +983,8 @@ static int host1x_drm_probe(struct host1x_device *dev) ...@@ -983,8 +983,8 @@ static int host1x_drm_probe(struct host1x_device *dev)
int err; int err;
drm = drm_dev_alloc(driver, &dev->dev); drm = drm_dev_alloc(driver, &dev->dev);
if (!drm) if (IS_ERR(drm))
return -ENOMEM; return PTR_ERR(drm);
dev_set_drvdata(&dev->dev, drm); dev_set_drvdata(&dev->dev, drm);
......
...@@ -86,8 +86,8 @@ static int udl_usb_probe(struct usb_interface *interface, ...@@ -86,8 +86,8 @@ static int udl_usb_probe(struct usb_interface *interface,
int r; int r;
dev = drm_dev_alloc(&driver, &interface->dev); dev = drm_dev_alloc(&driver, &interface->dev);
if (!dev) if (IS_ERR(dev))
return -ENOMEM; return PTR_ERR(dev);
r = drm_dev_register(dev, (unsigned long)udev); r = drm_dev_register(dev, (unsigned long)udev);
if (r) if (r)
......
...@@ -233,8 +233,8 @@ static int vc4_drm_bind(struct device *dev) ...@@ -233,8 +233,8 @@ static int vc4_drm_bind(struct device *dev)
return -ENOMEM; return -ENOMEM;
drm = drm_dev_alloc(&vc4_drm_driver, dev); drm = drm_dev_alloc(&vc4_drm_driver, dev);
if (!drm) if (IS_ERR(drm))
return -ENOMEM; return PTR_ERR(drm);
platform_set_drvdata(pdev, drm); platform_set_drvdata(pdev, drm);
vc4->dev = drm; vc4->dev = drm;
drm->dev_private = vc4; drm->dev_private = vc4;
......
...@@ -334,8 +334,8 @@ static int __init vgem_init(void) ...@@ -334,8 +334,8 @@ static int __init vgem_init(void)
int ret; int ret;
vgem_device = drm_dev_alloc(&vgem_driver, NULL); vgem_device = drm_dev_alloc(&vgem_driver, NULL);
if (!vgem_device) { if (IS_ERR(vgem_device)) {
ret = -ENOMEM; ret = PTR_ERR(vgem_device);
goto out; goto out;
} }
......
...@@ -54,8 +54,8 @@ int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev) ...@@ -54,8 +54,8 @@ int drm_virtio_init(struct drm_driver *driver, struct virtio_device *vdev)
int ret; int ret;
dev = drm_dev_alloc(driver, &vdev->dev); dev = drm_dev_alloc(driver, &vdev->dev);
if (!dev) if (IS_ERR(dev))
return -ENOMEM; return PTR_ERR(dev);
dev->virtdev = vdev; dev->virtdev = vdev;
vdev->priv = dev; vdev->priv = dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment