virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree
       [not found] <20200221210319.2245170-1-daniel.vetter@ffwll.ch>
@ 2020-02-21 21:02 ` Daniel Vetter
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2020-02-21 21:02 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, virtualization,
	Noralf Trønnes, Thomas Zimmermann, Daniel Vetter,
	Dave Airlie, Sam Ravnborg, Linus Walleij

With this we can drop the final kfree from the release function.

I also noticed that cirrus forgot to call drm_dev_fini().

v2: Don't call kfree(cirrus) after we've handed overship of that to
drm_device and the drmm_ stuff.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: virtualization@lists.linux-foundation.org
---
 drivers/gpu/drm/cirrus/cirrus.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
index d2ff63ce8eaf..2232556ce34c 100644
--- a/drivers/gpu/drm/cirrus/cirrus.c
+++ b/drivers/gpu/drm/cirrus/cirrus.c
@@ -35,6 +35,7 @@
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_ioctl.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_modeset_helper_vtables.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
@@ -527,10 +528,8 @@ static void cirrus_mode_config_init(struct cirrus_device *cirrus)
 
 static void cirrus_release(struct drm_device *dev)
 {
-	struct cirrus_device *cirrus = dev->dev_private;
-
 	drm_mode_config_cleanup(dev);
-	kfree(cirrus);
+	drm_dev_fini(dev);
 }
 
 DEFINE_DRM_GEM_FOPS(cirrus_fops);
@@ -575,9 +574,12 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 
 	dev = &cirrus->dev;
 	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
-	if (ret)
-		goto err_free_cirrus;
+	if (ret) {
+		kfree(cirrus);
+		goto err_pci_release;
+	}
 	dev->dev_private = cirrus;
+	drmm_add_final_kfree(dev, cirrus);
 
 	ret = -ENOMEM;
 	cirrus->vram = ioremap(pci_resource_start(pdev, 0),
@@ -618,8 +620,6 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	iounmap(cirrus->vram);
 err_dev_put:
 	drm_dev_put(dev);
-err_free_cirrus:
-	kfree(cirrus);
 err_pci_release:
 	pci_release_regions(pdev);
 	return ret;
-- 
2.24.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 07/51] drm/qxl: Use drmm_add_final_kfree
       [not found] <20200227181522.2711142-1-daniel.vetter@ffwll.ch>
@ 2020-02-27 18:14 ` Daniel Vetter
  2020-02-27 18:14 ` [PATCH 09/51] drm/cirrus: " Daniel Vetter
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2020-02-27 18:14 UTC (permalink / raw)
  To: DRI Development
  Cc: spice-devel, Daniel Vetter, Intel Graphics Development, m.felsch,
	virtualization, Dave Airlie, Daniel Vetter, l.stach

With this we can drop the final kfree from the release function.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: virtualization@lists.linux-foundation.org
Cc: spice-devel@lists.freedesktop.org
---
 drivers/gpu/drm/qxl/qxl_drv.c | 2 --
 drivers/gpu/drm/qxl/qxl_kms.c | 2 ++
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_drv.c b/drivers/gpu/drm/qxl/qxl_drv.c
index 4fda3f9b29f4..09102e2efabc 100644
--- a/drivers/gpu/drm/qxl/qxl_drv.c
+++ b/drivers/gpu/drm/qxl/qxl_drv.c
@@ -144,8 +144,6 @@ static void qxl_drm_release(struct drm_device *dev)
 	 */
 	qxl_modeset_fini(qdev);
 	qxl_device_fini(qdev);
-	dev->dev_private = NULL;
-	kfree(qdev);
 }
 
 static void
diff --git a/drivers/gpu/drm/qxl/qxl_kms.c b/drivers/gpu/drm/qxl/qxl_kms.c
index 70b20ee4741a..09d7b5f6d172 100644
--- a/drivers/gpu/drm/qxl/qxl_kms.c
+++ b/drivers/gpu/drm/qxl/qxl_kms.c
@@ -27,6 +27,7 @@
 #include <linux/pci.h>
 
 #include <drm/drm_drv.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_probe_helper.h>
 
 #include "qxl_drv.h"
@@ -121,6 +122,7 @@ int qxl_device_init(struct qxl_device *qdev,
 	qdev->ddev.pdev = pdev;
 	pci_set_drvdata(pdev, &qdev->ddev);
 	qdev->ddev.dev_private = qdev;
+	drmm_add_final_kfree(&qdev->ddev, qdev);
 
 	mutex_init(&qdev->gem.mutex);
 	mutex_init(&qdev->update_area_mutex);
-- 
2.24.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree
       [not found] <20200227181522.2711142-1-daniel.vetter@ffwll.ch>
  2020-02-27 18:14 ` [PATCH 07/51] drm/qxl: Use drmm_add_final_kfree Daniel Vetter
