summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/mgag200
diff options
context:
space:
mode:
authorThomas Zimmermann <tzimmermann@suse.de>2020-06-05 15:58:01 +0200
committerThomas Zimmermann <tzimmermann@suse.de>2020-06-11 10:06:07 +0200
commit3c8923c3f15e1c7f84b804f218500febf46868a3 (patch)
tree6bea4f69f5f3968196bc14690ecf6daeb8d7c797 /drivers/gpu/drm/mgag200
parentc714dd941dd158500299b2138fcd06709afd2605 (diff)
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 <tzimmermann@suse.de> Acked-by: Sam Ravnborg <sam@ravnborg.org> Link: https://patchwork.freedesktop.org/patch/msgid/20200605135803.19811-13-tzimmermann@suse.de
Diffstat (limited to 'drivers/gpu/drm/mgag200')
-rw-r--r--drivers/gpu/drm/mgag200/mgag200_drv.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/drivers/gpu/drm/mgag200/mgag200_drv.c b/drivers/gpu/drm/mgag200/mgag200_drv.c
index 926437a27a22..592e484f87ee 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;
}