Skip to content

Commit f5cc0cb

Browse files
Sui Jingfenglynxeye-dev
authored andcommitted
drm/etnaviv: Add a helper to get the first available GPU device node
This patch make the code in the etnaviv_pdev_probe() less twisted, and it also make it easier to drop the reference to device node after finished. Before apply this patch, there is no call to of_node_put() when done. We should call of_node_put() when done. Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
1 parent a10a43e commit f5cc0cb

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

drivers/gpu/drm/etnaviv/etnaviv_drv.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
* DRM operations:
3030
*/
3131

32+
static struct device_node *etnaviv_of_first_available_node(void)
33+
{
34+
struct device_node *np;
35+
36+
for_each_compatible_node(np, NULL, "vivante,gc") {
37+
if (of_device_is_available(np))
38+
return np;
39+
}
40+
41+
return NULL;
42+
}
3243

3344
static void load_gpu(struct drm_device *dev)
3445
{
@@ -597,9 +608,6 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
597608
if (!of_device_is_available(core_node))
598609
continue;
599610

600-
if (!first_node)
601-
first_node = core_node;
602-
603611
drm_of_component_match_add(&pdev->dev, &match,
604612
component_compare_of, core_node);
605613
}
@@ -634,8 +642,11 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
634642
* device as the GPU we found. This assumes that all Vivante
635643
* GPUs in the system share the same DMA constraints.
636644
*/
637-
if (first_node)
645+
first_node = etnaviv_of_first_available_node();
646+
if (first_node) {
638647
of_dma_configure(&pdev->dev, first_node, true);
648+
of_node_put(first_node);
649+
}
639650

640651
return component_master_add_with_match(dev, &etnaviv_master_ops, match);
641652
}
@@ -709,16 +720,13 @@ static int __init etnaviv_init(void)
709720
* If the DT contains at least one available GPU device, instantiate
710721
* the DRM platform device.
711722
*/
712-
for_each_compatible_node(np, NULL, "vivante,gc") {
713-
if (!of_device_is_available(np))
714-
continue;
723+
np = etnaviv_of_first_available_node();
724+
if (np) {
715725
of_node_put(np);
716726

717727
ret = etnaviv_create_platform_device("etnaviv", &etnaviv_drm);
718728
if (ret)
719729
goto unregister_platform_driver;
720-
721-
break;
722730
}
723731

724732
return 0;

0 commit comments

Comments
 (0)