@ 2020-02-27 18:14 ` Daniel Vetter
  2020-02-27 21:01   ` Sam Ravnborg
  2020-02-27 18:14 ` [PATCH 28/51] drm/bochs: Drop explicit drm_mode_config_cleanup Daniel Vetter
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Daniel Vetter @ 2020-02-27 18:14 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, m.felsch,
	virtualization, Noralf Trønnes, Thomas Zimmermann,
	Dave Airlie, Daniel Vetter, Sam Ravnborg, Linus Walleij, l.stach

With this we can drop the final kfree from the release function.

I also noticed that cirrus forgot to call drm_dev_fini().

v2: Don't call kfree(cirrus) after we've handed overship of that to
drm_device and the drmm_ stuff.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: virtualization@lists.linux-foundation.org
---
 drivers/gpu/drm/cirrus/cirrus.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
index d2ff63ce8eaf..2232556ce34c 100644
--- a/drivers/gpu/drm/cirrus/cirrus.c
+++ b/drivers/gpu/drm/cirrus/cirrus.c
@@ -35,6 +35,7 @@
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_ioctl.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_modeset_helper_vtables.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
@@ -527,10 +528,8 @@ static void cirrus_mode_config_init(struct cirrus_device *cirrus)
 
 static void cirrus_release(struct drm_device *dev)
 {
-	struct cirrus_device *cirrus = dev->dev_private;
-
 	drm_mode_config_cleanup(dev);
-	kfree(cirrus);
+	drm_dev_fini(dev);
 }
 
 DEFINE_DRM_GEM_FOPS(cirrus_fops);
@@ -575,9 +574,12 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 
 	dev = &cirrus->dev;
 	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
-	if (ret)
-		goto err_free_cirrus;
+	if (ret) {
+		kfree(cirrus);
+		goto err_pci_release;
+	}
 	dev->dev_private = cirrus;
+	drmm_add_final_kfree(dev, cirrus);
 
 	ret = -ENOMEM;
 	cirrus->vram = ioremap(pci_resource_start(pdev, 0),
@@ -618,8 +620,6 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	iounmap(cirrus->vram);
 err_dev_put:
 	drm_dev_put(dev);
-err_free_cirrus:
-	kfree(cirrus);
 err_pci_release:
 	pci_release_regions(pdev);
 	return ret;
-- 
2.24.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 28/51] drm/bochs: Drop explicit drm_mode_config_cleanup
       [not found] <20200227181522.2711142-1-daniel.vetter@ffwll.ch>
  2020-02-27 18:14 ` [PATCH 07/51] drm/qxl: Use drmm_add_final_kfree Daniel Vetter
  2020-02-27 18:14 ` [PATCH 09/51] drm/cirrus: " Daniel Vetter
@ 2020-02-27 18:14 ` Daniel Vetter
  2020-02-27 18:15 ` [PATCH 29/51] drm/cirrus: Drop explicit drm_mode_config_cleanup call Daniel Vetter
  2020-02-27 18:15 ` [PATCH 30/51] drm/cirrus: Fully embrace devm_ Daniel Vetter
  4 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2020-02-27 18:14 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, m.felsch,
	virtualization, Laurent Pinchart, Daniel Vetter, l.stach

Instead rely on the automatic clean, for which we just need to check
that drm_mode_config_init succeeded. To avoid an inversion in the
cleanup we also have to move the dev_private allocation over to
drmm_kzalloc.

This is made possible by a preceeding patch which added a drmm_
cleanup action to drm_mode_config_init(), hence all we need to do to
ensure that drm_mode_config_cleanup() is run on final drm_device
cleanup is check the new error code for _init().

v2: Explain why this cleanup is possible (Laurent).

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: virtualization@lists.linux-foundation.org
---
 drivers/gpu/drm/bochs/bochs.h     |  1 -
 drivers/gpu/drm/bochs/bochs_drv.c |  6 ++----
 drivers/gpu/drm/bochs/bochs_kms.c | 14 +++++---------
 3 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h
index 917767173ee6..e5bd1d517a18 100644
--- a/drivers/gpu/drm/bochs/bochs.h
+++ b/drivers/gpu/drm/bochs/bochs.h
@@ -92,7 +92,6 @@ void bochs_mm_fini(struct bochs_device *bochs);
 
 /* bochs_kms.c */
 int bochs_kms_init(struct bochs_device *bochs);
