From: Thomas Zimmermann Date: Fri, 5 Jun 2020 13:58:01 +0000 (+0200) Subject: drm/mgag200: Allocate device structures in mgag200_driver_load() X-Git-Tag: v5.10.7~1332^2~33^2~547 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3c8923c3f15e1c7f84b804f218500febf46868a3;p=platform%2Fkernel%2Flinux-rpi.git drm/mgag200: Allocate device structures in mgag200_driver_load() Instances of struct drm_device and struct mga_device are now allocated next to each other in mgag200_driver_load(). Yet another preparation before embedding the DRM device instance in struct mga_device. Signed-off-by: Thomas Zimmermann Acked-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/20200605135803.19811-13-tzimmermann@suse.de --- diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c index 926437a..592e484f 100644 --- a/drivers/gpu/drm/mgag200/mgag200_drv.c +++ b/drivers/gpu/drm/mgag200/mgag200_drv.c @@ -88,26 +88,36 @@ static int mgag200_device_init(struct mga_device *mdev, unsigned long flags) return 0; } -static int mgag200_driver_load(struct drm_device *dev, unsigned long flags) +static struct mga_device * +mgag200_driver_load(struct pci_dev *pdev, unsigned long flags) { + struct drm_device *dev; struct mga_device *mdev; int ret; + dev = drm_dev_alloc(&mgag200_driver, &pdev->dev); + if (IS_ERR(dev)) + return ERR_CAST(dev); + + dev->pdev = pdev; + pci_set_drvdata(pdev, dev); + mdev = devm_kzalloc(dev->dev, sizeof(struct mga_device), GFP_KERNEL); if (mdev == NULL) - return -ENOMEM; + return ERR_PTR(-ENOMEM); dev->dev_private = (void *)mdev; mdev->dev = dev; ret = mgag200_device_init(mdev, flags); if (ret) - goto err_mm; + goto err_drm_dev_put; - return 0; + return mdev; -err_mm: +err_drm_dev_put: + drm_dev_put(dev); dev->dev_private = NULL; - return ret; + return ERR_PTR(ret); } static void mgag200_driver_unload(struct drm_device *dev) @@ -141,6 +151,7 @@ MODULE_DEVICE_TABLE(pci, mgag200_pciidlist); static int mgag200_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) { + struct mga_device *mdev; struct drm_device *dev; int ret; @@ -150,16 +161,10 @@ mgag200_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (ret) return ret; - dev = drm_dev_alloc(&mgag200_driver, &pdev->dev); - if (IS_ERR(dev)) - return PTR_ERR(dev); - - dev->pdev = pdev; - pci_set_drvdata(pdev, dev); - - ret = mgag200_driver_load(dev, ent->driver_data); - if (ret) - goto err_drm_dev_put; + mdev = mgag200_driver_load(pdev, ent->driver_data); + if (IS_ERR(mdev)) + return PTR_ERR(mdev); + dev = mdev->dev; ret = drm_dev_register(dev, ent->driver_data); if (ret) @@ -171,7 +176,6 @@ mgag200_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_mgag200_driver_unload: mgag200_driver_unload(dev); -err_drm_dev_put: drm_dev_put(dev); return ret; }