summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-10-02 11:23:37 +0200
committerDave Airlie <airlied@redhat.com>2013-10-09 07:55:09 +0200
commit0dc8fe5985e01f238e7dc64ff1733cc0291811e8 (patch)
tree977b912c062fee10c10e39082546a5ecacd39792 /drivers
parentdrm: move drm_lastclose() to drm_fops.c (diff)
downloadlinux-0dc8fe5985e01f238e7dc64ff1733cc0291811e8.tar.xz
linux-0dc8fe5985e01f238e7dc64ff1733cc0291811e8.zip
drm: introduce drm_dev_free() to fix error paths
The error paths in DRM bus drivers currently leak memory as they don't correctly revert drm_dev_alloc(). Introduce drm_dev_free() to free DRM devices which haven't been registered, yet. We must be careful not to introduce any side-effects with cleanups done in drm_dev_free(). drm_ht_remove(), drm_ctxbitmap_cleanup() and drm_gem_destroy() are all fine in that regard. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/drm/drm_pci.c2
-rw-r--r--drivers/gpu/drm/drm_platform.c2
-rw-r--r--drivers/gpu/drm/drm_stub.c35
-rw-r--r--drivers/gpu/drm/drm_usb.c2
4 files changed, 28 insertions, 13 deletions
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index 743589dc47ce..cabe2bd702ae 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -354,7 +354,7 @@ int drm_get_pci_dev(struct pci_dev *pdev, const struct pci_device_id *ent,
err_pci:
pci_disable_device(pdev);
err_free:
- kfree(dev);
+ drm_dev_free(dev);
return ret;
}
EXPORT_SYMBOL(drm_get_pci_dev);
diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
index a0f91f85651f..fc24fee8ec83 100644
--- a/drivers/gpu/drm/drm_platform.c
+++ b/drivers/gpu/drm/drm_platform.c
@@ -64,7 +64,7 @@ static int drm_get_platform_dev(struct platform_device *platdev,
return 0;
err_free:
- kfree(dev);
+ drm_dev_free(dev);
return ret;
}
diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
index 432994aafc3b..3b5b07482de8 100644
--- a/drivers/gpu/drm/drm_stub.c
+++ b/drivers/gpu/drm/drm_stub.c
@@ -363,7 +363,6 @@ static void drm_unplug_minor(struct drm_minor *minor)
*/
void drm_put_dev(struct drm_device *dev)
{
- struct drm_driver *driver;
struct drm_map_list *r_list, *list_temp;
DRM_DEBUG("\n");
@@ -372,7 +371,6 @@ void drm_put_dev(struct drm_device *dev)
DRM_ERROR("cleanup called no dev\n");
return;
}
- driver = dev->driver;
drm_lastclose(dev);
@@ -386,9 +384,6 @@ void drm_put_dev(struct drm_device *dev)
list_for_each_entry_safe(r_list, list_temp, &dev->maplist, head)
drm_rmmap(dev, r_list->map);
- drm_ht_remove(&dev->map_hash);
-
- drm_ctxbitmap_cleanup(dev);
if (drm_core_check_feature(dev, DRIVER_MODESET))
drm_put_minor(&dev->control);
@@ -396,14 +391,11 @@ void drm_put_dev(struct drm_device *dev)
if (dev->render)
drm_put_minor(&dev->render);
- if (driver->driver_features & DRIVER_GEM)
- drm_gem_destroy(dev);
-
drm_put_minor(&dev->primary);
list_del(&dev->driver_item);
- kfree(dev->devname);
- kfree(dev);
+
+ drm_dev_free(dev);
}
EXPORT_SYMBOL(drm_put_dev);
@@ -502,6 +494,29 @@ err_free:
EXPORT_SYMBOL(drm_dev_alloc);
/**
+ * drm_dev_free - Free DRM device
+ * @dev: DRM device to free
+ *
+ * Free a DRM device that has previously been allocated via drm_dev_alloc().
+ * You must not use kfree() instead or you will leak memory.
+ *
+ * This must not be called once the device got registered. Use drm_put_dev()
+ * instead, which then calls drm_dev_free().
+ */
+void drm_dev_free(struct drm_device *dev)
+{
+ if (dev->driver->driver_features & DRIVER_GEM)
+ drm_gem_destroy(dev);
+
+ drm_ctxbitmap_cleanup(dev);
+ drm_ht_remove(&dev->map_hash);
+
+ kfree(dev->devname);
+ kfree(dev);
+}
+EXPORT_SYMBOL(drm_dev_free);
+
+/**
* drm_dev_register - Register DRM device
* @dev: Device to register
*
diff --git a/drivers/gpu/drm/drm_usb.c b/drivers/gpu/drm/drm_usb.c
index 5ef353f77b5a..b179b70e7853 100644
--- a/drivers/gpu/drm/drm_usb.c
+++ b/drivers/gpu/drm/drm_usb.c
@@ -29,7 +29,7 @@ int drm_get_usb_dev(struct usb_interface *interface,
return 0;
err_free:
- kfree(dev);
+ drm_dev_free(dev);
return ret;
}