-void bochs_kms_fini(struct bochs_device *bochs);
 
 /* bochs_fbdev.c */
 extern const struct drm_mode_config_funcs bochs_mode_funcs;
diff --git a/drivers/gpu/drm/bochs/bochs_drv.c b/drivers/gpu/drm/bochs/bochs_drv.c
index addb0568c1af..e18c51de1196 100644
--- a/drivers/gpu/drm/bochs/bochs_drv.c
+++ b/drivers/gpu/drm/bochs/bochs_drv.c
@@ -7,6 +7,7 @@
 
 #include <drm/drm_drv.h>
 #include <drm/drm_atomic_helper.h>
+#include <drm/drm_managed.h>
 
 #include "bochs.h"
 
@@ -21,10 +22,7 @@ static void bochs_unload(struct drm_device *dev)
 {
 	struct bochs_device *bochs = dev->dev_private;
 
-	bochs_kms_fini(bochs);
 	bochs_mm_fini(bochs);
-	kfree(bochs);
-	dev->dev_private = NULL;
 }
 
 static int bochs_load(struct drm_device *dev)
@@ -32,7 +30,7 @@ static int bochs_load(struct drm_device *dev)
 	struct bochs_device *bochs;
 	int ret;
 
-	bochs = kzalloc(sizeof(*bochs), GFP_KERNEL);
+	bochs = drmm_kzalloc(dev, sizeof(*bochs), GFP_KERNEL);
 	if (bochs == NULL)
 		return -ENOMEM;
 	dev->dev_private = bochs;
diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c
index e8cc8156d773..8285c03a6a95 100644
--- a/drivers/gpu/drm/bochs/bochs_kms.c
+++ b/drivers/gpu/drm/bochs/bochs_kms.c
@@ -134,7 +134,11 @@ const struct drm_mode_config_funcs bochs_mode_funcs = {
 
 int bochs_kms_init(struct bochs_device *bochs)
 {
-	drm_mode_config_init(bochs->dev);
+	int ret;
+
+	ret = drm_mode_config_init(bochs->dev);
+	if (ret)
+		return ret;
 
 	bochs->dev->mode_config.max_width = 8192;
 	bochs->dev->mode_config.max_height = 8192;
@@ -160,11 +164,3 @@ int bochs_kms_init(struct bochs_device *bochs)
 
 	return 0;
 }
-
-void bochs_kms_fini(struct bochs_device *bochs)
-{
-	if (!bochs->dev->mode_config.num_connector)
-		return;
-
-	drm_mode_config_cleanup(bochs->dev);
-}
-- 
2.24.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 29/51] drm/cirrus: Drop explicit drm_mode_config_cleanup call
       [not found] <20200227181522.2711142-1-daniel.vetter@ffwll.ch>
                   ` (2 preceding siblings ...)
  2020-02-27 18:14 ` [PATCH 28/51] drm/bochs: Drop explicit drm_mode_config_cleanup Daniel Vetter
