drm/atmel-hlcdc: use managed device resources for the display controller

Take benefit of managed device resources to reduce the risk of memory
leak and to simplify error paths.

Signed-off-by: Ludovic Desroches <ludovic.desroches@microchip.com>
Reviewed-by: Manikandan Muralidharan <manikandan.m@microchip.com>
Link: https://patch.msgid.link/20251218-lcd_cleanup_mainline-v2-1-df837aba878f@microchip.com
Signed-off-by: Manikandan Muralidharan <manikandan.m@microchip.com>
This commit is contained in:
Ludovic Desroches 2025-12-18 14:25:59 +01:00 committed by Manikandan Muralidharan
parent ce76a26734
commit 950cba9870
2 changed files with 13 additions and 13 deletions

View File

@ -751,11 +751,16 @@ static int atmel_hlcdc_dc_modeset_init(struct drm_device *dev)
return 0;
}
static struct atmel_hlcdc_dc *atmel_hlcdc_dc_of_dev(struct drm_device *dev)
{
return container_of(dev, struct atmel_hlcdc_dc, dev);
}
static int atmel_hlcdc_dc_load(struct drm_device *dev)
{
struct platform_device *pdev = to_platform_device(dev->dev);
const struct of_device_id *match;
struct atmel_hlcdc_dc *dc;
struct atmel_hlcdc_dc *dc = atmel_hlcdc_dc_of_dev(dev);
int ret;
match = of_match_node(atmel_hlcdc_of_match, dev->dev->parent->of_node);
@ -769,10 +774,6 @@ static int atmel_hlcdc_dc_load(struct drm_device *dev)
return -EINVAL;
}
dc = devm_kzalloc(dev->dev, sizeof(*dc), GFP_KERNEL);
if (!dc)
return -ENOMEM;
dc->desc = match->data;
dc->hlcdc = dev_get_drvdata(dev->dev->parent);
dev->dev_private = dc;
@ -853,16 +854,18 @@ static const struct drm_driver atmel_hlcdc_dc_driver = {
static int atmel_hlcdc_dc_drm_probe(struct platform_device *pdev)
{
struct atmel_hlcdc_dc *dc;
struct drm_device *ddev;
int ret;
ddev = drm_dev_alloc(&atmel_hlcdc_dc_driver, &pdev->dev);
if (IS_ERR(ddev))
return PTR_ERR(ddev);
dc = devm_drm_dev_alloc(&pdev->dev, &atmel_hlcdc_dc_driver, struct atmel_hlcdc_dc, dev);
if (IS_ERR(dc))
return PTR_ERR(dc);
ddev = &dc->dev;
ret = atmel_hlcdc_dc_load(ddev);
if (ret)
goto err_put;
return ret;
ret = drm_dev_register(ddev, 0);
if (ret)
@ -875,9 +878,6 @@ static int atmel_hlcdc_dc_drm_probe(struct platform_device *pdev)
err_unload:
atmel_hlcdc_dc_unload(ddev);
err_put:
drm_dev_put(ddev);
return ret;
}
@ -887,7 +887,6 @@ static void atmel_hlcdc_dc_drm_remove(struct platform_device *pdev)
drm_dev_unregister(ddev);
atmel_hlcdc_dc_unload(ddev);
drm_dev_put(ddev);
}
static void atmel_hlcdc_dc_drm_shutdown(struct platform_device *pdev)

View File

@ -350,6 +350,7 @@ struct atmel_hlcdc_dc {
struct dma_pool *dscrpool;
struct atmel_hlcdc *hlcdc;
struct drm_crtc *crtc;
struct drm_device dev;
struct atmel_hlcdc_layer *layers[ATMEL_HLCDC_MAX_LAYERS];
struct {
u32 imr;