Skip to content

Commit a10a43e

Browse files
Sui Jingfenglynxeye-dev
authored andcommitted
drm/etnaviv: Add helper functions to create and destroy platform device
The newly introduced functions are etnaviv_create_platform_device() and etnaviv_destroy_platform_device(). Those two function are pure function and can be shared for other use case. Currently, the benefit is that we no longer need to call of_node_put() for three different cases, we only need to call it once in the etnaviv_init() function. Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
1 parent 4cb91cc commit a10a43e

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

drivers/gpu/drm/etnaviv/etnaviv_drv.c

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -655,11 +655,43 @@ static struct platform_driver etnaviv_platform_driver = {
655655
},
656656
};
657657

658+
static int etnaviv_create_platform_device(const char *name,
659+
struct platform_device **ppdev)
660+
{
661+
struct platform_device *pdev;
662+
int ret;
663+
664+
pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE);
665+
if (!pdev)
666+
return -ENOMEM;
667+
668+
ret = platform_device_add(pdev);
669+
if (ret) {
670+
platform_device_put(pdev);
671+
return ret;
672+
}
673+
674+
*ppdev = pdev;
675+
676+
return 0;
677+
}
678+
679+
static void etnaviv_destroy_platform_device(struct platform_device **ppdev)
680+
{
681+
struct platform_device *pdev = *ppdev;
682+
683+
if (!pdev)
684+
return;
685+
686+
platform_device_unregister(pdev);
687+
688+
*ppdev = NULL;
689+
}
690+
658691
static struct platform_device *etnaviv_drm;
659692

660693
static int __init etnaviv_init(void)
661694
{
662-
struct platform_device *pdev;
663695
int ret;
664696
struct device_node *np;
665697

@@ -680,23 +712,12 @@ static int __init etnaviv_init(void)
680712
for_each_compatible_node(np, NULL, "vivante,gc") {
681713
if (!of_device_is_available(np))
682714
continue;
715+
of_node_put(np);
683716

684-
pdev = platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE);
685-
if (!pdev) {
686-
ret = -ENOMEM;
687-
of_node_put(np);
688-
goto unregister_platform_driver;
689-
}
690-
691-
ret = platform_device_add(pdev);
692-
if (ret) {
693-
platform_device_put(pdev);
694-
of_node_put(np);
717+
ret = etnaviv_create_platform_device("etnaviv", &etnaviv_drm);
718+
if (ret)
695719
goto unregister_platform_driver;
696-
}
697720

698-
etnaviv_drm = pdev;
699-
of_node_put(np);
700721
break;
701722
}
702723

@@ -712,7 +733,7 @@ module_init(etnaviv_init);
712733

713734
static void __exit etnaviv_exit(void)
714735
{
715-
platform_device_unregister(etnaviv_drm);
736+
etnaviv_destroy_platform_device(&etnaviv_drm);
716737
platform_driver_unregister(&etnaviv_platform_driver);
717738
platform_driver_unregister(&etnaviv_gpu_driver);
718739
}

0 commit comments

Comments
 (0)