@ 2020-02-27 18:15 ` Daniel Vetter
  2020-02-28 20:32   ` Sam Ravnborg
  2020-02-27 18:15 ` [PATCH 30/51] drm/cirrus: Fully embrace devm_ Daniel Vetter
  4 siblings, 1 reply; 12+ messages in thread
From: Daniel Vetter @ 2020-02-27 18:15 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, m.felsch,
	virtualization, Noralf Trønnes, Laurent Pinchart,
	Thomas Zimmermann, Dave Airlie, Daniel Vetter, Sam Ravnborg,
	l.stach

We can even delete the drm_driver.release hook now!

This is made possible by a preceeding patch which added a drmm_
cleanup action to drm_mode_config_init(), hence all we need to do to
ensure that drm_mode_config_cleanup() is run on final drm_device
cleanup is check the new error code for _init().

v2: Explain why this cleanup is possible (Laurent).

Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: virtualization@lists.linux-foundation.org
---
 drivers/gpu/drm/cirrus/cirrus.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
index a9d789a56536..6ac0286810ec 100644
--- a/drivers/gpu/drm/cirrus/cirrus.c
+++ b/drivers/gpu/drm/cirrus/cirrus.c
@@ -510,11 +510,15 @@ static const struct drm_mode_config_funcs cirrus_mode_config_funcs = {
 	.atomic_commit = drm_atomic_helper_commit,
 };
 
-static void cirrus_mode_config_init(struct cirrus_device *cirrus)
+static int cirrus_mode_config_init(struct cirrus_device *cirrus)
 {
 	struct drm_device *dev = &cirrus->dev;
+	int ret;
+
+	ret = drm_mode_config_init(dev);
+	if (ret)
+		return ret;
 
-	drm_mode_config_init(dev);
 	dev->mode_config.min_width = 0;
 	dev->mode_config.min_height = 0;
 	dev->mode_config.max_width = CIRRUS_MAX_PITCH / 2;
@@ -522,15 +526,12 @@ static void cirrus_mode_config_init(struct cirrus_device *cirrus)
 	dev->mode_config.preferred_depth = 16;
 	dev->mode_config.prefer_shadow = 0;
 	dev->mode_config.funcs = &cirrus_mode_config_funcs;
+
+	return 0;
 }
 
 /* ------------------------------------------------------------------ */
 
-static void cirrus_release(struct drm_device *dev)
-{
-	drm_mode_config_cleanup(dev);
-}
-
 DEFINE_DRM_GEM_FOPS(cirrus_fops);
 
 static struct drm_driver cirrus_driver = {
@@ -544,7 +545,6 @@ static struct drm_driver cirrus_driver = {
 
 	.fops		 = &cirrus_fops,
 	DRM_GEM_SHMEM_DRIVER_OPS,
-	.release         = cirrus_release,
 };
 
 static int cirrus_pci_probe(struct pci_dev *pdev,
@@ -591,7 +591,9 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	if (cirrus->mmio == NULL)
 		goto err_unmap_vram;
 
-	cirrus_mode_config_init(cirrus);
+	ret = cirrus_mode_config_init(cirrus);
+	if (ret)
+		goto err_cleanup;
 
 	ret = cirrus_conn_init(cirrus);
 	if (ret < 0)
@@ -613,7 +615,6 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	return 0;
 
 err_cleanup:
-	drm_mode_config_cleanup(dev);
 	iounmap(cirrus->mmio);
 err_unmap_vram:
 	iounmap(cirrus->vram);
-- 
2.24.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 30/51] drm/cirrus: Fully embrace devm_
       [not found] <20200227181522.2711142-1-daniel.vetter@ffwll.ch>
                   ` (3 preceding siblings ...)
  2020-02-27 18:15 ` [PATCH 29/51] drm/cirrus: Drop explicit drm_mode_config_cleanup call Daniel Vetter
@ 2020-02-27 18:15 ` Daniel Vetter
  4 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2020-02-27 18:15 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, m.felsch,
	virtualization, Noralf Trønnes, Thomas Zimmermann,
	Dave Airlie, Daniel Vetter, Emil Velikov, l.stach

With the drm_device lifetime fun cleaned up there's nothing in the way
anymore to use devm_ for everything hw releated. Do it, and in the
process, throw out the entire onion unwinding.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
Cc: Emil Velikov <emil.velikov@collabora.com>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: virtualization@lists.linux-foundation.org
---
 drivers/gpu/drm/cirrus/cirrus.c | 44 +++++++++++----------------------
 1 file changed, 14 insertions(+), 30 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
index 6ac0286810ec..1b78a2f88f69 100644
--- a/drivers/gpu/drm/cirrus/cirrus.c
+++ b/drivers/gpu/drm/cirrus/cirrus.c
@@ -558,7 +558,7 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	if (ret)
 		return ret;
 
-	ret = pci_enable_device(pdev);
+	ret = pcim_enable_device(pdev);
 	if (ret)
 		return ret;
 
@@ -569,39 +569,38 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	ret = -ENOMEM;
 	cirrus = kzalloc(sizeof(*cirrus), GFP_KERNEL);
 	if (cirrus == NULL)
-		goto err_pci_release;
+		return ret;
 
 	dev = &cirrus->dev;
-	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
+	ret = devm_drm_dev_init(&pdev->dev, dev, &cirrus_driver);
 	if (ret) {
 		kfree(cirrus);
-		goto err_pci_release;
+		return ret;
 	}
 	dev->dev_private = cirrus;
 	drmm_add_final_kfree(dev, cirrus);
 
-	ret = -ENOMEM;
-	cirrus->vram = ioremap(pci_resource_start(pdev, 0),
-			       pci_resource_len(pdev, 0));
+	cirrus->vram = devm_ioremap(&pdev->dev, pci_resource_start(pdev, 0),
+				    pci_resource_len(pdev, 0));
 	if (cirrus->vram == NULL)
-		goto err_dev_put;
+		return -ENOMEM;
 
-	cirrus->mmio = ioremap(pci_resource_start(pdev, 1),
-			       pci_resource_len(pdev, 1));
+	cirrus->mmio = devm_ioremap(&pdev->dev, pci_resource_start(pdev, 1),
+				    pci_resource_len(pdev, 1));
 	if (cirrus->mmio == NULL)
