Skip to content

Commit aefae87

Browse files
dakrdliviu
authored andcommitted
drm/arm/malidp: use drmm_* to allocate driver structures
Use drm managed resources to allocate driver structures and get rid of the deprecated drm_dev_alloc() call and replace it with devm_drm_dev_alloc(). This also serves as preparation to get rid of drm_device->dev_private and to fix use-after-free issues on driver unload. Signed-off-by: Danilo Krummrich <[email protected]> Signed-off-by: Liviu Dudau <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 0e308ef commit aefae87

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

drivers/gpu/drm/arm/malidp_drv.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <drm/drm_fourcc.h>
2424
#include <drm/drm_gem_dma_helper.h>
2525
#include <drm/drm_gem_framebuffer_helper.h>
26+
#include <drm/drm_managed.h>
2627
#include <drm/drm_modeset_helper.h>
2728
#include <drm/drm_module.h>
2829
#include <drm/drm_of.h>
@@ -716,11 +717,13 @@ static int malidp_bind(struct device *dev)
716717
int ret = 0, i;
717718
u32 version, out_depth = 0;
718719

719-
malidp = devm_kzalloc(dev, sizeof(*malidp), GFP_KERNEL);
720-
if (!malidp)
721-
return -ENOMEM;
720+
malidp = devm_drm_dev_alloc(dev, &malidp_driver, typeof(*malidp), base);
721+
if (IS_ERR(malidp))
722+
return PTR_ERR(malidp);
723+
724+
drm = &malidp->base;
722725

723-
hwdev = devm_kzalloc(dev, sizeof(*hwdev), GFP_KERNEL);
726+
hwdev = drmm_kzalloc(drm, sizeof(*hwdev), GFP_KERNEL);
724727
if (!hwdev)
725728
return -ENOMEM;
726729

@@ -753,12 +756,6 @@ static int malidp_bind(struct device *dev)
753756
if (ret && ret != -ENODEV)
754757
return ret;
755758

756-
drm = drm_dev_alloc(&malidp_driver, dev);
757-
if (IS_ERR(drm)) {
758-
ret = PTR_ERR(drm);
759-
goto alloc_fail;
760-
}
761-
762759
drm->dev_private = malidp;
763760
dev_set_drvdata(dev, drm);
764761

@@ -887,8 +884,6 @@ static int malidp_bind(struct device *dev)
887884
malidp_runtime_pm_suspend(dev);
888885
drm->dev_private = NULL;
889886
dev_set_drvdata(dev, NULL);
890-
drm_dev_put(drm);
891-
alloc_fail:
892887
of_reserved_mem_device_release(dev);
893888

894889
return ret;
@@ -917,7 +912,6 @@ static void malidp_unbind(struct device *dev)
917912
malidp_runtime_pm_suspend(dev);
918913
drm->dev_private = NULL;
919914
dev_set_drvdata(dev, NULL);
920-
drm_dev_put(drm);
921915
of_reserved_mem_device_release(dev);
922916
}
923917

drivers/gpu/drm/arm/malidp_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct malidp_error_stats {
2929
};
3030

3131
struct malidp_drm {
32+
struct drm_device base;
3233
struct malidp_hw_device *dev;
3334
struct drm_crtc crtc;
3435
struct drm_writeback_connector mw_connector;

0 commit comments

Comments
 (0)