-		goto err_unmap_vram;
+		return -ENOMEM;
 
 	ret = cirrus_mode_config_init(cirrus);
 	if (ret)
-		goto err_cleanup;
+		return ret;
 
 	ret = cirrus_conn_init(cirrus);
 	if (ret < 0)
-		goto err_cleanup;
+		return ret;
 
 	ret = cirrus_pipe_init(cirrus);
 	if (ret < 0)
-		goto err_cleanup;
+		return ret;
 
 	drm_mode_config_reset(dev);
 
@@ -609,33 +608,18 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	pci_set_drvdata(pdev, dev);
 	ret = drm_dev_register(dev, 0);
 	if (ret)
-		goto err_cleanup;
+		return ret;
 
 	drm_fbdev_generic_setup(dev, dev->mode_config.preferred_depth);
 	return 0;
-
-err_cleanup:
-	iounmap(cirrus->mmio);
-err_unmap_vram:
-	iounmap(cirrus->vram);
-err_dev_put:
-	drm_dev_put(dev);
-err_pci_release:
-	pci_release_regions(pdev);
-	return ret;
 }
 
 static void cirrus_pci_remove(struct pci_dev *pdev)
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
-	struct cirrus_device *cirrus = dev->dev_private;
 
 	drm_dev_unplug(dev);
 	drm_atomic_helper_shutdown(dev);
-	iounmap(cirrus->mmio);
-	iounmap(cirrus->vram);
-	drm_dev_put(dev);
-	pci_release_regions(pdev);
 }
 
 static const struct pci_device_id pciidlist[] = {
-- 
2.24.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree
  2020-02-27 18:14 ` [PATCH 09/51] drm/cirrus: " Daniel Vetter
@ 2020-02-27 21:01   ` Sam Ravnborg
  0 siblings, 0 replies; 12+ messages in thread
From: Sam Ravnborg @ 2020-02-27 21:01 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Intel Graphics Development, m.felsch, DRI Development,
	virtualization, Noralf Trønnes, Gerd Hoffmann,
	Thomas Zimmermann, Dave Airlie, Daniel Vetter, Linus Walleij,
	l.stach

On Thu, Feb 27, 2020 at 07:14:40PM +0100, Daniel Vetter wrote:
> With this we can drop the final kfree from the release function.
> 
> I also noticed that cirrus forgot to call drm_dev_fini().
> 
> v2: Don't call kfree(cirrus) after we've handed overship of that to
> drm_device and the drmm_ stuff.
> 
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: "Noralf Trønnes" <noralf@tronnes.org>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: virtualization@lists.linux-foundation.org

Acked-by: Sam Ravnborg <sam@ravnborg.org>

> ---
>  drivers/gpu/drm/cirrus/cirrus.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
> index d2ff63ce8eaf..2232556ce34c 100644
> --- a/drivers/gpu/drm/cirrus/cirrus.c
> +++ b/drivers/gpu/drm/cirrus/cirrus.c
> @@ -35,6 +35,7 @@
>  #include <drm/drm_gem_shmem_helper.h>
>  #include <drm/drm_gem_framebuffer_helper.h>
>  #include <drm/drm_ioctl.h>
> +#include <drm/drm_managed.h>
>  #include <drm/drm_modeset_helper_vtables.h>
>  #include <drm/drm_probe_helper.h>
>  #include <drm/drm_simple_kms_helper.h>
> @@ -527,10 +528,8 @@ static void cirrus_mode_config_init(struct cirrus_device *cirrus)
>  
>  static void cirrus_release(struct drm_device *dev)
>  {
> -	struct cirrus_device *cirrus = dev->dev_private;
> -
>  	drm_mode_config_cleanup(dev);
> -	kfree(cirrus);
> +	drm_dev_fini(dev);
>  }
>  
>  DEFINE_DRM_GEM_FOPS(cirrus_fops);
> @@ -575,9 +574,12 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
>  
>  	dev = &cirrus->dev;
>  	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
> -	if (ret)
> -		goto err_free_cirrus;
> +	if (ret) {
> +		kfree(cirrus);
> +		goto err_pci_release;
> +	}
>  	dev->dev_private = cirrus;
> +	drmm_add_final_kfree(dev, cirrus);
>  
>  	ret = -ENOMEM;
>  	cirrus->vram = ioremap(pci_resource_start(pdev, 0),
> @@ -618,8 +620,6 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
>  	iounmap(cirrus->vram);
>  err_dev_put:
>  	drm_dev_put(dev);
> -err_free_cirrus:
> -	kfree(cirrus);
>  err_pci_release:
>  	pci_release_regions(pdev);
>  	return ret;
> -- 
> 2.24.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 29/51] drm/cirrus: Drop explicit drm_mode_config_cleanup call
  2020-02-27 18:15 ` [PATCH 29/51] drm/cirrus: Drop explicit drm_mode_config_cleanup call Daniel Vetter
@ 2020-02-28 20:32   ` Sam Ravnborg
  0 siblings, 0 replies; 12+ messages in thread
From: Sam Ravnborg @ 2020-02-28 20:32 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Gerd Hoffmann, Intel Graphics Development, m.felsch,
	DRI Development, virtualization, Noralf Trønnes,
	Laurent Pinchart, Thomas Zimmermann, Dave Airlie, Daniel Vetter,
	l.stach

On Thu, Feb 27, 2020 at 07:15:00PM +0100, Daniel Vetter wrote:
> We can even delete the drm_driver.release hook now!
> 
> This is made possible by a preceeding patch which added a drmm_
> cleanup action to drm_mode_config_init(), hence all we need to do to
> ensure that drm_mode_config_cleanup() is run on final drm_device
> cleanup is check the new error code for _init().
> 
> v2: Explain why this cleanup is possible (Laurent).
> 
> Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
> Cc: Dave Airlie <airlied@redhat.com>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: "Noralf Trønnes" <noralf@tronnes.org>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> Cc: virtualization@lists.linux-foundation.org

Acked-by: Sam Ravnborg <sam@ravnborg.org>

But as stated in other post - using drmm_mode_config_init()
would make this more readable.

	Sam

> ---
>  drivers/gpu/drm/cirrus/cirrus.c | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
> index a9d789a56536..6ac0286810ec 100644
> --- a/drivers/gpu/drm/cirrus/cirrus.c
> +++ b/drivers/gpu/drm/cirrus/cirrus.c
> @@ -510,11 +510,15 @@ static const struct drm_mode_config_funcs cirrus_mode_config_funcs = {
>  	.atomic_commit = drm_atomic_helper_commit,
>  };
>  
> -static void cirrus_mode_config_init(struct cirrus_device *cirrus)
> +static int cirrus_mode_config_init(struct cirrus_device *cirrus)
>  {
>  	struct drm_device *dev = &cirrus->dev;
> +	int ret;
> +
> +	ret = drm_mode_config_init(dev);
> +	if (ret)
> +		return ret;
>  
> -	drm_mode_config_init(dev);
>  	dev->mode_config.min_width = 0;
>  	dev->mode_config.min_height = 0;
>  	dev->mode_config.max_width = CIRRUS_MAX_PITCH / 2;
> @@ -522,15 +526,12 @@ static void cirrus_mode_config_init(struct cirrus_device *cirrus)
>  	dev->mode_config.preferred_depth = 16;
>  	dev->mode_config.prefer_shadow = 0;
>  	dev->mode_config.funcs = &cirrus_mode_config_funcs;
> +
> +	return 0;
>  }
>  
>  /* ------------------------------------------------------------------ */
>  
> -static void cirrus_release(struct drm_device *dev)
> -{
> -	drm_mode_config_cleanup(dev);
> -}
> -
>  DEFINE_DRM_GEM_FOPS(cirrus_fops);
>  
>  static struct drm_driver cirrus_driver = {
> @@ -544,7 +545,6 @@ static struct drm_driver cirrus_driver = {
>  
>  	.fops		 = &cirrus_fops,
>  	DRM_GEM_SHMEM_DRIVER_OPS,
> -	.release         = cirrus_release,
>  };
>  
>  static int cirrus_pci_probe(struct pci_dev *pdev,
> @@ -591,7 +591,9 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
>  	if (cirrus->mmio == NULL)
>  		goto err_unmap_vram;
>  
> -	cirrus_mode_config_init(cirrus);
> +	ret = cirrus_mode_config_init(cirrus);
> +	if (ret)
> +		goto err_cleanup;
>  
>  	ret = cirrus_conn_init(cirrus);
>  	if (ret < 0)
> @@ -613,7 +615,6 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
>  	return 0;
>  
>  err_cleanup:
> -	drm_mode_config_cleanup(dev);
>  	iounmap(cirrus->mmio);
>  err_unmap_vram:
>  	iounmap(cirrus->vram);
> -- 
> 2.24.1

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree
       [not found] <20200302222631.3861340-1-daniel.vetter@ffwll.ch>
@ 2020-03-02 22:25 ` Daniel Vetter
  2020-03-03  7:49   ` Gerd Hoffmann
  0 siblings, 1 reply; 12+ messages in thread
From: Daniel Vetter @ 2020-03-02 22:25 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, virtualization,
	Noralf Trønnes, Thomas Zimmermann, Daniel Vetter,
	Dave Airlie, Sam Ravnborg, Linus Walleij

With this we can drop the final kfree from the release function.

I also noticed that cirrus forgot to call drm_dev_fini().

v2: Don't call kfree(cirrus) after we've handed overship of that to
drm_device and the drmm_ stuff.

Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: virtualization@lists.linux-foundation.org
---
 drivers/gpu/drm/cirrus/cirrus.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
index d2ff63ce8eaf..2232556ce34c 100644
--- a/drivers/gpu/drm/cirrus/cirrus.c
+++ b/drivers/gpu/drm/cirrus/cirrus.c
@@ -35,6 +35,7 @@
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_ioctl.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_modeset_helper_vtables.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
@@ -527,10 +528,8 @@ static void cirrus_mode_config_init(struct cirrus_device *cirrus)
 
 static void cirrus_release(struct drm_device *dev)
 {
-	struct cirrus_device *cirrus = dev->dev_private;
-
 	drm_mode_config_cleanup(dev);
-	kfree(cirrus);
+	drm_dev_fini(dev);
 }
 
 DEFINE_DRM_GEM_FOPS(cirrus_fops);
@@ -575,9 +574,12 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 
 	dev = &cirrus->dev;
 	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
-	if (ret)
-		goto err_free_cirrus;
+	if (ret) {
+		kfree(cirrus);
+		goto err_pci_release;
+	}
 	dev->dev_private = cirrus;
+	drmm_add_final_kfree(dev, cirrus);
 
 	ret = -ENOMEM;
 	cirrus->vram = ioremap(pci_resource_start(pdev, 0),
@@ -618,8 +620,6 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	iounmap(cirrus->vram);
 err_dev_put:
 	drm_dev_put(dev);
-err_free_cirrus:
-	kfree(cirrus);
 err_pci_release:
 	pci_release_regions(pdev);
 	return ret;
-- 
2.24.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree
  2020-03-02 22:25 ` Daniel Vetter
@ 2020-03-03  7:49   ` Gerd Hoffmann
  2020-03-03  8:27     ` Daniel Vetter
  0 siblings, 1 reply; 12+ messages in thread
From: Gerd Hoffmann @ 2020-03-03  7:49 UTC (permalink / raw)
  To: Daniel Vetter
  Cc: Intel Graphics Development, DRI Development, virtualization,
	Noralf Trønnes, Thomas Zimmermann, Dave Airlie,
	Daniel Vetter, Sam Ravnborg, Linus Walleij

> @@ -575,9 +574,12 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
>  
>  	dev = &cirrus->dev;
>  	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
> -	if (ret)
> -		goto err_free_cirrus;
> +	if (ret) {
> +		kfree(cirrus);
> +		goto err_pci_release;
> +	}
>  	dev->dev_private = cirrus;
> +	drmm_add_final_kfree(dev, cirrus);

That doesn't look like an error path improvement.
With patch #30 applied it'll looks alot better though.
So maybe squash the patches?

In any case:
Acked-by: Gerd Hoffmann <kraxel@redhat.com>

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree
  2020-03-03  7:49   ` Gerd Hoffmann
@ 2020-03-03  8:27     ` Daniel Vetter
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2020-03-03  8:27 UTC (permalink / raw)
  To: Gerd Hoffmann
  Cc: Daniel Vetter, Intel Graphics Development, DRI Development,
	virtualization, Noralf Trønnes, Thomas Zimmermann,
	Daniel Vetter, Dave Airlie, Sam Ravnborg, Linus Walleij

On Tue, Mar 03, 2020 at 08:49:34AM +0100, Gerd Hoffmann wrote:
> > @@ -575,9 +574,12 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
> >  
> >  	dev = &cirrus->dev;
> >  	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
> > -	if (ret)
> > -		goto err_free_cirrus;
> > +	if (ret) {
> > +		kfree(cirrus);
> > +		goto err_pci_release;
> > +	}
> >  	dev->dev_private = cirrus;
> > +	drmm_add_final_kfree(dev, cirrus);
> 
> That doesn't look like an error path improvement.
> With patch #30 applied it'll looks alot better though.
> So maybe squash the patches?

Breaks the patch set evolution, there's a _lot_ of dependencies in here to
make sure we never break anything interim. But yeah that's why I created
this entire series, since with just the first part it's really not any
better. I also have a pile more ideas on top, so hopefully once this lands
I can get around to them and make everything even better :-)

Cheers, Daniel

> 
> In any case:
> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
> 
> cheers,
>   Gerd
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree
       [not found] <20200323144950.3018436-1-daniel.vetter@ffwll.ch>
@ 2020-03-23 14:49 ` Daniel Vetter
  0 siblings, 0 replies; 12+ messages in thread
From: Daniel Vetter @ 2020-03-23 14:49 UTC (permalink / raw)
  To: DRI Development
  Cc: Daniel Vetter, Intel Graphics Development, virtualization,
	Noralf Trønnes, Gerd Hoffmann, Thomas Zimmermann,
	Daniel Vetter, Dave Airlie, Sam Ravnborg, Linus Walleij

With this we can drop the final kfree from the release function.

I also noticed that cirrus forgot to call drm_dev_fini().

v2: Don't call kfree(cirrus) after we've handed overship of that to
drm_device and the drmm_ stuff.

Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: "Noralf Trønnes" <noralf@tronnes.org>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: virtualization@lists.linux-foundation.org
---
 drivers/gpu/drm/cirrus/cirrus.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/cirrus/cirrus.c b/drivers/gpu/drm/cirrus/cirrus.c
index d2ff63ce8eaf..2232556ce34c 100644
--- a/drivers/gpu/drm/cirrus/cirrus.c
+++ b/drivers/gpu/drm/cirrus/cirrus.c
@@ -35,6 +35,7 @@
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
 #include <drm/drm_ioctl.h>
+#include <drm/drm_managed.h>
 #include <drm/drm_modeset_helper_vtables.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
@@ -527,10 +528,8 @@ static void cirrus_mode_config_init(struct cirrus_device *cirrus)
 
 static void cirrus_release(struct drm_device *dev)
 {
-	struct cirrus_device *cirrus = dev->dev_private;
-
 	drm_mode_config_cleanup(dev);
-	kfree(cirrus);
+	drm_dev_fini(dev);
 }
 
 DEFINE_DRM_GEM_FOPS(cirrus_fops);
@@ -575,9 +574,12 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 
 	dev = &cirrus->dev;
 	ret = drm_dev_init(dev, &cirrus_driver, &pdev->dev);
-	if (ret)
-		goto err_free_cirrus;
+	if (ret) {
+		kfree(cirrus);
+		goto err_pci_release;
+	}
 	dev->dev_private = cirrus;
+	drmm_add_final_kfree(dev, cirrus);
 
 	ret = -ENOMEM;
 	cirrus->vram = ioremap(pci_resource_start(pdev, 0),
@@ -618,8 +620,6 @@ static int cirrus_pci_probe(struct pci_dev *pdev,
 	iounmap(cirrus->vram);
 err_dev_put:
 	drm_dev_put(dev);
-err_free_cirrus:
-	kfree(cirrus);
 err_pci_release:
 	pci_release_regions(pdev);
 	return ret;
-- 
2.25.1

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-03-23 14:49 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20200227181522.2711142-1-daniel.vetter@ffwll.ch>
2020-02-27 18:14 ` [PATCH 07/51] drm/qxl: Use drmm_add_final_kfree Daniel Vetter
2020-02-27 18:14 ` [PATCH 09/51] drm/cirrus: " Daniel Vetter
2020-02-27 21:01   ` Sam Ravnborg
2020-02-27 18:14 ` [PATCH 28/51] drm/bochs: Drop explicit drm_mode_config_cleanup Daniel Vetter
2020-02-27 18:15 ` [PATCH 29/51] drm/cirrus: Drop explicit drm_mode_config_cleanup call Daniel Vetter
2020-02-28 20:32   ` Sam Ravnborg
2020-02-27 18:15 ` [PATCH 30/51] drm/cirrus: Fully embrace devm_ Daniel Vetter
     [not found] <20200323144950.3018436-1-daniel.vetter@ffwll.ch>
2020-03-23 14:49 ` [PATCH 09/51] drm/cirrus: Use drmm_add_final_kfree Daniel Vetter
     [not found] <20200302222631.3861340-1-daniel.vetter@ffwll.ch>
2020-03-02 22:25 ` Daniel Vetter
2020-03-03  7:49   ` Gerd Hoffmann
2020-03-03  8:27     ` Daniel Vetter
     [not found] <20200221210319.2245170-1-daniel.vetter@ffwll.ch>
2020-02-21 21:02 ` Daniel Vetter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).